Skip to content

Commit 228cc88

Browse files
author
Lily Wang
committed
added deprecation warning
1 parent 962d45d commit 228cc88

File tree

2 files changed

+45
-18
lines changed

2 files changed

+45
-18
lines changed

xarray/backends/zarr.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import absolute_import, division, print_function
22

3+
import warnings
4+
35
from distutils.version import LooseVersion
46

57
import numpy as np
@@ -327,11 +329,11 @@ def sync(self):
327329
pass
328330

329331

330-
def open_zarr(store, group=None, synchronizer=None, chunks=None,
332+
def open_zarr(store, group=None, synchronizer=None, chunks='auto',
331333
decode_cf=True, mask_and_scale=True, decode_times=True,
332334
concat_characters=True, decode_coords=True,
333-
drop_variables=None, auto_chunk=True,
334-
overwrite_encoded_chunks=False):
335+
drop_variables=None, overwrite_encoded_chunks=False,
336+
**kwargs):
335337
"""Load and decode a dataset from a Zarr store.
336338
337339
.. note:: Experimental
@@ -354,13 +356,8 @@ def open_zarr(store, group=None, synchronizer=None, chunks=None,
354356
chunks : int or dict or {None, 'auto'}, optional
355357
Chunk sizes along each dimension, e.g., ``5`` or
356358
``{'x': 5, 'y': 5}``. If `chunks='auto'`, dask chunks are created
357-
based on the variable's zarr chunks. If `chunks=None` and
358-
`auto_chunk=False`, zarr array data will lazily convert to numpy
359-
arrays upon access.
360-
auto_chunk : bool, optional
361-
Whether to automatically create dask chunks corresponding to each
362-
variable's zarr chunks. If `chunks=None`, this overrides `chunks`.
363-
Equivalent to `chunks='auto'.` (Default: True)
359+
based on the variable's zarr chunks. If `chunks=None`, zarr array
360+
data will lazily convert to numpy arrays upon access.
364361
overwrite_encoded_chunks: bool, optional
365362
Whether to drop the zarr chunks encoded for each variable when a
366363
dataset is loaded with specified chunk sizes (default: False)
@@ -404,9 +401,19 @@ def open_zarr(store, group=None, synchronizer=None, chunks=None,
404401
----------
405402
http://zarr.readthedocs.io/
406403
"""
407-
408-
if auto_chunk and chunks is None:
409-
chunks = 'auto' # maintain backwards compatibility
404+
if 'auto_chunk' in kwargs:
405+
auto_chunk = kwargs.pop('auto_chunk')
406+
if auto_chunk == True:
407+
chunks = 'auto' # maintain backwards compatibility
408+
elif auto_chunk == False:
409+
chunks = None
410+
411+
warnings.warn("auto_chunk is deprecated. Use chunks='auto' instead.",
412+
FutureWarning, stacklevel=2)
413+
414+
if kwargs:
415+
raise TypeError("open_zarr() got unexpected keyword arguments " +
416+
",".join(kwargs.keys()))
410417

411418
if not isinstance(chunks, (int, dict)):
412419
if chunks != 'auto' and chunks is not None:

xarray/tests/test_backends.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,15 +1325,15 @@ def test_auto_chunk(self):
13251325
original = create_test_data().chunk()
13261326

13271327
with self.roundtrip(
1328-
original, open_kwargs={'auto_chunk': False}) as actual:
1328+
original, open_kwargs={'chunks': None}) as actual:
13291329
for k, v in actual.variables.items():
13301330
# only index variables should be in memory
13311331
assert v._in_memory == (k in actual.dims)
13321332
# there should be no chunks
13331333
assert v.chunks is None
13341334

13351335
with self.roundtrip(
1336-
original, open_kwargs={'auto_chunk': True}) as actual:
1336+
original, open_kwargs={'chunks': 'auto'}) as actual:
13371337
for k, v in actual.variables.items():
13381338
# only index variables should be in memory
13391339
assert v._in_memory == (k in actual.dims)
@@ -1346,7 +1346,7 @@ def test_manual_chunk(self):
13461346
# All of these should return non-chunked arrays
13471347
NO_CHUNKS = (None, 0, {})
13481348
for no_chunk in NO_CHUNKS:
1349-
open_kwargs = {'chunks': no_chunk, 'auto_chunk': False}
1349+
open_kwargs = {'chunks': no_chunk}
13501350
with self.roundtrip(original, open_kwargs=open_kwargs) as actual:
13511351
for k, v in actual.variables.items():
13521352
# only index variables should be in memory
@@ -1380,13 +1380,33 @@ def test_manual_chunk(self):
13801380

13811381
assert_identical(actual, auto)
13821382
assert_identical(actual.load(), auto.load())
1383+
1384+
def test_deprecate_auto_chunk(self):
1385+
original = create_test_data().chunk()
1386+
with pytest.warns(FutureWarning):
1387+
with self.roundtrip(
1388+
original, open_kwargs={'auto_chunk': True}) as actual:
1389+
for k, v in actual.variables.items():
1390+
# only index variables should be in memory
1391+
assert v._in_memory == (k in actual.dims)
1392+
# chunk size should be the same as original
1393+
assert v.chunks == original[k].chunks
1394+
1395+
with pytest.warns(FutureWarning):
1396+
with self.roundtrip(
1397+
original, open_kwargs={'auto_chunk': False}) as actual:
1398+
for k, v in actual.variables.items():
1399+
# only index variables should be in memory
1400+
assert v._in_memory == (k in actual.dims)
1401+
# there should be no chunks
1402+
assert v.chunks is None
1403+
13831404

13841405
def test_write_uneven_dask_chunks(self):
13851406
# regression for GH#2225
13861407
original = create_test_data().chunk({'dim1': 3, 'dim2': 4, 'dim3': 3})
1387-
13881408
with self.roundtrip(
1389-
original, open_kwargs={'auto_chunk': True}) as actual:
1409+
original, open_kwargs={'chunks': 'auto'}) as actual:
13901410
for k, v in actual.data_vars.items():
13911411
print(k)
13921412
assert v.chunks == actual[k].chunks

0 commit comments

Comments
 (0)