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

import_metadata==5.0.0 causes error when loading netcdf file #7115

Closed
4 tasks done
EtienneCmb opened this issue Oct 3, 2022 · 5 comments
Closed
4 tasks done

import_metadata==5.0.0 causes error when loading netcdf file #7115

EtienneCmb opened this issue Oct 3, 2022 · 5 comments
Labels
bug needs triage Issue that has not been reviewed by xarray team member

Comments

@EtienneCmb
Copy link
Contributor

What happened?

Loading an .nc file under Python 3.7 and with the latest importlib_metadata==5.0.0 doesn't work.

What did you expect to happen?

File should be loaded.

Minimal Complete Verifiable Example

# Python version 3.7
# import_metadata==5.0.0

import xarray as xr
import numpy as np

data = xr.DataArray(
    np.random.rand(10, 20)
)
data.to_netcdf('test.nc')
xr.load_dataarray('test.nc')

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.

Relevant log output

Traceback (most recent call last):
  File "xarray_bug.py", line 7, in <module>
    xr.load_dataarray('test.nc')
  File "/home/etienne/anaconda3/envs/py37/lib/python3.7/site-packages/xarray/backends/api.py", line 267, in load_dataarray
    with open_dataarray(filename_or_obj, **kwargs) as da:
  File "/home/etienne/anaconda3/envs/py37/lib/python3.7/site-packages/xarray/backends/api.py", line 666, in open_dataarray
    **kwargs,
  File "/home/etienne/anaconda3/envs/py37/lib/python3.7/site-packages/xarray/backends/api.py", line 479, in open_dataset
    engine = plugins.guess_engine(filename_or_obj)
  File "/home/etienne/anaconda3/envs/py37/lib/python3.7/site-packages/xarray/backends/plugins.py", line 110, in guess_engine
    engines = list_engines()
  File "/home/etienne/anaconda3/envs/py37/lib/python3.7/site-packages/xarray/backends/plugins.py", line 105, in list_engines
    entrypoints = entry_points().get("xarray.backends", ())
AttributeError: 'EntryPoints' object has no attribute 'get'

Anything else we need to know?

Environment

INSTALLED VERSIONS

commit: None
python: 3.7.12 | packaged by conda-forge | (default, Oct 26 2021, 06:08:21)
[GCC 9.4.0]
python-bits: 64
OS: Linux
OS-release: 5.4.210-1-MANJARO
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: fr_FR.UTF-8
LOCALE: ('fr_FR', 'UTF-8')
libhdf5: 1.12.2
libnetcdf: 4.9.0

xarray: 0.20.2
pandas: 1.3.5
numpy: 1.21.6
scipy: None
netCDF4: 1.6.1
pydap: None
h5netcdf: 1.0.2
h5py: 3.7.0
Nio: None
zarr: None
cftime: 1.6.2
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: 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
setuptools: 65.4.1
pip: 22.2.2
conda: None
pytest: None
IPython: 7.34.0
sphinx: None

@EtienneCmb EtienneCmb added bug needs triage Issue that has not been reviewed by xarray team member labels Oct 3, 2022
@Illviljan
Copy link
Contributor

Illviljan commented Oct 3, 2022

Hello,

We try to follow nep-29 and intend to only support python >=3.8:

xarray/setup.cfg

Lines 72 to 76 in f5884a2

[options]
packages = find:
zip_safe = False # https://mypy.readthedocs.io/en/latest/installed_packages.html
include_package_data = True
python_requires = >=3.8

There's a change to this behavior in 3.10 as well, see:

# New selection mechanism introduced with Python 3.10. See GH6514.
if sys.version_info >= (3, 10):
entrypoints = entry_points(group="xarray.backends")
else:
entrypoints = entry_points().get("xarray.backends", ())

@EtienneCmb
Copy link
Contributor Author

Ok, thank you. I need to update my env then :)

@Illviljan
Copy link
Contributor

If you want to investigate more, feel free to try with python 3.8 as well.
Our CI seems to install importlib-metadata 4.11.4 py310hff52083_0 conda-forge for python 3.8 so maybe there's an issue there?

@dcherian
Copy link
Contributor

dcherian commented Oct 3, 2022

I need to update my env then

Thanks @EtienneCmb

@dcherian dcherian closed this as completed Oct 3, 2022
@observingClouds
Copy link
Contributor

I was about to open the same issue but can confirm that I only get an issue with python<3.8 and importlib_metadata==5.0.0
@Illviljan , importlib-metadata should not be necessary for python>=3.8 as it became part of the standard library.

juseg added a commit to juseg/hyoga that referenced this issue Nov 17, 2022
There is an incompatibility between `python<3.8` and
`importlib_metadata==5.0.0` and (pydata/xarray#7115, NEP 29).
juseg added a commit to juseg/hyoga that referenced this issue Nov 18, 2022
Without cartopy dependency docs can be built in virtualenv with pip.
The readthedocs builds revealed an incompatibility between `python<3.8`
and `importlib_metadata==5.0.0` (see pydata/xarray#7115, NEP 29).

* Remove readthedocs conda enviromnent.

* Ask readthedocs to use Python 3.8.

* Require Python >= 3.8.

* Remove readthedocs build settings.

* Replace conda with pip for readthedocs build.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug needs triage Issue that has not been reviewed by xarray team member
Projects
None yet
Development

No branches or pull requests

4 participants