Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle range on heterogeneously typed Dataset column #2345

Merged
merged 3 commits into from
Feb 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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