[Bug] ModuleNotFoundError with xarray >= v2025.03.0

Open
#566 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
data

Research direction

Start with cf_xarray/accessor.py and reproduce the import failure using xarray v2025.03.0, comparing it with the working v2025.01.2 setup. Check the referenced xarray arithmetic module move and any other affected imports; done means cf_xarray imports successfully with the newer xarray release and its relevant tests pass.

Written by the indexing model from the issue text.

Description

Xarray's v2025.03.0 release last week seems to have included a breaking change that results in cf_xarray erroring out on import.

After I updated our dependencies today, xarray got bumped from v2025.01.2 to v2025.03.0, and I starting seeing this error in my stack trace:

my/code/common/io.py:16: in <module>
    from cf_xarray import decode_compress_to_multi_index, encode_multi_index_as_compress
.venv/lib/python3.11/site-packages/cf_xarray/__init__.py:2: in <module>
    from .accessor import CFAccessor  # noqa
.venv/lib/python3.11/site-packages/cf_xarray/accessor.py:27: in <module>
    from xarray.core.arithmetic import SupportsArithmetic
E   ModuleNotFoundError: No module named 'xarray.core.arithmetic'

When I pin the constraint for xarray to xarray >= 2023.10.1, < 2025.3.0 I no longer see this issue, so I have a good workaround, just wanted to make sure to report in case you have the appetite to fix the issue or other followers encounter the same problem.

You can see the problematic file move in question here (xarray/core/arithmetic.py → xarray/computation/arithmetic.py). There may be others.

Dominant language
Python
Stars
181
Forks
49
Avg merge
43m
Merged PRs (30d)
1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from xarray-contrib/cf-xarray

All issues in xarray-contrib/cf-xarray

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.