diff --git a/holoviews/core/data/pandas.py b/holoviews/core/data/pandas.py index 3806834206..e937ba39e7 100644 --- a/holoviews/core/data/pandas.py +++ b/holoviews/core/data/pandas.py @@ -1,6 +1,5 @@ import numpy as np import pandas as pd -from pandas.api.types import is_period_dtype from .interface import Interface, DataError from ..dimension import dimension_name @@ -157,8 +156,6 @@ def validate(cls, dataset, vdims=True): def range(cls, dataset, dimension): dimension = dataset.get_dimension(dimension, strict=True) column = dataset.data[dimension.name] - if is_period_dtype(column): - column = column.dt.to_timestamp() if column.dtype.kind == 'O': if (not isinstance(dataset.data, pd.DataFrame) or util.LooseVersion(pd.__version__) < util.LooseVersion('0.17.0')): 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/data/test_pandasinterface.py b/holoviews/tests/core/data/test_pandasinterface.py index dad5a411ae..c7669fb332 100644 --- a/holoviews/tests/core/data/test_pandasinterface.py +++ b/holoviews/tests/core/data/test_pandasinterface.py @@ -5,7 +5,7 @@ from holoviews.core.data import Dataset from holoviews.core.data.interface import DataError from holoviews.core.spaces import HoloMap -from holoviews.element import Curve, Scatter, Points, Distribution +from holoviews.element import Scatter, Points, Distribution from .base import HeterogeneousColumnTests, InterfaceTests @@ -164,12 +164,6 @@ def test_dataset_with_interface_column(self): ds = Dataset(df) self.assertEqual(list(ds.data.columns), ['interface']) - def test_dataset_range_for_pd_period_range(self): - period_range = pd.period_range("1990", "1991", freq="M") - expected_range = (pd.Timestamp('1990-01-01 00:00:00'), pd.Timestamp('1991-01-01 00:00:00')) - curve = Curve((period_range, range(13))) - assert curve.range("x") == expected_range - class PandasInterfaceTests(BasePandasInterfaceTests): 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):