From bed7e1dd21ca8e6c338c7876309496ac573768f2 Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Mon, 25 Nov 2024 20:16:04 +0800 Subject: [PATCH] Add xarray.show_backends alias --- doc/api.rst | 1 + doc/whats-new.rst | 3 ++- xarray/__init__.py | 2 ++ xarray/backends/plugins.py | 13 +++++++++++++ xarray/tests/test_plugins.py | 7 +++++++ 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/doc/api.rst b/doc/api.rst index 85ef46ca6ba..103f3984512 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -36,6 +36,7 @@ Top-level functions dot polyval map_blocks + show_backends show_versions set_options get_options diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 0da34df2c1a..4b21c7cf488 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -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 `_. Breaking changes ~~~~~~~~~~~~~~~~ diff --git a/xarray/__init__.py b/xarray/__init__.py index 634f67a61a2..a0abffc2222 100644 --- a/xarray/__init__.py +++ b/xarray/__init__.py @@ -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 @@ -108,6 +109,7 @@ "register_datatree_accessor", "save_mfdataset", "set_options", + "show_backends", "show_versions", "unify_chunks", "where", diff --git a/xarray/backends/plugins.py b/xarray/backends/plugins.py index 555538c2562..c4e09b5939f 100644 --- a/xarray/backends/plugins.py +++ b/xarray/backends/plugins.py @@ -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() diff --git a/xarray/tests/test_plugins.py b/xarray/tests/test_plugins.py index 2b321ba8dfc..4f9b07725e6 100644 --- a/xarray/tests/test_plugins.py +++ b/xarray/tests/test_plugins.py @@ -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