Skip to content

Version 0.13 broke my ufunc #3339

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

Closed
rsignell-usgs opened this issue Sep 24, 2019 · 5 comments
Closed

Version 0.13 broke my ufunc #3339

rsignell-usgs opened this issue Sep 24, 2019 · 5 comments

Comments

@rsignell-usgs
Copy link

rsignell-usgs commented Sep 24, 2019

This simple xarray ufunc to calculate wind speed worked under xarray=0.12.3:

import xarray as xr
url = 'http://thredds.ucar.edu/thredds/dodsC/grib/NCEP/HRRR/CONUS_2p5km/Best'
ds = xr.open_dataset(url, chunks={'time1':1})
windspeed = xr.ufuncs.sqrt(ds['u-component_of_wind_height_above_ground']**2 + ds['v-component_of_wind_height_above_ground']**2)

but with xarray=0.13.0, merge_variables fails and dumps this traceback:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-2ac66965ccfc> in <module>
----> 1 windspeed = xr.ufuncs.sqrt(ds['u-component_of_wind_height_above_ground']**2 + ds['v-component_of_wind_height_above_ground']**2)

/srv/conda/envs/notebook/lib/python3.7/site-packages/xarray/core/dataarray.py in func(self, other)
   2495                 else f(other_variable, self.variable)
   2496             )
-> 2497             coords = self.coords._merge_raw(other_coords)
   2498             name = self._result_name(other)
   2499 

/srv/conda/envs/notebook/lib/python3.7/site-packages/xarray/core/coordinates.py in _merge_raw(self, other)
    128         else:
    129             # don't align because we already called xarray.align
--> 130             variables = expand_and_merge_variables([self.variables, other.variables])
    131         return variables
    132 

/srv/conda/envs/notebook/lib/python3.7/site-packages/xarray/core/merge.py in expand_and_merge_variables(objs, priority_arg)
    380     expanded = expand_variable_dicts(objs)
    381     priority_vars = _get_priority_vars(objs, priority_arg)
--> 382     variables = merge_variables(expanded, priority_vars)
    383     return variables
    384 

/srv/conda/envs/notebook/lib/python3.7/site-packages/xarray/core/merge.py in merge_variables(list_of_variables_dicts, priority_vars, compat)
    202             else:
    203                 try:
--> 204                     merged[name] = unique_variable(name, var_list, compat)
    205                 except MergeError:
    206                     if compat != "minimal":

/srv/conda/envs/notebook/lib/python3.7/site-packages/xarray/core/merge.py in unique_variable(name, variables, compat, equals)
    116         out = out.compute()
    117         for var in variables[1:]:
--> 118             equals = getattr(out, compat)(var)
    119             if not equals:
    120                 break

/srv/conda/envs/notebook/lib/python3.7/site-packages/xarray/core/variable.py in broadcast_equals(self, other, equiv)
   1574         except (ValueError, AttributeError):
   1575             return False
-> 1576         return self.equals(other, equiv=equiv)
   1577 
   1578     def identical(self, other):

/srv/conda/envs/notebook/lib/python3.7/site-packages/xarray/core/variable.py in equals(self, other, equiv)
   1558         try:
   1559             return self.dims == other.dims and (
-> 1560                 self._data is other._data or equiv(self.data, other.data)
   1561             )
   1562         except (TypeError, AttributeError):

/srv/conda/envs/notebook/lib/python3.7/site-packages/xarray/core/duck_array_ops.py in array_equiv(arr1, arr2)
    200     with warnings.catch_warnings():
    201         warnings.filterwarnings("ignore", "In the future, 'NAT == x'")
--> 202         flag_array = (arr1 == arr2) | (isnull(arr1) & isnull(arr2))
    203         return bool(flag_array.all())
    204 

/srv/conda/envs/notebook/lib/python3.7/site-packages/dask/array/core.py in __eq__(self, other)
   1740 
   1741     def __eq__(self, other):
-> 1742         return elemwise(operator.eq, self, other)
   1743 
   1744     def __gt__(self, other):

/srv/conda/envs/notebook/lib/python3.7/site-packages/dask/array/core.py in elemwise(op, *args, **kwargs)
   3765             for a in args
   3766         ),
-> 3767         **blockwise_kwargs
   3768     )
   3769 

/srv/conda/envs/notebook/lib/python3.7/site-packages/dask/array/blockwise.py in blockwise(func, out_ind, name, token, dtype, adjust_chunks, new_axes, align_arrays, concatenate, meta, *args, **kwargs)
    143 
    144     if align_arrays:
