Skip to content

change default in ds.chunk and datarray.chunk variable.chunk #4633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 14 additions & 10 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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-",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The style checker is catching that name_prefix is not defined here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sorry, I deleted a line by mistake yesterday, when I have added the inline comment -_-'

Expand Down
15 changes: 10 additions & 5 deletions xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down