Skip to content

Commit

Permalink
Add test for spatial select
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro committed May 6, 2024
1 parent 9fc22f9 commit 57d81f7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions holoviews/element/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def spatial_select_gridded(xvals, yvals, geometry):
def spatial_select_columnar(xvals, yvals, geometry, geom_method=None):
if 'cudf' in sys.modules:
import cudf
import cupy as cp
if isinstance(xvals, cudf.Series):
xvals = xvals.values.astype('float')
yvals = yvals.values.astype('float')
Expand All @@ -98,8 +99,8 @@ def spatial_select_columnar(xvals, yvals, geometry, geom_method=None):
)
return result.values
except ImportError:
xvals = np.asarray(xvals)
yvals = np.asarray(yvals)
xvals = cp.asnumpy(xvals)
yvals = cp.asnumpy(yvals)
if 'dask' in sys.modules:
import dask.dataframe as dd
if isinstance(xvals, dd.Series):
Expand Down
19 changes: 19 additions & 0 deletions holoviews/tests/element/test_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,25 @@ def test_numpy(self, geometry, pt_mask, pandas_df, _method):
mask = spatial_select_columnar(pandas_df.x.to_numpy(copy=True), pandas_df.y.to_numpy(copy=True), geometry, _method)
assert np.array_equal(mask, pt_mask)

@pytest.mark.gpu
def test_cudf(self, geometry, pt_mask, pandas_df, _method, unimport):
import cudf
import cupy as cp
unimport('cuspatial')

df = cudf.from_pandas(pandas_df)
mask = spatial_select_columnar(df.x, df.y, geometry, _method)
assert np.array_equal(cp.asnumpy(mask), pt_mask)

@pytest.mark.xfail(reason='cuspatial.point_in_polygon API has changed')
@pytest.mark.gpu
def test_cuspatial(self, geometry, pt_mask, pandas_df, _method):
import cudf
import cupy as cp

df = cudf.from_pandas(pandas_df)
mask = spatial_select_columnar(df.x, df.y, geometry, _method)
assert np.array_equal(cp.asnumpy(mask), pt_mask)

@pytest.mark.parametrize("geometry", [geometry_encl, geometry_noencl])
class TestSpatialSelectColumnarDaskMeta:
Expand Down
1 change: 1 addition & 0 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ platforms = ["linux-64"]
[feature.test-gpu.dependencies]
cuda-version = "12.2.*"
cudf = "24.04.*"
cuspatial = "*"
cupy = { version = "*", channel = "conda-forge" }
ucx = { version = "*", channel = "conda-forge" }

Expand Down

0 comments on commit 57d81f7

Please sign in to comment.