From f22abed435af65e9e5a27a04bfc47bb31b3cbaef Mon Sep 17 00:00:00 2001 From: Alessandro Amici Date: Tue, 4 May 2021 08:09:17 +0200 Subject: [PATCH 1/6] Add scipy to the list of backends that support `lock` --- xarray/backends/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xarray/backends/api.py b/xarray/backends/api.py index 8c60c4030a1..29ce46c8c68 100644 --- a/xarray/backends/api.py +++ b/xarray/backends/api.py @@ -449,7 +449,7 @@ def open_dataset( relevant when using dask or another form of parallelism. By default, appropriate locks are chosen to safely read and write files with the currently active dask scheduler. Supported by "netcdf4", "h5netcdf", - "pynio", "pseudonetcdf", "cfgrib". + "scipy", "pynio", "pseudonetcdf", "cfgrib". See engine open function for kwargs accepted by each specific engine. @@ -633,7 +633,7 @@ def open_dataarray( relevant when using dask or another form of parallelism. By default, appropriate locks are chosen to safely read and write files with the currently active dask scheduler. Supported by "netcdf4", "h5netcdf", - "pynio", "pseudonetcdf", "cfgrib". + "scipy", "pynio", "pseudonetcdf", "cfgrib". See engine open function for kwargs accepted by each specific engine. From 4e0062fa902628b933eafbe19c1f41cb53b22e77 Mon Sep 17 00:00:00 2001 From: Alessandro Amici Date: Tue, 4 May 2021 08:20:13 +0200 Subject: [PATCH 2/6] Add `lock` deprecation to zarr and pydap --- xarray/backends/pydap_.py | 9 +++++++++ xarray/backends/zarr.py | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/xarray/backends/pydap_.py b/xarray/backends/pydap_.py index 148f32cf982..0efe68c8c88 100644 --- a/xarray/backends/pydap_.py +++ b/xarray/backends/pydap_.py @@ -122,7 +122,16 @@ def open_dataset( use_cftime=None, decode_timedelta=None, session=None, + lock=None, ): + # TODO remove after v0.19 + if kwargs.pop("lock", None): + warnings.warn( + "The kwarg 'lock' has been deprecated for this backend, and is now " + "ignored. In the future passing lock will raise an error.", + DeprecationWarning, + ) + store = PydapDataStore.open( filename_or_obj, session=session, diff --git a/xarray/backends/zarr.py b/xarray/backends/zarr.py index a4086eacece..417845b36ac 100644 --- a/xarray/backends/zarr.py +++ b/xarray/backends/zarr.py @@ -1,5 +1,6 @@ import os import pathlib +import warnings from distutils.version import LooseVersion import numpy as np @@ -721,7 +722,15 @@ def open_dataset( consolidate_on_close=False, chunk_store=None, storage_options=None, + lock=None, ): + # TODO remove after v0.19 + if kwargs.pop("lock", None): + warnings.warn( + "The kwarg 'lock' has been deprecated for this backend, and is now " + "ignored. In the future passing lock will raise an error.", + DeprecationWarning, + ) filename_or_obj = _normalize_path(filename_or_obj) store = ZarrStore.open_group( From 0a042089c6ee069885d9af3c8ca1c2508d020713 Mon Sep 17 00:00:00 2001 From: Alessandro Amici Date: Tue, 4 May 2021 08:28:53 +0200 Subject: [PATCH 3/6] Add what's new entry --- doc/whats-new.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 2b3e398634c..864d8eefa84 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -131,6 +131,11 @@ Deprecations :py:func:`xarray.open_mfdataset` when `combine='by_coords'` is specified. Fixes (:issue:`5230`), via (:pull:`5231`, :pull:`5255`). By `Tom Nicholas `_. +- The `lock` keyword argument to :py:func:`open_dataset` and :py:func:`open_dataarray` is now + a backend specific option. It will give a warning if passed to a backend that doesn't support it + instead of being siletly ignored. From the next version it will raise an error. + This is part of the refactor to support external backends (:issue:`5073`). + By `Tom Nicholas `_ and `Alessandro Amici `_. Bug fixes From 3bade3891dfe48130ad56587bff098215aa57f42 Mon Sep 17 00:00:00 2001 From: Alessandro Amici Date: Tue, 4 May 2021 08:34:32 +0200 Subject: [PATCH 4/6] Fix merge. --- xarray/backends/pydap_.py | 4 +++- xarray/backends/zarr.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/xarray/backends/pydap_.py b/xarray/backends/pydap_.py index 0efe68c8c88..2fb0e7f52e7 100644 --- a/xarray/backends/pydap_.py +++ b/xarray/backends/pydap_.py @@ -1,3 +1,5 @@ +import warnings + import numpy as np from ..core import indexing @@ -125,7 +127,7 @@ def open_dataset( lock=None, ): # TODO remove after v0.19 - if kwargs.pop("lock", None): + if lock is None: warnings.warn( "The kwarg 'lock' has been deprecated for this backend, and is now " "ignored. In the future passing lock will raise an error.", diff --git a/xarray/backends/zarr.py b/xarray/backends/zarr.py index 417845b36ac..4d4da49ddf6 100644 --- a/xarray/backends/zarr.py +++ b/xarray/backends/zarr.py @@ -725,7 +725,7 @@ def open_dataset( lock=None, ): # TODO remove after v0.19 - if kwargs.pop("lock", None): + if lock is None: warnings.warn( "The kwarg 'lock' has been deprecated for this backend, and is now " "ignored. In the future passing lock will raise an error.", From d9aabff4f8d5386bd44036bffdae89cc3b6e020a Mon Sep 17 00:00:00 2001 From: Alessandro Amici Date: Tue, 4 May 2021 08:57:37 +0200 Subject: [PATCH 5/6] Fix "option not passed" test --- xarray/backends/pydap_.py | 2 +- xarray/backends/zarr.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/xarray/backends/pydap_.py b/xarray/backends/pydap_.py index 2fb0e7f52e7..2372468d934 100644 --- a/xarray/backends/pydap_.py +++ b/xarray/backends/pydap_.py @@ -127,7 +127,7 @@ def open_dataset( lock=None, ): # TODO remove after v0.19 - if lock is None: + if lock is not None: warnings.warn( "The kwarg 'lock' has been deprecated for this backend, and is now " "ignored. In the future passing lock will raise an error.", diff --git a/xarray/backends/zarr.py b/xarray/backends/zarr.py index 4d4da49ddf6..fef7d739d25 100644 --- a/xarray/backends/zarr.py +++ b/xarray/backends/zarr.py @@ -725,7 +725,7 @@ def open_dataset( lock=None, ): # TODO remove after v0.19 - if lock is None: + if lock is not None: warnings.warn( "The kwarg 'lock' has been deprecated for this backend, and is now " "ignored. In the future passing lock will raise an error.", From 0dbda01636820ae2f29781ef913fa52e0752d05b Mon Sep 17 00:00:00 2001 From: Alessandro Amici Date: Tue, 4 May 2021 08:58:21 +0200 Subject: [PATCH 6/6] Update doc/whats-new.rst Co-authored-by: Maximilian Roos <5635139+max-sixty@users.noreply.github.com> --- doc/whats-new.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 864d8eefa84..7bdcd1c38c6 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -133,7 +133,7 @@ Deprecations By `Tom Nicholas `_. - The `lock` keyword argument to :py:func:`open_dataset` and :py:func:`open_dataarray` is now a backend specific option. It will give a warning if passed to a backend that doesn't support it - instead of being siletly ignored. From the next version it will raise an error. + instead of being silently ignored. From the next version it will raise an error. This is part of the refactor to support external backends (:issue:`5073`). By `Tom Nicholas `_ and `Alessandro Amici `_.