home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 1793236828

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
1793236828 I_kwDOAMm_X85q4p9c 7965 Maximum recursion calling `np.divide` with `DataArray` as `where` argument 1486942 open 0     2 2023-07-07T10:11:28Z 2023-07-07T15:16:06Z   CONTRIBUTOR      

What happened?

Calling np.divide() passing a bool expression involving a DataArray results in a RecursionError starting at apply_ufunc. Passing DataArray.data works fine.

What did you expect to happen?

No response

Minimal Complete Verifiable Example

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

N = 10 array = np.random.random((N,)) da = xr.DataArray(np.random.random((N,)), dims=("x",), coords={"x": np.arange(N)})

This works

print(np.divide(array, da, where=(da > 0.2).data))

This gives recursion error

print(np.divide(array, da, where=da > 0.2)) ```

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 Traceback (most recent call last): File "divide_recursion_mvce.py", line 7, in <module> print(np.divide(array, da, where=da > 0.2)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "venv/lib64/python3.11/site-packages/xarray/core/arithmetic.py", line 86, in array_ufunc return apply_ufunc( ^^^^^^^^^^^^ File "venv/lib64/python3.11/site-packages/xarray/core/computation.py", line 1197, in apply_ufunc return apply_dataarray_vfunc( ^^^^^^^^^^^^^^^^^^^^^^ File "venv/lib64/python3.11/site-packages/xarray/core/computation.py", line 304, in apply_dataarray_vfunc result_var = func(data_vars) ^^^^^^^^^^^^^^^^ File "venv/lib64/python3.11/site-packages/xarray/core/computation.py", line 761, in apply_variable_ufunc result_data = func(input_data) ^^^^^^^^^^^^^^^^^ File "venv/lib64/python3.11/site-packages/xarray/core/arithmetic.py", line 86, in array_ufunc return apply_ufunc( ^^^^^^^^^^^^ File "venv/lib64/python3.11/site-packages/xarray/core/computation.py", line 1210, in apply_ufunc return apply_array_ufunc(func, *args, dask=dask) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

...

File "venv/lib64/python3.11/site-packages/xarray/core/computation.py", line 1210, in apply_ufunc return apply_array_ufunc(func, *args, dask=dask) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "venv/lib64/python3.11/site-packages/xarray/core/computation.py", line 815, in apply_array_ufunc if any(is_chunked_array(arg) for arg in args): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "venv/lib64/python3.11/site-packages/xarray/core/computation.py", line 815, in <genexpr> if any(is_chunked_array(arg) for arg in args): ^^^^^^^^^^^^^^^^^^^^^ File "venv/lib64/python3.11/site-packages/xarray/core/pycompat.py", line 99, in is_chunked_array return is_duck_dask_array(x) or (is_duck_array(x) and hasattr(x, "chunks")) ^^^^^^^^^^^^^^^^^^^^^ File "venv/lib64/python3.11/site-packages/xarray/core/pycompat.py", line 95, in is_duck_dask_array return is_duck_array(x) and is_dask_collection(x) ^^^^^^^^^^^^^^^^^^^^^ File "venv/lib64/python3.11/site-packages/xarray/core/pycompat.py", line 87, in is_dask_collection if module_available("dask"): ^^^^^^^^^^^^^^^^^^^^^^^^ File "venv/lib64/python3.11/site-packages/xarray/core/utils.py", line 1160, in module_available return importlib.util.find_spec(module) is not None ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<frozen importlib.util>", line 103, in find_spec File "<frozen importlib._bootstrap>", line 1080, in _find_spec File "<frozen importlib._bootstrap>", line 924, in find_spec File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed RecursionError: maximum recursion depth exceeded while calling a Python object ```

Anything else we need to know?

No response

Environment

INSTALLED VERSIONS ------------------ commit: None python: 3.11.3 (main, Apr 27 2023, 22:08:21) [GCC] python-bits: 64 OS: Linux OS-release: 6.3.9-1-default machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_GB.UTF-8 LOCALE: ('en_GB', 'UTF-8') libhdf5: 1.12.2 libnetcdf: 4.9.3-development xarray: 2023.6.0 pandas: 1.5.3 numpy: 1.25.0 scipy: 1.11.1 netCDF4: 1.6.4 pydap: None h5netcdf: None h5py: None Nio: None zarr: None cftime: 1.6.2 nc_time_axis: None PseudoNetCDF: None iris: None bottleneck: None dask: None distributed: None matplotlib: 3.7.2 cartopy: None seaborn: None numbagg: None fsspec: None cupy: None pint: None sparse: None flox: None numpy_groupies: None setuptools: 65.5.0 pip: 23.1.2 conda: None pytest: 7.4.0 mypy: None IPython: 8.14.0 sphinx: None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/7965/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
    13221727 issue

Links from other tables

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