Skip to content

Commit

Permalink
Fix period range (#5393)
Browse files Browse the repository at this point in the history
* Converting period to timestamp

* Added unit test

* Convert in max_range instead
  • Loading branch information
hoxbro authored Aug 17, 2022
1 parent 8b2ee78 commit 89368a2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 0 additions & 5 deletions holoviews/core/data/pandas.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
try:
import itertools.izip as zip
except ImportError:
pass

import numpy as np
import pandas as pd

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
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 89368a2

Please sign in to comment.