From 89368a2c7d78fbaf7642525f62c31e58a0d70157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Wed, 17 Aug 2022 16:31:14 +0200 Subject: [PATCH] Fix period range (#5393) * Converting period to timestamp * Added unit test * Convert in max_range instead --- holoviews/core/data/pandas.py | 5 ----- holoviews/core/util.py | 5 ++++- holoviews/tests/core/test_utils.py | 4 ++++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/holoviews/core/data/pandas.py b/holoviews/core/data/pandas.py index 1bda819144..e937ba39e7 100644 --- a/holoviews/core/data/pandas.py +++ b/holoviews/core/data/pandas.py @@ -1,8 +1,3 @@ -try: - import itertools.izip as zip -except ImportError: - pass - import numpy as np import pandas as pd diff --git a/holoviews/core/util.py b/holoviews/core/util.py index 1545770126..bce9c0427c 100644 --- a/holoviews/core/util.py +++ b/holoviews/core/util.py @@ -922,7 +922,10 @@ def max_range(ranges, combined=True): for r in values for v in r): converted = [] for l, h in values: - if isinstance(l, datetime_types) and isinstance(h, datetime_types): + if isinstance(l, pd.Period) and isinstance(h, pd.Period): + l = l.to_timestamp().to_datetime64() + h = h.to_timestamp().to_datetime64() + elif isinstance(l, datetime_types) and isinstance(h, datetime_types): l, h = (pd.Timestamp(l).to_datetime64(), pd.Timestamp(h).to_datetime64()) converted.append((l, h)) diff --git a/holoviews/tests/core/test_utils.py b/holoviews/tests/core/test_utils.py index 9c94e190da..3be3e848b3 100644 --- a/holoviews/tests/core/test_utils.py +++ b/holoviews/tests/core/test_utils.py @@ -332,6 +332,10 @@ def test_max_range2(self): self.assertTrue(math.isnan(lower)) self.assertTrue(math.isnan(upper)) + def test_max_range3(self): + periods = [(pd.Period("1990", freq="M"), pd.Period("1991", freq="M"))] + expected = (np.datetime64("1990", 'ns'), np.datetime64("1991", 'ns')) + self.assertEqual(max_range(periods), expected) class TestWrapTupleStreams(unittest.TestCase):