Skip to content

Commit

Permalink
Convert in max_range instead
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro committed Aug 17, 2022
1 parent 4da2dce commit f861ad2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
3 changes: 0 additions & 3 deletions holoviews/core/data/pandas.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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')):
Expand Down
5 changes: 4 additions & 1 deletion holoviews/core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 1 addition & 7 deletions holoviews/tests/core/data/test_pandasinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):

Expand Down
4 changes: 4 additions & 0 deletions holoviews/tests/core/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit f861ad2

Please sign in to comment.