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

xvec support #1405

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
17 changes: 17 additions & 0 deletions hvplot/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
is_cudf,
is_streamz,
is_ibis,
is_xvec,
is_xarray,
is_xarray_dataarray,
process_crs,
Expand Down Expand Up @@ -1048,6 +1049,22 @@ def _process_data(
if col is not None:
grid.append(col)
streaming = False

if is_xvec(data):
import xvec # noqa: F401

geom_coords = list(data.xvec.geom_coords)
if len(geom_coords) > 1:
param.main.param.warning(
f'Only the first geometry coord will be rendered: {geom_coords[0]!r}. The '
f"others are 'flattened' in groupby: {geom_coords[1:]}"
)
data = data.drop_vars(geom_coords[1:])
if groupby is None:
groupby = [dim for dim in data.dims if dim != geom_coords[0]]
data = data.xvec.to_geodataframe()
self.source_data = data

if is_geodataframe(data):
datatype = 'geopandas' if hasattr(data, 'geom_type') else 'spatialpandas'
self.data = data
Expand Down
23 changes: 22 additions & 1 deletion hvplot/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,14 @@ def is_streamz(data):
return sdf and isinstance(data, (sdf.DataFrame, sdf.Series, sdf.DataFrames, sdf.Seriess))


def is_xvec(data):
if not hasattr(data, 'xvec'):
return False
import xvec # noqa

return len(data.xvec.geom_coords) > 0


def is_xarray(data):
if not check_library(data, 'xarray'):
return False
Expand Down Expand Up @@ -482,7 +490,18 @@ def is_geodataframe(data):


def process_xarray(
data, x, y, by, groupby, use_dask, persist, gridded, label, value_label, other_dims, kind=None
data,
x,
y,
by,
groupby,
use_dask,
persist,
gridded,
label,
value_label,
other_dims,
kind=None,
):
import xarray as xr

Expand All @@ -509,6 +528,7 @@ def process_xarray(

data_vars = list(dataset.data_vars)
ignore = (by or []) + (groupby or [])

dims = [c for c in dataset.coords if dataset[c].shape != () and c not in ignore][::-1]
index_dims = [d for d in dims if d in dataset.indexes]

Expand Down Expand Up @@ -565,6 +585,7 @@ def process_xarray(

if groupby is None:
groupby = [c for c in leftover_dims if c not in (by or [])]

return data, x, y, by, groupby


Expand Down
Loading