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

plugins.py:98: DeprecationWarning: SelectableGroups dict interface is deprecated. Use select. #6514

Closed
alexamici opened this issue Apr 25, 2022 · 4 comments · Fixed by #6516
Labels

Comments

@alexamici
Copy link
Collaborator

alexamici commented Apr 25, 2022

What happened?

The plugin interface warns with DeprecationWarning in python 3.10.

What did you expect to happen?

No warning to be issued.

Minimal Complete Verifiable Example

Running `pytest` on any *Xarray* importing test.

Relevant log output

   .../python3.10/site-packages/xarray/backends/plugins.py:98: DeprecationWarning: SelectableGroups dict interface is deprecated. Use select.
    entrypoints = entry_points().get("xarray.backends", ())

Anything else we need to know?

According to the Compatibity note in:

https://docs.python.org/3/library/importlib.metadata.html#entry-points

the new API is entry_points(group='xarray.backends')

Environment

INSTALLED VERSIONS ------------------ commit: None python: 3.10.4 | packaged by conda-forge | (main, Mar 24 2022, 17:42:03) [Clang 12.0.1 ] python-bits: 64 OS: Darwin OS-release: 21.3.0 machine: arm64 processor: arm byteorder: little LC_ALL: None LANG: None LOCALE: (None, 'UTF-8') libhdf5: None libnetcdf: None

xarray: 2022.3.0
pandas: 1.4.2
numpy: 1.22.3
scipy: 1.8.0
netCDF4: None
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: 2.11.3
cftime: None
nc_time_axis: None
PseudoNetCDF: None
rasterio: 1.2.10
cfgrib: None
iris: None
bottleneck: None
dask: 2022.04.1
distributed: 2022.4.1
matplotlib: 3.5.1
cartopy: None
seaborn: None
numbagg: None
fsspec: 2022.3.0
cupy: None
pint: None
sparse: None
setuptools: 62.1.0
pip: 22.0.4
conda: 4.12.0
pytest: 7.1.2
IPython: 8.2.0
sphinx: None

@alexamici alexamici added bug needs triage Issue that has not been reviewed by xarray team member labels Apr 25, 2022
@dcherian dcherian removed the needs triage Issue that has not been reviewed by xarray team member label Apr 25, 2022
@bcbnz
Copy link
Contributor

bcbnz commented Apr 26, 2022

Just came to report this after seeing it in some tests of one of my projects. Based on a change I made for plugins in that project, I think that changing

@functools.lru_cache(maxsize=1)
def list_engines():
entrypoints = entry_points().get("xarray.backends", ())
return build_engines(entrypoints)

to

    @functools.lru_cache(maxsize=1)
    def list_engines():
        try:
            entrypoints = entry_points(group="xarray.backends")  # Python >= 3.10
        except TypeError:
            entrypoints = entry_points().get("xarray.backends", ())
        return build_engines(entrypoints)

will take care of this. Not tested as I don't have access to an older Python environment right now, but I can make a pull request later if this would be a suitable workaround and nobody else does so first.

@dcherian
Copy link
Contributor

@bcbnz please open a PR if you have the time.

One suggestion would be to use an explicit version check using sys.version_info() instead of catching TypeError

@alexamici
Copy link
Collaborator Author

The Compatibility Note I linked above appears to point out the the entry_points(group="xarray.backends") is available since Python 3.6, so we not need the versione check at all.

@bcbnz
Copy link
Contributor

bcbnz commented Apr 26, 2022

The Compatibility Note I linked above appears to point out the the entry_points(group="xarray.backends") is available since Python 3.6, so we not need the versione check at all.

There's some unfortunate version numbers there. That refers to version 3.6 of the third-party importlib_metadata library, a later version of which was used for the importlib.metadata library included with Python 3.10. If you try to run entry_points(group="xarray.backends") on Python 3.9 it fails with a TypeError.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants