@@ -32,16 +32,19 @@ This is what a ``BackendEntrypoint`` subclass should look like:
32
32
33
33
.. code-block :: python
34
34
35
+ from xarray.backends import BackendEntrypoint
36
+
37
+
35
38
class MyBackendEntrypoint (BackendEntrypoint ):
36
39
def open_dataset (
37
40
self ,
38
41
filename_or_obj ,
39
42
* ,
40
43
drop_variables = None ,
41
44
# other backend specific keyword arguments
45
+ # `chunks` and `cache` DO NOT go here, they are handled by xarray
42
46
):
43
- ...
44
- return ds
47
+ return my_open_dataset(filename_or_obj, drop_variables = drop_variables)
45
48
46
49
open_dataset_parameters = [" filename_or_obj" , " drop_variables" ]
47
50
@@ -50,7 +53,7 @@ This is what a ``BackendEntrypoint`` subclass should look like:
50
53
_, ext = os.path.splitext(filename_or_obj)
51
54
except TypeError :
52
55
return False
53
- return ext in {... }
56
+ return ext in {" .my_format " , " .my_fmt " }
54
57
55
58
``BackendEntrypoint `` subclass methods and attributes are detailed in the following.
56
59
@@ -74,20 +77,19 @@ The following is an example of the high level processing steps:
74
77
decode_times = True ,
75
78
decode_timedelta = True ,
76
79
decode_coords = True ,
77
- my_backend_param = None ,
80
+ my_backend_option = None ,
78
81
):
79
82
vars , attrs, coords = my_reader(
80
83
filename_or_obj,
81
84
drop_variables = drop_variables,
82
- my_backend_param = my_backend_param ,
85
+ my_backend_option = my_backend_option ,
83
86
)
84
87
vars , attrs, coords = my_decode_variables(
85
88
vars , attrs, decode_times, decode_timedelta, decode_coords
86
89
) # see also conventions.decode_cf_variables
87
90
88
- ds = xr.Dataset(vars , attrs = attrs)
89
- ds = ds.set_coords(coords)
90
- ds.set_close(store.close)
91
+ ds = xr.Dataset(vars , attrs = attrs, coords = coords)
92
+ ds.set_close(my_close_method)
91
93
92
94
return ds
93
95
@@ -98,9 +100,9 @@ method shall be set by using :py:meth:`~xarray.Dataset.set_close`.
98
100
99
101
100
102
The input of ``open_dataset `` method are one argument
101
- (``filename ``) and one keyword argument (``drop_variables ``):
103
+ (``filename_or_obj ``) and one keyword argument (``drop_variables ``):
102
104
103
- - ``filename ``: can be a string containing a path or an instance of
105
+ - ``filename_or_obj ``: can be any object but usually it is a string containing a path or an instance of
104
106
:py:class: `pathlib.Path `.
105
107
- ``drop_variables ``: can be `None ` or an iterable containing the variable
106
108
names to be dropped when reading the data.
@@ -117,7 +119,7 @@ should implement in its interface the following boolean keyword arguments, calle
117
119
- ``decode_coords ``
118
120
119
121
Note: all the supported decoders shall be declared explicitly
120
- in backend ``open_dataset `` signature.
122
+ in backend ``open_dataset `` signature and adding a `` **kargs `` is not allowed .
121
123
122
124
These keyword arguments are explicitly defined in Xarray
123
125
:py:func: `~xarray.open_dataset ` signature. Xarray will pass them to the
@@ -241,7 +243,7 @@ How to register a backend
241
243
242
244
Define a new entrypoint in your ``setup.py `` (or ``setup.cfg ``) with:
243
245
244
- - group: ``xarray.backend ``
246
+ - group: ``xarray.backends ``
245
247
- name: the name to be passed to :py:meth: `~xarray.open_dataset ` as ``engine ``
246
248
- object reference: the reference of the class that you have implemented.
247
249
@@ -251,9 +253,7 @@ You can declare the entrypoint in ``setup.py`` using the following syntax:
251
253
252
254
setuptools.setup(
253
255
entry_points={
254
- "xarray.backends": [
255
- "engine_name=your_package.your_module:YourBackendEntryClass"
256
- ],
256
+ "xarray.backends": ["my_engine=my_package.my_module:MyBackendEntryClass"],
257
257
},
258
258
)
259
259
@@ -263,18 +263,18 @@ in ``setup.cfg``:
263
263
264
264
[options.entry_points]
265
265
xarray.backends =
266
- engine_name = your_package.your_module:YourBackendEntryClass
266
+ my_engine = my_package.my_module:MyBackendEntryClass
267
267
268
268
269
269
See https://packaging.python.org/specifications/entry-points/#data-model
270
270
for more information
271
271
272
- If you are using [ Poetry]( https://python-poetry.org/) for your build system, you can accomplish the same thing using "plugins". In this case you would need to add the following to your ``pyproject.toml `` file:
272
+ If you are using ` Poetry < https://python-poetry.org/ >`_ for your build system, you can accomplish the same thing using "plugins". In this case you would need to add the following to your ``pyproject.toml `` file:
273
273
274
274
.. code-block :: toml
275
275
276
276
[tool.poetry.plugins."xarray_backends"]
277
- "engine_name " = "your_package.your_module:YourBackendEntryClass "
277
+ "my_engine " = "my_package.my_module:MyBackendEntryClass "
278
278
279
279
See https://python-poetry.org/docs/pyproject/#plugins for more information on Poetry plugins.
280
280
@@ -328,6 +328,9 @@ This is an example ``BackendArray`` subclass implementation:
328
328
329
329
.. code-block :: python
330
330
331
+ from xarray.backends import BackendArray
332
+
333
+
331
334
class MyBackendArray (BackendArray ):
332
335
def __init__ (
333
336
self ,
0 commit comments