Skip to content

Commit fd42449

Browse files
Illviljankeewis
andauthored
Initialize custom backends in open_dataset (#5684)
* Test using correct signature * Initialize the class like in build_engine * Update whats-new.rst * Update whats-new.rst * Add back self to classes * Add some typing to the test, mypy should fail * mypy failed as expected, should not now Co-authored-by: keewis <keewis@users.noreply.github.com>
1 parent 5499949 commit fd42449

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

doc/whats-new.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ Bug fixes
7171
- Fixed performance bug where ``cftime`` import attempted within various core operations if ``cftime`` not
7272
installed (:pull:`5640`).
7373
By `Luke Sewell <https://github.com/lusewell>`_
74-
74+
- When a custom engine was used in :py:func:`~xarray.open_dataset` the engine
75+
wasn't initialized properly, causing missing argument errors or inconsistent
76+
method signatures. (:pull:`5684`)
77+
By `Jimmy Westling <https://github.com/illviljan>`_.
7578
- Numbers are properly formatted in a plot's title (:issue:`5788`, :pull:`5789`).
7679
By `Maxime Liquet <https://github.com/maximlt>`_.
7780

xarray/backends/plugins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def get_backend(engine):
158158
)
159159
backend = engines[engine]
160160
elif isinstance(engine, type) and issubclass(engine, BackendEntrypoint):
161-
backend = engine
161+
backend = engine()
162162
else:
163163
raise TypeError(
164164
(

xarray/tests/test_backends_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ def test_custom_engine() -> None:
2626

2727
class CustomBackend(xr.backends.BackendEntrypoint):
2828
def open_dataset(
29+
self,
2930
filename_or_obj,
3031
drop_variables=None,
3132
**kwargs,
32-
):
33+
) -> xr.Dataset:
3334
return expected.copy(deep=True)
3435

3536
actual = xr.open_dataset("fake_filename", engine=CustomBackend)

0 commit comments

Comments
 (0)