Skip to content
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

fix(core): Allow omitting codec configuration #199

Merged
merged 3 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silver-news-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zarrita/core": patch
---

fix: Allow omitting codec configuration
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"shape": [3, 3, 3], "data_type": "int16", "chunk_grid": {"configuration": {"chunk_shape": [3, 3, 3]}, "name": "regular"}, "chunk_key_encoding": {"configuration": {"separator": "/"}, "name": "default"}, "fill_value": 0, "codecs": [{"configuration": {"chunk_shape": [3, 3, 1], "codecs": [{"configuration": {"endian": "little"}, "name": "bytes"}, {"configuration": {"level": 5}, "name": "gzip"}], "index_codecs": [{"configuration": {"endian": "little"}, "name": "bytes"}, {"name": "crc32c"}]}, "name": "sharding_indexed"}], "attributes": {}, "dimension_names": null, "zarr_format": 3, "node_type": "array"}
{"shape": [3, 3, 3], "data_type": "int16", "chunk_grid": {"configuration": {"chunk_shape": [3, 3, 3]}, "name": "regular"}, "chunk_key_encoding": {"configuration": {"separator": "/"}, "name": "default"}, "fill_value": 0, "codecs": [{"configuration": {"chunk_shape": [3, 3, 1], "codecs": [{"name": "bytes"}, {"configuration": {"level": 5}, "name": "gzip"}], "index_codecs": [{"configuration": {"endian": "little"}, "name": "bytes"}, {"name": "crc32c"}]}, "name": "sharding_indexed"}], "attributes": {}, "dimension_names": null, "zarr_format": 3, "node_type": "array"}
4 changes: 2 additions & 2 deletions packages/core/src/codecs/bytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ export class BytesCodec<D extends Exclude<DataType, "v2:object">> {
#endian?: "little" | "big";

constructor(
configuration: { endian?: "little" | "big" },
configuration: { endian?: "little" | "big" } | undefined,
meta: { data_type: D; shape: number[]; codecs: CodecMetadata[] },
) {
this.#endian = configuration.endian;
this.#endian = configuration?.endian;
this.#TypedArray = get_ctr(meta.data_type);
this.#shape = meta.shape;
this.#strides = get_strides(meta.shape, get_array_order(meta.codecs));
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/codecs/json2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class JsonCodec {
#encoder_config: EncoderConfig;
#decoder_config: DecoderConfig;

constructor(public configuration: JsonCodecConfig) {
constructor(public configuration: JsonCodecConfig = {}) {
// Reference: https://github.com/zarr-developers/numcodecs/blob/0878717a3613d91a453fe3d3716aa9c67c023a8b/numcodecs/json.py#L36
const {
encoding = "utf-8",
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/codecs/transpose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,17 @@ function get_order(arr: Chunk<DataType>): "C" | "F" {
export class TransposeCodec {
kind = "array_to_array";

constructor(public configuration: { order: "C" | "F" }) {}
constructor(public configuration?: { order: "C" | "F" }) {}

static fromConfig(configuration: { order: "C" | "F" }) {
return new TransposeCodec(configuration);
}

encode<D extends DataType>(arr: Chunk<D>): Chunk<D> {
if (get_order(arr) === this.configuration.order) {
if (get_order(arr) === this.configuration?.order) {
return arr;
}
return convert_array_order(arr, this.configuration.order);
return convert_array_order(arr, this.configuration?.order ?? "C");
}

decode<D extends DataType>(arr: Chunk<D>): Chunk<D> {
Expand Down