Uh oh!
There was an error while loading. Please reload this page.
Feat/write empty chunks - #2429
Conversation
normanrz
left a comment
There was a problem hiding this comment.
I think this is a good approach. Should we add some backwards compatibility thing for the write_empty_chunks kwarg in zarr.open?
I think that In [41]: x=np.random.randn(10, 10, 10)
In [42]: x2, y=np.broadcast_arrays(x, 0)
In [43]: xisx2# No copy of the array is createdOut[43]: TrueIn [44]: y.base# Only a single value is allocated for the fill value array data.It'd be nice to avoid the equality check when writing, at least under some circumstances, but I haven't thought of an easy way to do that. |
d-v-b
commented
Oct 22, 2024
Are you thinking of something like a warning to guide people to use the configuration approach, if they pass in |
normanrz
commented
Oct 22, 2024
Yes, a warning and maybe even setting the config for them? |
d-v-b
commented
Oct 22, 2024
I think a warning is a good idea but I'm hesitant to have any runtime code that sets config variables beyond the initial setup. IMO we are better off treating it as immutable, and leaving it to users to set. I think we can afford to just do a warning here because user code won't break if |
normanrz
commented
Oct 22, 2024
That sounds reasonable |
I've forgotten the code path now, but if zarr creates the empty chunk using |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| else: | ||
| _chunks = normalize_chunks(chunk_shape, shape, dtype_parsed.itemsize) | ||
| config_parsed = ArrayConfig(order=order, write_empty_chunks=write_empty_chunks) |
normanrz
commented
Dec 13, 2024
I added an I added deprecation warnings for both the |
…n into feat/write-empty-chunks
d-v-b
commented
Dec 19, 2024
@normanrz do you think we should surface the |
normanrz
commented
Dec 19, 2024
I was thinking the same thing. We could expose it as |
normanrz
commented
Dec 19, 2024
I renamed |
d-v-b
commented
Dec 20, 2024
@normanrz do you think we should add |
d-v-b
commented
Dec 20, 2024
a catch-all |
| order: MemoryOrder | ||
| write_empty_chunks: bool | ||
| def __init__( |
There was a problem hiding this comment.
this design prevents us from having None as a valid value for a configuration parameter, because it will not be possible to distinguish "parameter was unset" from "parameter was set to None". A solution is to use a classmethod that takes a dictionary where some keys may not be present, which unambiguously expresses a missing parameter. I am working on this.
normanrz
commented
Dec 20, 2024
Yeah. That could work |
d-v-b
commented
Dec 20, 2024
nice, i'm hacking on this rn |
d-v-b
commented
Dec 20, 2024
After working on this a bit, I think we can't deprecate the by contrast, |
normanrz
commented
Dec 20, 2024
Ok. Are you working on this or do you want help? |
d-v-b
commented
Dec 20, 2024
i'm working on it! |
d-v-b
commented
Dec 20, 2024
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Norman Rzepka <code@normanrz.com>
Co-authored-by: Norman Rzepka <code@normanrz.com>
Requested changes have been addressed in the meantime.
jni
commented
Jan 1, 2025
Is there a quick way (documentation/docstrings) for users to know that the new default for @d-v-b I'm also not entirely sure why you went with option 2 from #2015 (re: mutable global state), though it's alleviated by passing config to the write functions + context managers. I actually quite like the current implementation despite having the same reservation, I'd just love to see a fully-worked-out rationale for the chosen option, maybe in an update to the top-level description of this PR. (Which could also show the other ways of setting config other than the context manager.) |
d-v-b
commented
Jan 1, 2025
we definitely need an easy way to document that the default value is As for the explanation of the merged PR, I'd rather not change the top-level description of the PR at this point but I can add my thoughts here: The default value of the Of course another solution would be to deprecate |
This PR adds a boolean
array.write_empty_chunksvalue to the global config, and uses this value to control whether chunks that are "empty", i.e. filled with values equivalent to the array's fill value, are written to storage.In
zarr-python2.x,write_empty_chunkswas a property of anArraythat users specified when creating theArrayobject. This had pros and cons which I'm happy to discuss if people are interested, but the tl;dr is that the cons of that approach are driving my decision in this PR to makewrite_empty_chunksa global runtime property accessible via the config API.Usage looks something like this (
donfigexperts please correct me if there's a better way):If people hate this, then we can definitely change this API. I'm very open to discussion here.
Also worth noting:
Our check for whether a chunk is equal to the fill value is pretty inefficient -- it's allocating a new array for every check invocation. This can definitely be made more efficient, in a stupid way by caching an all-fill-value chunk on the array instance and using that for the comparison, or a smarter way by doing the
(chunk, fill_value)comparison without allocating a new array. But I think this is an effort for a separate PR.closes#2409
TODO: