diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index b95f681bc79..c9baa143986 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -1010,12 +1010,11 @@ def chunks(self) -> Optional[Tuple[Tuple[int, ...], ...]]: def chunk( self, chunks: Union[ - None, Number, Tuple[Number, ...], Tuple[Tuple[Number, ...], ...], Mapping[Hashable, Union[None, Number, Tuple[Number, ...]]], - ] = None, + ] = {}, # {} even though it's technically unsafe, is being used intentionally here (#4667) name_prefix: str = "xarray-", token: str = None, lock: bool = False, diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 04974c58113..fb158e2fe4f 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -362,7 +362,7 @@ def _assert_empty(args: tuple, msg: str = "%s") -> None: def _maybe_chunk( name, var, - chunks=None, + chunks, token=None, lock=None, name_prefix="xarray-", @@ -1819,11 +1819,10 @@ def chunks(self) -> Mapping[Hashable, Tuple[int, ...]]: def chunk( self, chunks: Union[ - None, Number, str, Mapping[Hashable, Union[None, Number, str, Tuple[Number, ...]]], - ] = None, + ] = {}, # {} even though it's technically unsafe, is being used intentionally here (#4667) name_prefix: str = "xarray-", token: str = None, lock: bool = False, @@ -1855,17 +1854,22 @@ def chunk( ------- chunked : xarray.Dataset """ + if chunks is None: + warnings.warn( + "None value for 'chunks' is deprecated. " + "It will raise an error in the future. Use instead '{}'", + category=FutureWarning, + ) + chunks = {} if isinstance(chunks, (Number, str)): chunks = dict.fromkeys(self.dims, chunks) - if chunks is not None: - bad_dims = chunks.keys() - self.dims.keys() - if bad_dims: - raise ValueError( - "some chunks keys are not dimensions on this " - "object: %s" % bad_dims - ) + bad_dims = chunks.keys() - self.dims.keys() + if bad_dims: + raise ValueError( + "some chunks keys are not dimensions on this " "object: %s" % bad_dims + ) variables = { k: _maybe_chunk(k, v, chunks, token, lock, name_prefix) diff --git a/xarray/core/variable.py b/xarray/core/variable.py index a3876cb0077..a604a81cfa1 100644 --- a/xarray/core/variable.py +++ b/xarray/core/variable.py @@ -986,7 +986,7 @@ def chunks(self): _array_counter = itertools.count() - def chunk(self, chunks=None, name=None, lock=False): + def chunk(self, chunks={}, name=None, lock=False): """Coerce this array's data into a dask arrays with the given chunks. If this variable is a non-dask array, it will be converted to dask @@ -1016,12 +1016,17 @@ def chunk(self, chunks=None, name=None, lock=False): import dask import dask.array as da + if chunks is None: + warnings.warn( + "None value for 'chunks' is deprecated. " + "It will raise an error in the future. Use instead '{}'", + category=FutureWarning, + ) + chunks = {} + if utils.is_dict_like(chunks): chunks = {self.get_axis_num(dim): chunk for dim, chunk in chunks.items()} - if chunks is None: - chunks = self.chunks or self.shape - data = self._data if is_duck_dask_array(data): data = data.rechunk(chunks) @@ -2368,7 +2373,7 @@ def values(self, values): f"Please use DataArray.assign_coords, Dataset.assign_coords or Dataset.assign as appropriate." ) - def chunk(self, chunks=None, name=None, lock=False): + def chunk(self, chunks={}, name=None, lock=False): # Dummy - do not chunk. This method is invoked e.g. by Dataset.chunk() return self.copy(deep=False)