--> 145         chunkss, arrays = unify_chunks(*args)
    146     else:
    147         arginds = [(a, i) for (a, i) in toolz.partition(2, args) if i is not None]

/srv/conda/envs/notebook/lib/python3.7/site-packages/dask/array/core.py in unify_chunks(*args, **kwargs)
   3034 
   3035     arginds = [
-> 3036         (asanyarray(a) if ind is not None else a, ind) for a, ind in partition(2, args)
   3037     ]  # [x, ij, y, jk]
   3038     args = list(concat(arginds))  # [(x, ij), (y, jk)]

/srv/conda/envs/notebook/lib/python3.7/site-packages/dask/array/core.py in <listcomp>(.0)
   3034 
   3035     arginds = [
-> 3036         (asanyarray(a) if ind is not None else a, ind) for a, ind in partition(2, args)
   3037     ]  # [x, ij, y, jk]
   3038     args = list(concat(arginds))  # [(x, ij), (y, jk)]

/srv/conda/envs/notebook/lib/python3.7/site-packages/dask/array/core.py in asanyarray(a)
   3609     elif hasattr(a, "to_dask_array"):
   3610         return a.to_dask_array()
-> 3611     elif hasattr(a, "data") and type(a).__module__.startswith("xarray."):
   3612         return asanyarray(a.data)
   3613     elif isinstance(a, (list, tuple)) and any(isinstance(i, Array) for i in a):

ValueError: cannot include dtype 'M' in a buffer

Is this a bug or a feature that I should be handling differently in my code?

Output of xr.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.7.3 | packaged by conda-forge | (default, Jul 1 2019, 21:52:21)
[GCC 7.3.0]
python-bits: 64
OS: Linux
OS-release: 4.14.138-114.102.amzn2.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
libhdf5: 1.10.5
libnetcdf: 4.6.2

xarray: 0.13.0
pandas: 0.24.2
numpy: 1.17.2
scipy: 1.3.1
netCDF4: 1.5.1.2
pydap: installed
h5netcdf: 0.7.4
h5py: 2.10.0
Nio: None
zarr: 2.3.2
cftime: 1.0.3.4
nc_time_axis: None
PseudoNetCDF: None
rasterio: 1.0.28
cfgrib: None
iris: 2.2.0
bottleneck: None
dask: 2.2.0
distributed: 2.2.0
matplotlib: 3.1.1
cartopy: 0.17.0
seaborn: None
numbagg: None
setuptools: 41.2.0
pip: 19.2.3
conda: None
pytest: None
IPython: 7.8.0
sphinx: None

@jhamman
Copy link
Member

jhamman commented Sep 24, 2019

@rsignell-usgs - can you add the output from xr.show_versions()? This seems to work for me with xarray=0.13 and numpy=1.17.2.

INSTALLED VERSIONS

commit: None
python: 3.6.7 | packaged by conda-forge | (default, Jul 2 2019, 02:18:42)
[GCC 7.3.0]
python-bits: 64
OS: Linux
OS-release: 3.10.0-693.21.1.el7.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
libhdf5: 1.10.4
libnetcdf: 4.6.2

xarray: 0.13.0
pandas: 0.25.1
numpy: 1.17.2
scipy: 1.3.1
netCDF4: 1.5.1.2
pydap: None
h5netcdf: 0.7.4
h5py: 2.9.0
Nio: None
zarr: 2.3.2
cftime: 1.0.3.4
nc_time_axis: 1.2.0
PseudoNetCDF: None
rasterio: 1.0.28
cfgrib: None
iris: None
bottleneck: None
dask: 2.4.0
distributed: 2.4.0
matplotlib: 3.1.1
cartopy: 0.17.0
seaborn: 0.9.0
numbagg: None
setuptools: 41.2.0
pip: 19.2.3
conda: None
pytest: None
IPython: 7.8.0
sphinx: None

@shoyer
Copy link
Member

shoyer commented Sep 24, 2019

There was a recent bug fix in dask about this (dask/dask#5334). Can you try updating to the latest dask release?

@rsignell-usgs
Copy link
Author

@shoyer , indeed, while I have the same xarray=0.13 and numpy=1.17.2 as @jhamman, he has dask=2.4.0 and I have dask=2.2.0. I'll try upgrading and will report back.

@rsignell-usgs
Copy link
Author

Yep, upgrading to dask=2.4.0 fixed the problem! Phew.

@crusaderky
Copy link
Contributor

Related: #3222

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

No branches or pull requests

4 participants