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

Cannot import xarray.core.rolling with xarray version 2025.3.0 and python 3.11 #10179

Open
5 tasks done
YassineAbdelouadoud opened this issue Mar 27, 2025 · 11 comments · May be fixed by #10215
Open
5 tasks done

Cannot import xarray.core.rolling with xarray version 2025.3.0 and python 3.11 #10179

YassineAbdelouadoud opened this issue Mar 27, 2025 · 11 comments · May be fixed by #10215

Comments

@YassineAbdelouadoud
Copy link

What happened?

When installing xarray version 2025.3.0 in a conda environment with the python version pinned to 3.11, the import of xarray.core.rolling fails with ModuleNotFoundError: No module named 'xarray.core.rolling'

Below is a conda env file that allows the reproduction :

name: xarray_test_env
channels:
  - conda-forge
dependencies:
  - python=3.11
  - xarray=2025.3.0

It should be noted that this issue is not present with python 3.12 or later. It is also not present for earlier versions of xarray.

What did you expect to happen?

import xarray.core.rolling should not raise an error

Minimal Complete Verifiable Example

import xarray.core.rolling

MVCE confirmation

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

Relevant log output

Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'xarray.core.rolling'

Anything else we need to know?

#6844 could be related

Environment

INSTALLED VERSIONS ------------------ commit: None python: 3.11.11 | packaged by conda-forge | (main, Mar 3 2025, 20:43:55) [GCC 13.3.0] python-bits: 64 OS: Linux OS-release: 5.4.0-198-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: fr_FR.UTF-8 LOCALE: ('fr_FR', 'UTF-8') libhdf5: None libnetcdf: None

xarray: 2025.3.0
pandas: 2.2.3
numpy: 2.2.4
scipy: None
netCDF4: None
pydap: None
h5netcdf: None
h5py: None
zarr: None
cftime: None
nc_time_axis: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: None
cartopy: None
seaborn: None
numbagg: None
fsspec: None
cupy: None
pint: None
sparse: None
flox: None
numpy_groupies: None
setuptools: 75.8.2
pip: 25.0.1
conda: None
pytest: None
mypy: None
IPython: None
sphinx: None

@YassineAbdelouadoud YassineAbdelouadoud added bug needs triage Issue that has not been reviewed by xarray team member labels Mar 27, 2025
Copy link

welcome bot commented Mar 27, 2025

Thanks for opening your first issue here at xarray! Be sure to follow the issue template!
If you have an idea for a solution, we would really welcome a Pull Request with proposed changes.
See the Contributing Guide for more.
It may take us a while to respond here, but we really value your contribution. Contributors like you help make xarray better.
Thank you!

@keewis
Copy link
Collaborator

keewis commented Mar 27, 2025

for reference, anything in xarray.core is private API and thus can change at any time.

What are you using xarray.core.rolling for? If this is about anything in the public API (like DatasetRolling for use as a type hint, for example), we may be able to find a way to provide a stable import path for that.

cc @max-sixty

Edit: oh, wait, I didn't notice that this only happens on python=3.11. Let me check what is actually going on here.
Edit2: I can't reproduce with

mamba create -n test python=3.12 xarray=2025.03.0; conda activate test; python -c 'import xarray.core.rolling'; conda deactivate

This always fails for me, regardless of the python version used to create the environment.

@keewis keewis removed the needs triage Issue that has not been reviewed by xarray team member label Mar 27, 2025
@YassineAbdelouadoud
Copy link
Author

I am not using the private API directly, but it is used by linopy in expressions.py

But I see now that their latest version has the following code at the beginning :

try:
    # resolve breaking change in xarray 2025.03.0
    import xarray.computation.rolling
    from xarray.computation.rolling import DatasetRolling
except ImportError:
    import xarray.core.rolling
    from xarray.core.rolling import DatasetRolling  # type: ignore

So my issue comes down to using an outdated version of linopy.
Also I was mistaken on the fact it worked with later python version.

@keewis
Copy link
Collaborator

keewis commented Mar 27, 2025

As suspected, that import appears to be for type hinting purposes. I guess that means we should provide a stable import path / an official way for type hinting the return values of our various operations that return intermediate objects.

@pydata/xarray, what do you think?

@dcherian
Copy link
Contributor

Makes sense to me.

@max-sixty
Copy link
Collaborator

Yes, good idea. What's the best place for that? xarray.types / xarray.api?

@dcherian
Copy link
Contributor

types has a lot of internal stuff too. So, somewhere else would be good!

@keewis
Copy link
Collaborator

keewis commented Mar 27, 2025

xarray.typing?

@micguerr-bopen
Copy link

Hi all,

I've recently joined B-Open and started working with xarray and would love to get more involved as a contributor.
I thought implementing a typing module could be a good starting point.

I have a couple of questions to better understand how you'd approach this:

  1. Would you prefer to implement the typing module as a single file (xarray/typing.py), or as a package (xarray/typing/ with an __init__.py)?
  2. There are many internal types in xarray that could potentially be included, but I understand that not all of them should be exposed. Is there a recommended way to decide which types belong in the typing module? One idea I had was to include only types that are referenced in the public documentation—do you think that would be a reasonable approach?

Thanks for your help and for maintaining such a great library!

Best,
Michele

@max-sixty
Copy link
Collaborator

hi @micguerr-bopen !

that would be very welcome!

I think we can start with just xarray/typing.py, and start with some of the "bigger" types that aren't at the top level. things like D*Rolling, group by types — if you have the patience then looking through what used to be in xarray.core

we could add a docstring saying these are public API and can be referenced by other libraries

@keewis
Copy link
Collaborator

keewis commented Apr 8, 2025

I'd probably choose whatever is in the docs for a first pass, and only then go through the code to see what's missing (which we should then also document)

@micguerr-bopen micguerr-bopen linked a pull request Apr 11, 2025 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants