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

Various fixes for xarray 0.13 compatibility #3973

Merged
merged 3 commits into from
Sep 20, 2019
Merged
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: 12 additions & 5 deletions holoviews/core/data/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ def shape(cls, dataset, gridded=False):
if kd.name in array.dims][::-1]
if not all(d in names for d in array.dims):
array = np.squeeze(array)
try:
array = array.transpose(*names, transpose_coords=False)
except:
array = array.transpose(*names) # Handle old xarray
if len(names) > 1:
try:
array = array.transpose(*names, transpose_coords=False)
except:
array = array.transpose(*names) # Handle old xarray
shape = array.shape
if gridded:
return shape
Expand Down Expand Up @@ -218,6 +219,10 @@ def range(cls, dataset, dimension):
da = dask_array_module()
if da and isinstance(dmin, da.Array):
dmin, dmax = da.compute(dmin, dmax)
if isinstance(dmin, np.ndarray) and dmin.shape == ():
dmin = dmin[()]
if isinstance(dmax, np.ndarray) and dmax.shape == ():
dmax = dmax[()]
dmin = dmin if np.isscalar(dmin) or isinstance(dmin, util.datetime_types) else dmin.item()
dmax = dmax if np.isscalar(dmax) or isinstance(dmax, util.datetime_types) else dmax.item()
return dmin, dmax
Expand Down Expand Up @@ -390,8 +395,10 @@ def ndloc(cls, dataset, indices):
sampled = (all(isinstance(ind, np.ndarray) and ind.dtype.kind != 'b'
for ind in adjusted_indices) and len(indices) == len(kdims))
if sampled or (all_scalar and len(indices) == len(kdims)):
import xarray as xr
if all_scalar: isel = {k: [v] for k, v in isel.items()}
return dataset.data.isel_points(**isel).to_dataframe().reset_index()
selected = dataset.data.isel({k: xr.DataArray(v) for k, v in isel.items()})
return selected.to_dataframe().reset_index()
else:
return dataset.data.isel(**isel)

Expand Down