Skip to content

Commit

Permalink
Handle unsigned integer dtype in datashader aggregate operation (#5149)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoxbro authored and maximlt committed Dec 7, 2021
1 parent c28f02c commit 5bfdd5d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
8 changes: 6 additions & 2 deletions holoviews/operation/datashader.py
Expand Up @@ -415,15 +415,19 @@ def get_agg_data(cls, obj, category=None):

is_custom = isinstance(df, dd.DataFrame) or cuDFInterface.applies(df)
if any((not is_custom and len(df[d.name]) and isinstance(df[d.name].values[0], cftime_types)) or
df[d.name].dtype.kind == 'M' for d in (x, y)):
df[d.name].dtype.kind in ["M", "u"] for d in (x, y)):
df = df.copy()

for d in (x, y):
vals = df[d.name]
if not is_custom and len(vals) and isinstance(vals.values[0], cftime_types):
vals = cftime_to_timestamp(vals, 'ns')
elif df[d.name].dtype.kind == 'M':
elif vals.dtype.kind == 'M':
vals = vals.astype('datetime64[ns]')
elif vals.dtype == np.uint64:
raise TypeError(f"Dtype of uint64 for column {d.name} is not supported.")
elif vals.dtype.kind == 'u':
pass # To convert to int64
else:
continue
df[d.name] = cast_array_to_int64(vals)
Expand Down
22 changes: 20 additions & 2 deletions holoviews/tests/operation/testdatashader.py
Expand Up @@ -707,6 +707,26 @@ def test_multi_poly_rasterize(self):
expected = Image((xs, ys, arr), vdims=Dimension('Count', nodata=0))
self.assertEqual(agg, expected)

def test_uint_dtype(self):
df = pd.DataFrame(np.arange(2, dtype=np.uint8), columns=["A"])
curve = Curve(df)
img = rasterize(curve, dynamic=False, height=10, width=10)
assert (np.asarray(img.data["Count"]) == np.eye(10)).all()
df = pd.DataFrame(np.arange(2, dtype=np.uint16), columns=["A"])
curve = Curve(df)
img = rasterize(curve, dynamic=False, height=10, width=10)
assert (np.asarray(img.data["Count"]) == np.eye(10)).all()
df = pd.DataFrame(np.arange(2, dtype=np.uint32), columns=["A"])
curve = Curve(df)
img = rasterize(curve, dynamic=False, height=10, width=10)
assert (np.asarray(img.data["Count"]) == np.eye(10)).all()

def test_uint64_dtype(self):
df = pd.DataFrame(np.arange(2, dtype=np.uint64), columns=["A"])
curve = Curve(df)
with self.assertRaisesRegex(TypeError, match="Dtype of uint64 for column A is not supported"):
rasterize(curve, dynamic=False, height=10, width=10)



class DatashaderCatAggregateTests(ComparisonTestCase):
Expand Down Expand Up @@ -840,8 +860,6 @@ def test_regrid_upsampling(self):
self.assertEqual(regridded, expected)

def test_regrid_upsampling_linear(self):
### This test causes a numba error using 0.35.0 - temporarily disabled ###
return
img = Image(([0.5, 1.5], [0.5, 1.5], [[0, 1], [2, 3]]))
regridded = regrid(img, width=4, height=4, upsample=True, interpolation='linear', dynamic=False)
expected = Image(([0.25, 0.75, 1.25, 1.75], [0.25, 0.75, 1.25, 1.75],
Expand Down

0 comments on commit 5bfdd5d

Please sign in to comment.