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 unsigned integer dtype in datashader aggregate operation #5149

Merged
merged 9 commits into from
Dec 7, 2021
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
8 changes: 6 additions & 2 deletions holoviews/operation/datashader.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,15 +420,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] = vals.astype('int64')
Expand Down
18 changes: 16 additions & 2 deletions holoviews/tests/operation/test_datashader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from unittest import SkipTest, skipIf

import numpy as np
import pytest

from holoviews import (
Dimension, Curve, Points, Image, Dataset, RGB, Path, Graph, TriMesh,
Expand Down Expand Up @@ -848,8 +849,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 Expand Up @@ -1322,3 +1321,18 @@ def test_polys_inspection_1px_mask_miss(self):
polys = inspect_polygons(self.polysrgb,
max_indicators=3, dynamic=False, pixels=1, x=0, y=0)
self.assertEqual(polys, Polygons([], vdims='z'))


@pytest.mark.parametrize("dtype", [np.uint8, np.uint16, np.uint32])
def test_uint_dtype(dtype):
df = pd.DataFrame(np.arange(2, dtype=dtype), 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():
df = pd.DataFrame(np.arange(2, dtype=np.uint64), columns=["A"])
curve = Curve(df)
with pytest.raises(TypeError, match="Dtype of uint64 for column A is not supported."):
rasterize(curve, dynamic=False, height=10, width=10)