Skip to content

Commit

Permalink
Handle range on heterogeneously typed Dataset column (#2345)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored and jlstevens committed Feb 19, 2018
1 parent ecfb67a commit d05358f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
7 changes: 5 additions & 2 deletions holoviews/core/data/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,12 @@ def range(cls, dataset, dimension):
return np.NaN, np.NaN
else:
try:
assert column.dtype.kind not in 'SUO'
return (np.nanmin(column), np.nanmax(column))
except TypeError:
column.sort()
except (AssertionError, TypeError):
column = [v for v in util.python2sort(column) if v is not None]
if not len(column):
return np.NaN, np.NaN
return column[0], column[-1]

@classmethod
Expand Down
3 changes: 3 additions & 0 deletions holoviews/core/data/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ def range(cls, columns, dimension):
column = column.sort(inplace=False)
else:
column = column.sort_values()
column = column[~column.isin([None])]
if not len(column):
return np.NaN, np.NaN
return column.iloc[0], column.iloc[-1]
else:
return (column.min(), column.max())
Expand Down
2 changes: 1 addition & 1 deletion holoviews/core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ def max_range(ranges):
values = [(v1.to_datetime64(), v2.to_datetime64()) for v1, v2 in values]
arr = np.array(values)
if arr.dtype.kind in 'OSU':
arr = np.sort([v for v in arr.flat if not is_nan(v)])
arr = list(python2sort([v for v in arr.flat if not is_nan(v) and v is not None]))
return arr[0], arr[-1]
if arr.dtype.kind in 'M':
return arr[:, 0].min(), arr[:, 1].max()
Expand Down
4 changes: 4 additions & 0 deletions tests/core/data/testdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,10 @@ def test_dataset_redim_with_alias_dframe(self):
self.assertEqual(dataset.redim(**{'X-label':'X'}), dataset_redim)
self.assertEqual(dataset.redim(**{'x':'X'}), dataset_redim)

def test_dataset_mixed_type_range(self):
ds = Dataset((['A', 'B', 'C', None],), 'A')
self.assertEqual(ds.range(0), ('A', 'C'))

def test_dataset_sort_vdim_ht(self):
dataset = Dataset({'x':self.xs, 'y':-self.ys},
kdims=['x'], vdims=['y'])
Expand Down

0 comments on commit d05358f

Please sign in to comment.