Skip to content

Commit

Permalink
Add xarray.show_backends alias
Browse files Browse the repository at this point in the history
  • Loading branch information
VeckoTheGecko committed Nov 25, 2024
1 parent 552a74b commit bed7e1d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
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
3 changes: 2 additions & 1 deletion doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ v.2024.11.1 (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>`_.

Breaking changes
~~~~~~~~~~~~~~~~
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]:
"""
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

0 comments on commit bed7e1d

Please sign in to comment.