-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add chunks='auto' support for cftime datasets #10527
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
base: main
Are you sure you want to change the base?
Changes from 40 commits
eb1a967
852476d
c921c59
1aba531
9429c3d
3c9d27e
5153d2d
62e71e6
cfdc31b
2f16bc7
ce720fa
4fa58c1
e58d6d7
590e503
f953976
6706524
4e56acd
0d008cd
49c4e9c
4594099
5d00b0a
80421ef
d1f7ad3
1b7de62
4407185
d8f45b2
20226c1
11ac9f0
8485df5
2c27877
0983261
c4ec31f
adbf5b2
6c93bc4
74bc0ea
0b9bbd0
e58322f
dbc6ebd
5680663
b5933ed
5db9225
600c0fd
9fcc6eb
dc83692
1e1bbf3
9443815
db52c62
85ebafd
e2627c6
0bca828
a930a65
cbcb640
70208e0
3f0d3aa
e944eb4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,7 @@ | ||||||||||||||||||
from __future__ import annotations | ||||||||||||||||||
|
||||||||||||||||||
import importlib | ||||||||||||||||||
import sys | ||||||||||||||||||
import warnings | ||||||||||||||||||
from collections.abc import Hashable, Iterable, Iterator, Mapping | ||||||||||||||||||
from functools import lru_cache | ||||||||||||||||||
|
@@ -23,7 +24,9 @@ | |||||||||||||||||
DaskArray = NDArray # type: ignore[assignment, misc] | ||||||||||||||||||
DaskCollection: Any = NDArray # type: ignore[no-redef] | ||||||||||||||||||
|
||||||||||||||||||
from xarray.core.variable import Variable | ||||||||||||||||||
from xarray.namedarray._typing import _Dim, duckarray | ||||||||||||||||||
from xarray.namedarray.parallelcompat import T_ChunkedArray | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
K = TypeVar("K") | ||||||||||||||||||
|
@@ -195,6 +198,31 @@ def either_dict_or_kwargs( | |||||||||||||||||
return pos_kwargs | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
def fake_target_chunksize( | ||||||||||||||||||
data: Variable | T_ChunkedArray, | ||||||||||||||||||
target_chunksize: int, | ||||||||||||||||||
) -> tuple[int, np.dtype[Any]]: | ||||||||||||||||||
""" | ||||||||||||||||||
Naughty trick - let's get the ratio of our cftime_nbytes, and then compute | ||||||||||||||||||
|
Naughty trick - let's get the ratio of our cftime_nbytes, and then compute | |
The `normalize_chunks` algorithm takes a size `limit` in bytes, but will not work for object dtypes. | |
So we rescale the `limit` to an appropriate one based on `float64` dtype, and pass that to `normalize_chunks`. | |
Naughty trick - let's get the ratio of our cftime_nbytes, and then compute |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if data.dtype == object: | |
nbytes_approx: int = sys.getsizeof(first_n_items(data, 1)) # type: ignore[no-untyped-call] | |
else: | |
nbytes_approx = data.dtype.itemsize | |
if data.dtype != object: | |
return limit, var.dtype | |
nbytes_approx: int = sys.getsizeof(first_n_items(data, 1)) # type: ignore[no-untyped-call] |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -18,11 +18,13 @@ | |||||||||
get_chunked_array_type, | ||||||||||
guess_chunkmanager, | ||||||||||
) | ||||||||||
from xarray.namedarray.utils import fake_target_chunksize | ||||||||||
|
||||||||||
if TYPE_CHECKING: | ||||||||||
from xarray.core.dataarray import DataArray | ||||||||||
from xarray.core.dataset import Dataset | ||||||||||
from xarray.core.types import T_ChunkDim | ||||||||||
from xarray.core.variable import IndexVariable, Variable | ||||||||||
|
||||||||||
MissingCoreDimOptions = Literal["raise", "copy", "drop"] | ||||||||||
|
||||||||||
|
@@ -83,8 +85,15 @@ def _get_chunk(var: Variable, chunks, chunkmanager: ChunkManagerEntrypoint): | |||||||||
for dim, preferred_chunk_sizes in zip(dims, preferred_chunk_shape, strict=True) | ||||||||||
) | ||||||||||
|
||||||||||
limit = chunkmanager.get_auto_chunk_size() | ||||||||||
limit, var_dtype = fake_target_chunksize(var, limit) | ||||||||||
|
limit, var_dtype = fake_target_chunksize(var, limit) | |
# The `normalize_chunks` algorithm takes a size `limit` in bytes, but will not work for object dtypes. | |
# So we rescale the `limit` to an appropriate one based on `float64` dtype, and pass that to `normalize_chunks`. | |
limit, var_dtype = fake_target_chunksize(var, limit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this can be deleted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had a play and I don't think I can fully get rid of it, I've reused as much of the abstracted logic as possible though.