@@ -38,21 +38,23 @@ This is what a ``BackendEntrypoint`` subclass should look like:
38
38
39
39
.. code-block :: python
40
40
41
- from xarray.backends import BackendEntrypoint
41
+ from xarray.backends import BackendEntrypoint, CoderOptions
42
42
43
43
44
44
class MyBackendEntrypoint (BackendEntrypoint ):
45
+ coder_class = CoderOptions
46
+
45
47
def open_dataset (
46
48
self ,
47
49
filename_or_obj ,
48
50
* ,
49
- drop_variables = None ,
51
+ coder_options = None ,
50
52
# other backend specific keyword arguments
51
53
# `chunks` and `cache` DO NOT go here, they are handled by xarray
52
54
):
53
- return my_open_dataset(filename_or_obj, drop_variables = drop_variables )
55
+ return my_open_dataset(filename_or_obj, coder_options = coder_options )
54
56
55
- open_dataset_parameters = [" filename_or_obj" , " drop_variables " ]
57
+ open_dataset_parameters = [" filename_or_obj" , " coder_options " ]
56
58
57
59
def guess_can_open (self , filename_or_obj ):
58
60
try :
@@ -83,19 +85,15 @@ The following is an example of the high level processing steps:
83
85
self ,
84
86
filename_or_obj ,
85
87
* ,
86
- drop_variables = None ,
87
- decode_times = True ,
88
- decode_timedelta = True ,
89
- decode_coords = True ,
88
+ coder_options = None ,
90
89
my_backend_option = None ,
91
90
):
92
91
vars , attrs, coords = my_reader(
93
92
filename_or_obj,
94
- drop_variables = drop_variables,
95
93
my_backend_option = my_backend_option,
96
94
)
97
95
vars , attrs, coords = my_decode_variables(
98
- vars , attrs, decode_times, decode_timedelta, decode_coords
96
+ vars , attrs, ** coder_options.to_kwargs()
99
97
) # see also conventions.decode_cf_variables
100
98
101
99
ds = xr.Dataset(vars , attrs = attrs, coords = coords)
@@ -110,29 +108,26 @@ method shall be set by using :py:meth:`~xarray.Dataset.set_close`.
110
108
111
109
112
110
The input of ``open_dataset `` method are one argument
113
- (``filename_or_obj ``) and one keyword argument (``drop_variables ``):
111
+ (``filename_or_obj ``) and one keyword argument (``coder_options ``):
114
112
115
113
- ``filename_or_obj ``: can be any object but usually it is a string containing a path or an instance of
116
114
:py:class: `pathlib.Path `.
117
- - ``drop_variables ``: can be ``None `` or an iterable containing the variable
118
- names to be dropped when reading the data.
115
+ - ``coder_options ``: can be None or :py:class: `~xarray.backends.CoderOptions `
119
116
120
- If it makes sense for your backend, your ``open_dataset `` method
121
- should implement in its interface the following boolean keyword arguments, called
122
- **decoders **, which default to ``None ``:
117
+ If it makes sense for your backend, you can override the ``CoderOptions `` fields, which default to ``None ``:
123
118
124
119
- ``mask_and_scale ``
125
120
- ``decode_times ``
126
121
- ``decode_timedelta ``
127
122
- ``use_cftime ``
128
123
- ``concat_characters ``
129
124
- ``decode_coords ``
125
+ - ``drop_variables ``
130
126
131
- Note: all the supported decoders shall be declared explicitly
132
- in backend ``open_dataset `` signature and adding a ``**kwargs `` is not allowed.
127
+ Note: If ``coder_options `` is None the given kwargs are validated against the default.
133
128
134
129
These keyword arguments are explicitly defined in Xarray
135
- :py:func: `~xarray.open_dataset ` signature . Xarray will pass them to the
130
+ :py:func: `~xarray.CoderOptions ` or subclass . Xarray will pass them to the
136
131
backend only if the User explicitly sets a value different from ``None ``.
137
132
For more details on decoders see :ref: `RST decoders `.
138
133
@@ -141,7 +136,6 @@ arguments. All these keyword arguments can be passed to
141
136
:py:func: `~xarray.open_dataset ` grouped either via the ``backend_kwargs ``
142
137
parameter or explicitly using the syntax ``**kwargs ``.
143
138
144
-
145
139
If you don't want to support the lazy loading, then the
146
140
:py:class: `~xarray.Dataset ` shall contain values as a :py:class: `numpy.ndarray `
147
141
and your work is almost done.
@@ -260,14 +254,16 @@ time is stored in two attributes dataDate and dataTime as strings. Therefore,
260
254
it is not possible to reuse the Xarray time decoder, and implementing a new
261
255
one is mandatory.
262
256
263
- Decoders can be activated or deactivated using the boolean keywords of
264
- Xarray :py:meth: `~xarray.open_dataset ` signature: ``mask_and_scale ``,
257
+ Decoders can be activated or deactivated using ``coder_options `` kwarg
258
+ (:py:class: `~xarray.backends.CoderOptions `) or it's boolean keywords equivalent of
259
+ Xarray :py:meth: `~xarray.open_dataset ` (``mask_and_scale ``,
265
260
``decode_times ``, ``decode_timedelta ``, ``use_cftime ``,
266
- ``concat_characters ``, ``decode_coords ``.
261
+ ``concat_characters ``, ``decode_coords ``. `` drop_variables ``)
267
262
Such keywords are passed to the backend only if the User sets a value
268
263
different from ``None ``. Note that the backend does not necessarily have to
269
- implement all the decoders, but it shall declare in its ``open_dataset ``
270
- interface only the boolean keywords related to the supported decoders.
264
+ implement all the decoders, but it shall declare a ``coder_class `` in its
265
+ ``BackendEntrypoint `` interface with only the boolean keywords related to
266
+ the supported decoders.
271
267
272
268
.. _RST backend_registration :
273
269
0 commit comments