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

Add xarray.show_backends alias #9821

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Top-level functions
dot
polyval
map_blocks
show_backends
show_versions
set_options
get_options
Expand Down
2 changes: 2 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ v.2024.12.0 (unreleased)

New Features
~~~~~~~~~~~~
- Add :py:func:`~xarray.show_backends` alias for :py:func:`~xarray.backends.list_engines` (:issue:`6577`, :pull:`9821`).
By `Nick Hodgskin <https://github.com/VeckoTheGecko>`_.
- Better support wrapping additional array types (e.g. ``cupy`` or ``jax``) by calling generalized
duck array operations throughout more xarray methods. (:issue:`7848`, :pull:`9798`).
By `Sam Levang <https://github.com/slevang>`_.
Expand Down
2 changes: 2 additions & 0 deletions xarray/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
open_mfdataset,
save_mfdataset,
)
from xarray.backends.plugins import show_backends
from xarray.backends.zarr import open_zarr
from xarray.coding.cftime_offsets import cftime_range, date_range, date_range_like
from xarray.coding.cftimeindex import CFTimeIndex
Expand Down Expand Up @@ -108,6 +109,7 @@
"register_datatree_accessor",
"save_mfdataset",
"set_options",
"show_backends",
"show_versions",
"unify_chunks",
"where",
Expand Down
13 changes: 13 additions & 0 deletions xarray/backends/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,19 @@ def list_engines() -> dict[str, BackendEntrypoint]:
return build_engines(entrypoints)


def show_backends() -> dict[str, BackendEntrypoint]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def show_backends() -> dict[str, BackendEntrypoint]:
show_backends = list_engines

Would be easier.

"""
Return a dictionary of available engines and their BackendEntrypoint objects.

This function is an alias for ``xarray.backends.list_engines``.

Returns
-------
dictionary
"""
return list_engines()


def refresh_engines() -> None:
"""Refreshes the backend engines based on installed packages."""
list_engines.cache_clear()
Expand Down
7 changes: 7 additions & 0 deletions xarray/tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ def test_list_engines() -> None:
assert "store" in engines


def test_show_engines() -> None:
from xarray import show_backends
from xarray.backends import list_engines

assert show_backends() == list_engines()


def test_refresh_engines() -> None:
from xarray.backends import list_engines, refresh_engines

Expand Down
Loading