You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Zarr v3: TypeError on float fill_value "0.0" for uint8 arrays—compatibility with legacy datasets #3447
TypeError: Invalid type: 0.0. Expected an integer.
Steps to reproduce
# /// script# requires-python = ">=3.11"# dependencies = [# "requests",# "aiohttp",# "fsspec",# "zarr@git+https://github.com/zarr-developers/zarr-python.git@main",# ]# ///## This script automatically imports the development branch of zarr to check for issuesimportzarrurl="https://s3.embl.de/i2k-2020/platy-raw.ome.zarr"component="s0"# Try s0, but other resolutions likely affected# Attempt to open remote arrayz=zarr.open_array(store=url, path=component)
print(z)
zarr.print_debug_info()
Older zarr-python releases (e.g., v2.x) accepted this value. The latest (v3.x) fails, making many public datasets unreadable without editing their metadata.
Questions and Suggestions
Should zarr-python accept 0.0 as a compatible fill_value for integer arrays and transparently cast it?
Would it be possible to warn (not error) and interpret common cases (e.g., float-encoded zero for integer types)?
If strict typing is desired, could an opt-in backward compatibility flag be provided?
#3448 will fix this, until then here's a workaround:
# /// script# requires-python = ">=3.11"# dependencies = [# "requests",# "aiohttp",# "fsspec",# "zarr@git+https://github.com/zarr-developers/zarr-python.git@main",# ]# ///## This script automatically imports the development branch of zarr to check for issuesfromtypingimportAnyfromnumpyimportunsignedintegerfromnumpy._typing._nbit_baseimport_8Bitimportzarrfromzarr.core.commonimportZarrFormatfromzarr.dtypeimportUInt8fromzarr.dtypeimportdata_type_registryclassFixedUInt8(UInt8):
deffrom_json_scalar(self, data: Any, *, zarr_format: ZarrFormat) ->Any:
ifisinstance(data, float):
returnsuper().from_json_scalar(int(data), zarr_format=zarr_format)
returnsuper().from_json_scalar(data, zarr_format=zarr_format)
data_type_registry.register('uint8', FixedUInt8)
url="https://s3.embl.de/i2k-2020/platy-raw.ome.zarr"component="s0"# Try s0, but other resolutions likely affected# Attempt to open remote arrayz=zarr.open_array(store=url, path=component)
print(z)
zarr.print_debug_info()
The logic here is that you override the json deseralization logic to convert floats to ints, then register that data type under its zarr v3 name (e.g., "uint8"). Repeat as needed for the other data types.
would it be helpful to include this kind of example in our documentation? I think overriding data type JSON deserialization behavior is very much in scope for our data type registry design.
would it be helpful to include this kind of example in our documentation? I think overriding data type JSON deserialization behavior is very much in scope for our data type registry design.
Yes! and ideally the error messages related to this type of issue would point at those docs
Activity
d-v-b commentedon Sep 11, 2025
Yes, we should do this. IMO there's no need for a warning or error here.
d-v-b commentedon Sep 12, 2025
#3448 will fix this, until then here's a workaround:
The logic here is that you override the json deseralization logic to convert floats to ints, then register that data type under its zarr v3 name (e.g.,
"uint8"). Repeat as needed for the other data types.d-v-b commentedon Sep 12, 2025
would it be helpful to include this kind of example in our documentation? I think overriding data type JSON deserialization behavior is very much in scope for our data type registry design.
ianhi commentedon Sep 23, 2025
Yes! and ideally the error messages related to this type of issue would point at those docs
thewtex commentedon Sep 23, 2025
@d-v-b thank you for the fix!