Surprising behavior of DataArray.chunk when using automatic chunksize determination #8037
Replies: 2 comments
-
Thank you for the detailed report, @grahamfindlay!
coordinates in Xarray are typically not chunked. this is why you might observe that the
the dtype of the data and coordinates can influence the chunk size. If the data and Could you provide a minimal working example that reproduces this issue? This would be extremely useful for diagnosing the problem |
Beta Was this translation helpful? Give feedback.
-
Hi Anderson, thanks for your reply. Here is a minimal working example:
Which produces the following output:
I understand that this is all the intended behavior, and nothing is broken. It is just extremely surprising behavior. In increasing order of surprise, I expected
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
What is your issue?
I have a DataArray
da
with dims(x, y)
, and additional coordinates such asx_coord
on dimx
. If I try to chunk this array usingda.chunk(chunks={'x': 'auto'})
, I end up with a situation where:x
with chunksizea
.x
coordinate itself is not chunked.x_coord
coordinate on dimx
is chunked, with chunksizeb != a
.As far as I can tell, what is going on is that
da.chunk(chunks={'x': 'auto'})
is autodetermining the chunksize differently for each "thing" (data, variable, coordinate, etc) on thex
dimension. What I expected was for it to determine one chunksize based on the data in the array, then use that chunksize (or no chunking) to each coordinate as well. Maybe there could be an option to yield unified chunks by default.I discovered this because after chunking,
da.chunksizes
raises a ValueError because of the mismatch between the data andx_coord
, and the proposed solution -- callingda.unify_chunks()
-- then results in irregular chunksizes on both the data andx_coord
. To get the behavior that I expected I have to callda.chunk(da.encoding['preferred_chunks'])
, which also, incidentally, seems like what I would have expected fromda.unify_chunks()
.Beta Was this translation helpful? Give feedback.
All reactions