Skip to content

Commit 60cac04

Browse files
committed
start fixing config
1 parent 44e78f5 commit 60cac04

File tree

3 files changed

+23
-39
lines changed

3 files changed

+23
-39
lines changed

src/zarr/core/array.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
from zarr.core.dtype import (
7171
DTypeWrapper,
7272
FixedLengthAsciiString,
73-
FixedLengthUnicodeString,
7473
VariableLengthString,
7574
parse_data_type,
7675
)
@@ -4248,19 +4247,15 @@ def _get_default_chunk_encoding_v2(
42484247
"""
42494248
Get the default chunk encoding for Zarr format 2 arrays, given a dtype
42504249
"""
4251-
from numcodecs import VLenBytes as numcodecs_VLenBytes
4252-
from numcodecs import VLenUTF8 as numcodecs_VLenUTF8
4253-
from numcodecs import Zstd as numcodecs_zstd
4254-
4255-
if isinstance(dtype, VariableLengthString | FixedLengthUnicodeString):
4256-
filters = (numcodecs_VLenUTF8(),)
4257-
elif isinstance(dtype, FixedLengthAsciiString):
4258-
filters = (numcodecs_VLenBytes(),)
4250+
if dtype._zarr_v3_name in zarr_config.get("array.v2_default_filters"):
4251+
filters = zarr_config.get(f"array.v2_default_filters.{dtype._zarr_v3_name}")
42594252
else:
4260-
filters = None
4261-
4262-
compressor = numcodecs_zstd(level=0, checksum=False)
4253+
filters = zarr_config.get("array.v2_default_filters.default")
42634254

4255+
if dtype._zarr_v3_name in zarr_config.get("array.v2_default_compressor"):
4256+
compressor = zarr_config.get(f"array.v2_default_compressor.{dtype._zarr_v3_name}")
4257+
else:
4258+
compressor = zarr_config.get("array.v2_default_compressor.default")
42644259
return filters, compressor
42654260

42664261

src/zarr/core/config.py

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
if TYPE_CHECKING:
3737
from donfig.config_obj import ConfigSet
3838

39+
from collections import defaultdict
40+
3941

4042
class BadConfigError(ValueError):
4143
_msg = "bad Config: %r"
@@ -77,37 +79,24 @@ def enable_gpu(self) -> ConfigSet:
7779
"array": {
7880
"order": "C",
7981
"write_empty_chunks": False,
80-
"v2_default_compressor": {
81-
"numeric": {"id": "zstd", "level": 0, "checksum": False},
82-
"string": {"id": "zstd", "level": 0, "checksum": False},
83-
"bytes": {"id": "zstd", "level": 0, "checksum": False},
84-
},
82+
"v2_default_compressor": {"default": {"id": "zstd", "level": 0, "checksum": False}},
8583
"v2_default_filters": {
86-
"numeric": None,
87-
"string": [{"id": "vlen-utf8"}],
88-
"bytes": [{"id": "vlen-bytes"}],
89-
"raw": None,
84+
"default": None,
85+
"numpy.variable_length_unicode_string": [{"id": "vlen-utf8"}],
86+
"numpy.fixed_length_unicode_string": [{"id": "vlen-utf8"}],
87+
"r*": [{"id": "vlen-bytes"}],
9088
},
91-
"v3_default_filters": {"boolean": [], "numeric": [], "string": [], "bytes": []},
89+
"v3_default_filters": defaultdict(list),
9290
"v3_default_serializer": {
93-
"boolean": {"name": "bytes", "configuration": {"endian": "little"}},
94-
"numeric": {"name": "bytes", "configuration": {"endian": "little"}},
95-
"string": {"name": "vlen-utf8"},
96-
"bytes": {"name": "vlen-bytes"},
91+
"default": {"name": "bytes", "configuration": {"endian": "little"}},
92+
"numpy.variable_length_unicode_string": [{"name": "vlen-utf8"}],
93+
"numpy.fixed_length_unicode_string": [{"name": "vlen-utf8"}],
94+
"r*": {"name": "vlen-bytes"},
9795
},
9896
"v3_default_compressors": {
99-
"boolean": [
100-
{"name": "zstd", "configuration": {"level": 0, "checksum": False}},
101-
],
102-
"numeric": [
103-
{"name": "zstd", "configuration": {"level": 0, "checksum": False}},
104-
],
105-
"string": [
106-
{"name": "zstd", "configuration": {"level": 0, "checksum": False}},
107-
],
108-
"bytes": [
97+
"default": [
10998
{"name": "zstd", "configuration": {"level": 0, "checksum": False}},
110-
],
99+
]
111100
},
112101
},
113102
"async": {"concurrency": 10, "timeout": None},

src/zarr/core/dtype/_numpy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ def from_json_value(self, data: JSON, *, zarr_format: ZarrFormat) -> np.str_:
627627
@dataclass(frozen=True, kw_only=True)
628628
class VariableLengthString(DTypeWrapper[np.dtypes.StringDType, str]):
629629
dtype_cls = np.dtypes.StringDType
630-
_zarr_v3_name = "numpy.vlen_string"
630+
_zarr_v3_name = "numpy.variable_length_string"
631631

632632
@classmethod
633633
def _from_dtype_unsafe(cls, dtype: np.dtypes.StringDType) -> Self:
@@ -658,7 +658,7 @@ def from_json_value(self, data: JSON, *, zarr_format: ZarrFormat) -> str:
658658
@dataclass(frozen=True, kw_only=True)
659659
class VariableLengthString(DTypeWrapper[np.dtypes.ObjectDType, str]):
660660
dtype_cls = np.dtypes.ObjectDType
661-
_zarr_v3_name = "numpy.vlen_string"
661+
_zarr_v3_name = "numpy.variable_length_string"
662662

663663
@classmethod
664664
def _from_dtype_unsafe(cls, dtype: np.dtypes.ObjectDType) -> Self:

0 commit comments

Comments
 (0)