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

ModuleNotFoundError: No module named 'xarray.core.arithmetic' when trying to import xclim #2123

Closed
1 task done
bweeding opened this issue Mar 25, 2025 · 3 comments
Closed
1 task done
Assignees
Labels
bug Something isn't working

Comments

@bweeding
Copy link

Generic Issue

  • xclim version: 0.53.2
  • xarray version: 2025.3.0
  • Python version: 3.12.9
  • Operating System: Linux

I've just updated my xarray and xclim, and I now can't import xclim.

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[1], line 12
     10 import dask
     11 import sys
---> 12 import xclim as xc
     13 # from xclim import sdba
     14 # from xclim.sdba.adjustment import QuantileDeltaMapping
     15 import cftime

File /opt/anaconda3/envs/nhat_eval/lib/python3.12/site-packages/xclim/__init__.py:7
      3 from __future__ import annotations
      5 import importlib.resources as _resources
----> 7 from xclim import indices
      8 from xclim.core import units  # noqa
      9 from xclim.core.indicator import build_indicator_module_from_yaml

File /opt/anaconda3/envs/nhat_eval/lib/python3.12/site-packages/xclim/indices/__init__.py:5
      1 """Indices module."""
      3 from __future__ import annotations
----> 5 from xclim.indices._agro import *
      6 from xclim.indices._anuclim import *
      7 from xclim.indices._conversion import *

File /opt/anaconda3/envs/nhat_eval/lib/python3.12/site-packages/xclim/indices/_agro.py:11
      8 import xarray
      9 from scipy.stats import rv_continuous
---> 11 import xclim.indices.run_length as rl
     12 from xclim.core import DateStr, DayOfYearStr, Quantified
     13 from xclim.core.calendar import parse_offset, select_time

File /opt/anaconda3/envs/nhat_eval/lib/python3.12/site-packages/xclim/indices/run_length.py:24
     22 from xclim.core.options import OPTIONS, RUN_LENGTH_UFUNC
     23 from xclim.core.utils import split_auxiliary_coordinates, uses_dask
---> 24 from xclim.indices.helpers import resample_map
     26 npts_opt = 9000
     27 """
     28 Arrays with less than this number of data points per slice will trigger
     29 the use of the ufunc version of run lengths algorithms.
     30 """

File /opt/anaconda3/envs/nhat_eval/lib/python3.12/site-packages/xclim/indices/helpers.py:16
     13 from inspect import stack
     14 from typing import Any, Literal, cast
---> 16 import cf_xarray  # noqa: F401, pylint: disable=unused-import
     17 import cftime
     18 import numba as nb

File /opt/anaconda3/envs/nhat_eval/lib/python3.12/site-packages/cf_xarray/__init__.py:2
      1 from . import sgrid  # noqa
----> 2 from .accessor import CFAccessor  # noqa
      3 from .coding import (  # noqa
      4     decode_compress_to_multi_index,
      5     encode_multi_index_as_compress,
      6 )
      7 from .geometry import cf_to_shapely, shapely_to_cf  # noqa

File /opt/anaconda3/envs/nhat_eval/lib/python3.12/site-packages/cf_xarray/accessor.py:27
     25 import xarray as xr
     26 from xarray import DataArray, Dataset
---> 27 from xarray.core.arithmetic import SupportsArithmetic
     28 from xarray.core.groupby import GroupBy
     29 from xarray.core.resample import Resample

ModuleNotFoundError: No module named 'xarray.core.arithmetic'

Code of Conduct

  • I agree to follow this project's Code of Conduct
@Zeitsperre
Copy link
Collaborator

Hi Ben,

Thanks for the report. This is an issue with the newest version of xarray (v2025.3.0). xclim makes use of a lot of xarray internals, and sometimes they refactor their internal API. We currently have a pull request to make less use of their internals (#2116), but in the meantime, installing an older xarray will fix this issue.

We should be releasing a new version with these fixes either today or tomorrow.

@Zeitsperre Zeitsperre added the bug Something isn't working label Mar 25, 2025
@Zeitsperre Zeitsperre self-assigned this Mar 25, 2025
@aulemahal
Copy link
Collaborator

@bweeding and @Zeitsperre, indeed #2116 removes a lot of xarray's internals and fixes a few problems arising from the latest xarray.

However, the exact but here is coming from cf-xarray and not xclim. It looks like it is fixed in cf-xarray v0.10.4. So, when we release xclim 0.56, make sure to have the latest cf-xarray as well!

@bweeding
Copy link
Author

Ok cheers, will do!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants