home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 1419649041

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
1419649041 I_kwDOAMm_X85UniAR 7198 `groupby_bins` raises `AttributeError` when used with Dask, flox and option `labels` 43613877 closed 0     0 2022-10-23T05:44:04Z 2022-10-26T15:56:36Z 2022-10-26T15:56:36Z CONTRIBUTOR      

What happened?

I updated xarray and installed flox in my environment which caused my previously working call of groupby_bins to fail. The failure only occurs when I use the labels-options.

What did you expect to happen?

I expected that groupby_bins would work independent of the used algorithm.

Minimal Complete Verifiable Example

```Python import dask import xarray as xr import numpy as np

ds = xr.Dataset({"d":(("x","y"),dask.array.random.random((10,20)))}, coords={'x':np.arange(10),'y':np.arange(10,30)}) xr.set_options(use_flox=True) ds.groupby_bins('x', np.arange(0,11,5), labels=[5,10]).sum().compute() ```

MVCE confirmation

  • [X] Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • [X] Complete example — the example is self-contained, including all data and the text of any traceback.
  • [X] Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • [X] New issue — a search of GitHub Issues suggests this is not a duplicate.

Relevant log output

```Python

AttributeError Traceback (most recent call last) Cell In [1], line 7 5 ds = xr.Dataset({"d":(("x","y"),dask.array.random.random((10,20)))}, coords={'x':np.arange(10),'y':np.arange(10,30)}) 6 xr.set_options(use_flox=True) ----> 7 ds.groupby_bins('x', np.arange(0,11,5), labels=[5,10]).sum().compute()

File ~/mambaforge/envs/flox/lib/python3.10/site-packages/xarray/core/_reductions.py:2774, in DatasetGroupByReductions.sum(self, dim, skipna, min_count, keep_attrs, kwargs) 2678 """ 2679 Reduce this Dataset's data by applying sum along some dimension(s). 2680 (...) 2771 da (labels) float64 nan 4.0 4.0 2772 """ 2773 if flox and OPTIONS["use_flox"] and contains_only_dask_or_numpy(self._obj): -> 2774 return self._flox_reduce( 2775 func="sum", 2776 dim=dim, 2777 skipna=skipna, 2778 min_count=min_count, 2779 numeric_only=True, 2780 # fill_value=fill_value, 2781 keep_attrs=keep_attrs, 2782 kwargs, 2783 ) 2784 else: 2785 return self.reduce( 2786 duck_array_ops.sum, 2787 dim=dim, (...) 2792 **kwargs, 2793 )

File ~/mambaforge/envs/flox/lib/python3.10/site-packages/xarray/core/groupby.py:774, in GroupBy._flox_reduce(self, dim, keep_attrs, **kwargs) 769 if self._bins is not None: 770 # bins provided to flox are at full precision 771 # the bin edge labels have a default precision of 3 772 # reassign to fix that. 773 assert self._full_index is not None --> 774 new_coord = [ 775 pd.Interval(inter.left, inter.right) for inter in self._full_index 776 ] 777 result[self._group.name] = new_coord 778 # Fix dimension order when binning a dimension coordinate 779 # Needed as long as we do a separate code path for pint; 780 # For some reason Datasets and DataArrays behave differently!

File ~/mambaforge/envs/flox/lib/python3.10/site-packages/xarray/core/groupby.py:775, in <listcomp>(.0) 769 if self._bins is not None: 770 # bins provided to flox are at full precision 771 # the bin edge labels have a default precision of 3 772 # reassign to fix that. 773 assert self._full_index is not None 774 new_coord = [ --> 775 pd.Interval(inter.left, inter.right) for inter in self._full_index 776 ] 777 result[self._group.name] = new_coord 778 # Fix dimension order when binning a dimension coordinate 779 # Needed as long as we do a separate code path for pint; 780 # For some reason Datasets and DataArrays behave differently!

AttributeError: 'int' object has no attribute 'left' ```

Anything else we need to know?

python xr.set_options(use_flox=False) ds.groupby_bins('x', np.arange(0,11,5), labels=[5,10]).sum().compute() works as expected.

Environment

INSTALLED VERSIONS ------------------ commit: None python: 3.10.6 | packaged by conda-forge | (main, Aug 22 2022, 20:43:44) [Clang 13.0.1 ] python-bits: 64 OS: Darwin OS-release: 21.6.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: None LOCALE: (None, 'UTF-8') libhdf5: None libnetcdf: None xarray: 2022.10.0 pandas: 1.5.1 numpy: 1.23.4 scipy: None netCDF4: None pydap: None h5netcdf: None h5py: None Nio: None zarr: None cftime: None nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: 2022.10.0 distributed: 2022.10.0 matplotlib: None cartopy: None seaborn: None numbagg: None fsspec: 2022.10.0 cupy: None pint: None sparse: None flox: 0.6.1 numpy_groupies: 0.9.20 setuptools: 65.5.0 pip: 22.3 conda: None pytest: None IPython: 8.5.0 sphinx: None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/7198/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

  • 3 rows from issues_id in issues_labels
  • 0 rows from issue in issue_comments
Powered by Datasette · Queries took 0.699ms · About: xarray-datasette