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

groupby_bins raises ufunc 'isnan' error on 0.14.0 #3404

Closed
dnowacki-usgs opened this issue Oct 15, 2019 · 1 comment · Fixed by #3405
Closed

groupby_bins raises ufunc 'isnan' error on 0.14.0 #3404

dnowacki-usgs opened this issue Oct 15, 2019 · 1 comment · Fixed by #3405

Comments

@dnowacki-usgs
Copy link
Contributor

I recently upgraded to xarray 0.14.0. When running code that used to work in 0.13, I get a TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe'' in 0.14 when running code similar to the MCVE below. The code should return the GroupBy bins instead of the error.

MCVE Code Sample

import xarray as xr
import pandas as pd
import numpy as np

ts = pd.date_range(start='2010-08-01', end='2010-08-15', freq='24.8H')

ds = xr.Dataset()
ds['time'] = xr.DataArray(pd.date_range('2010-08-01', '2010-08-15', freq='15min'), dims='time')
ds['val'] = xr.DataArray(np.random.rand(*ds['time'].shape), dims='time')

ds.groupby_bins('time', ts) #error thrown here

Full error details below.

--------------------------------------------------------------------------- TypeError Traceback (most recent call last) in 9 ds['val'] = xr.DataArray(np.random.rand(*ds['time'].shape), dims='time') 10 ---> 11 ds.groupby_bins('time', ts)

~/miniconda3/lib/python3.7/site-packages/xarray/core/common.py in groupby_bins(self, group, bins, right, labels, precision, include_lowest, squeeze, restore_coord_dims)
727 "labels": labels,
728 "precision": precision,
--> 729 "include_lowest": include_lowest,
730 },
731 )

~/miniconda3/lib/python3.7/site-packages/xarray/core/groupby.py in init(self, obj, group, squeeze, grouper, bins, restore_coord_dims, cut_kwargs)
322
323 if bins is not None:
--> 324 if np.isnan(bins).all():
325 raise ValueError("All bin edges are NaN.")
326 binned = pd.cut(group.values, bins, **cut_kwargs)

TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

Output of xr.show_versions()

INSTALLED VERSIONS

commit: None
libhdf5: 1.10.4
libnetcdf: 4.6.2

xarray: 0.14.0
pandas: 0.25.1
numpy: 1.17.2
scipy: 1.3.0
netCDF4: 1.5.1.2
pydap: installed
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: 1.0.3.4
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: None
dask: 2.2.0
distributed: 2.5.2
matplotlib: 3.1.1
cartopy: 0.17.0
seaborn: 0.9.0
numbagg: None
setuptools: 41.4.0
pip: 19.3
conda: 4.7.12
pytest: 5.1.1
IPython: 7.8.0
sphinx: None

@dcherian
Copy link
Contributor

Another bug I introduced.

if bins is not None:
if np.isnan(bins).all():
raise ValueError("All bin edges are NaN.")
binned = pd.cut(group.values, bins, **cut_kwargs)

I think we replace isnan with duck_array_ops.isnull

can you send in a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants