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 e5de581
Show file tree
Hide file tree
Showing 5 changed files with 24 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:`xxx`).
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 @@ -51,6 +51,7 @@
TreeIsomorphismError,
group_subtrees,
)
from xarray.backends.plugins import show_backends
from xarray.core.variable import IndexVariable, Variable, as_variable
from xarray.namedarray.core import NamedArray
from xarray.util.print_versions import show_versions
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
6 changes: 6 additions & 0 deletions xarray/tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,12 @@ def test_list_engines() -> None:
assert ("zarr" in engines) == has_zarr
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 e5de581

Please sign in to comment.