Skip to content

Commit f455e00

Browse files
alexamicimax-sixty
andauthored
More correct deprecation warning for lock argument (#5256)
* Add scipy to the list of backends that support `lock` * Add `lock` deprecation to zarr and pydap * Add what's new entry * Fix merge. * Fix "option not passed" test * Update doc/whats-new.rst Co-authored-by: Maximilian Roos <5635139+max-sixty@users.noreply.github.com>
1 parent 4aef8f9 commit f455e00

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

doc/whats-new.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ Deprecations
133133
:py:func:`xarray.open_mfdataset` when `combine='by_coords'` is specified.
134134
Fixes (:issue:`5230`), via (:pull:`5231`, :pull:`5255`).
135135
By `Tom Nicholas <https://github.com/TomNicholas>`_.
136+
- The `lock` keyword argument to :py:func:`open_dataset` and :py:func:`open_dataarray` is now
137+
a backend specific option. It will give a warning if passed to a backend that doesn't support it
138+
instead of being silently ignored. From the next version it will raise an error.
139+
This is part of the refactor to support external backends (:issue:`5073`).
140+
By `Tom Nicholas <https://github.com/TomNicholas>`_ and `Alessandro Amici <https://github.com/alexamici>`_.
136141

137142

138143
Bug fixes

xarray/backends/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ def open_dataset(
449449
relevant when using dask or another form of parallelism. By default,
450450
appropriate locks are chosen to safely read and write files with the
451451
currently active dask scheduler. Supported by "netcdf4", "h5netcdf",
452-
"pynio", "pseudonetcdf", "cfgrib".
452+
"scipy", "pynio", "pseudonetcdf", "cfgrib".
453453
454454
See engine open function for kwargs accepted by each specific engine.
455455
@@ -633,7 +633,7 @@ def open_dataarray(
633633
relevant when using dask or another form of parallelism. By default,
634634
appropriate locks are chosen to safely read and write files with the
635635
currently active dask scheduler. Supported by "netcdf4", "h5netcdf",
636-
"pynio", "pseudonetcdf", "cfgrib".
636+
"scipy", "pynio", "pseudonetcdf", "cfgrib".
637637
638638
See engine open function for kwargs accepted by each specific engine.
639639

xarray/backends/pydap_.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import warnings
2+
13
import numpy as np
24

35
from ..core import indexing
@@ -122,7 +124,16 @@ def open_dataset(
122124
use_cftime=None,
123125
decode_timedelta=None,
124126
session=None,
127+
lock=None,
125128
):
129+
# TODO remove after v0.19
130+
if lock is not None:
131+
warnings.warn(
132+
"The kwarg 'lock' has been deprecated for this backend, and is now "
133+
"ignored. In the future passing lock will raise an error.",
134+
DeprecationWarning,
135+
)
136+
126137
store = PydapDataStore.open(
127138
filename_or_obj,
128139
session=session,

xarray/backends/zarr.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import pathlib
3+
import warnings
34
from distutils.version import LooseVersion
45

56
import numpy as np
@@ -721,7 +722,15 @@ def open_dataset(
721722
consolidate_on_close=False,
722723
chunk_store=None,
723724
storage_options=None,
725+
lock=None,
724726
):
727+
# TODO remove after v0.19
728+
if lock is not None:
729+
warnings.warn(
730+
"The kwarg 'lock' has been deprecated for this backend, and is now "
731+
"ignored. In the future passing lock will raise an error.",
732+
DeprecationWarning,
733+
)
725734

726735
filename_or_obj = _normalize_path(filename_or_obj)
727736
store = ZarrStore.open_group(

0 commit comments

Comments
 (0)