Skip to content

Commit 7d9224e

Browse files
authored
Rename internal snake_case identifiers to camelCase (#387)
* Rename internal snake_case identifiers to camelCase The codebase inherited Python-style snake_case naming from zarr-python, which created confusion about what is a zarr metadata field versus an internal API. This change draws a clear boundary: zarr metadata types (`ArrayMetadata`, `GroupMetadata`, `CodecMetadata`, etc.) retain snake_case because they represent the on-disk JSON format, while all internal function names, variable names, and interface properties use idiomatic TypeScript camelCase. The most visible breaking change is `CreateArrayOptions`, whose properties move to camelCase: await zarr.create(store, { shape: [100, 100], chunkShape: [10, 10], // was chunk_shape dataType: "float32", // was data_type fillValue: 0, // was fill_value }) Internal exports consumed by `@zarrita/ndarray` are also renamed (`_zarrita_internal_getStrides`, `_zarrita_internal_sliceIndices`), and the `Setter` type properties become `setScalar`/`setFromChunk`. * Use camelCase for create options CreateArrayOptions properties are now camelCase (chunkShape, fillValue, chunkSeparator, dimensionNames). Array getters keep dtype and chunks to match zarr-python.
1 parent 5df59fe commit 7d9224e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+885
-892
lines changed

.changeset/camelcase-internals.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
"zarrita": minor
3+
---
4+
5+
**BREAKING**: `zarr.create` options now use camelCase (`chunkShape`, `fillValue`, `chunkSeparator`, `dimensionNames`).
6+
7+
```ts
8+
await zarr.create(store, {
9+
dtype: "float32", // was data_type
10+
shape: [100, 100],
11+
chunkShape: [10, 10], // was chunk_shape
12+
fillValue: 0, // was fill_value
13+
dimensionNames: ["y", "x"], // was dimension_names
14+
})
15+
```

docs/cookbook.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ import { FileSystemStore } from "@zarrita/storage";
6666

6767
const store = new FileSystemStore("tempstore");
6868
const arr = await zarr.create(store, {
69-
shape: [10, 10],
70-
chunks: [5, 5],
7169
dtype: "int32",
70+
shape: [10, 10],
71+
chunkShape: [5, 5],
7272
});
7373
arr; // zarr.Array<"int32", FileSystemStore>
7474
```

docs/packages/zarrita.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ import * as zarr from "zarrita";
145145
let root = zarr.root(new Map());
146146
let grp = await zarr.create(root);
147147
let arr = await zarr.create(root.resolve("foo"), {
148-
data_type: "int32",
148+
dtype: "int32",
149149
shape: [4, 4],
150-
chunk_shape: [2, 2],
150+
chunkShape: [2, 2],
151151
});
152152
console.log(root.store);
153153
// Map(2) {
@@ -236,9 +236,10 @@ system correctly infers that the value of chunk `data` is a `BigInt64Array`:
236236

237237
```javascript
238238
let arr = await zarr.create(root.resolve("foo"), {
239-
data_type: "int64",
239+
dtype: "int64",
240240
shape: [4, 4],
241-
chunk_shape: [2, 2],
241+
chunkShape: [2, 2],
242+
dimensionNames: ["x", "y"],
242243
});
243244
let chunk = await arr.getChunk([0, 0]);
244245
// ^ Chunk<"int64">

packages/@zarrita-ndarray/__tests__/setter.test.ts

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import ndarray, { type TypedArray } from "ndarray";
22
import { assign } from "ndarray-ops";
33
import { describe, expect, it } from "vitest";
44
import {
5-
_zarrita_internal_get_strides as get_strides,
5+
_zarrita_internal_getStrides as get_strides,
66
type Projection,
77
slice,
8-
_zarrita_internal_slice_indices as slice_indices,
8+
_zarrita_internal_sliceIndices as slice_indices,
99
} from "zarrita";
1010

1111
import { _internal_setter } from "../src/index.js";
@@ -23,15 +23,15 @@ function to_c<T extends TypedArray>({
2323
}
2424

2525
describe("setter", () => {
26-
it("setter.set_scalar - fill", async () => {
26+
it("setter.setScalar - fill", async () => {
2727
let a = _internal_setter.prepare(
2828
new Float32Array(2 * 3 * 4),
2929
[2, 3, 4],
3030
get_strides([2, 3, 4], "C"),
3131
);
3232

3333
let sel = [2, 3, 4].map((size) => slice_indices(slice(null), size));
34-
_internal_setter.set_scalar(a, sel, 1);
34+
_internal_setter.setScalar(a, sel, 1);
3535
// biome-ignore format: the array should not be formatted
3636
expect(a.data).toStrictEqual(new Float32Array([
3737
1, 1, 1, 1,
@@ -44,14 +44,14 @@ describe("setter", () => {
4444
]));
4545
});
4646

47-
it("setter.set_scalar - point", async () => {
47+
it("setter.setScalar - point", async () => {
4848
let a = _internal_setter.prepare(
4949
new Float32Array(2 * 3 * 4),
5050
[2, 3, 4],
5151
get_strides([2, 3, 4], "C"),
5252
);
5353

54-
_internal_setter.set_scalar(a, [0, 0, 0], 1);
54+
_internal_setter.setScalar(a, [0, 0, 0], 1);
5555
// biome-ignore format: the array should not be formatted
5656
expect(a.data).toStrictEqual(new Float32Array([
5757
1, 0, 0, 0,
@@ -63,7 +63,7 @@ describe("setter", () => {
6363
0, 0, 0, 0,
6464
]));
6565

66-
_internal_setter.set_scalar(a, [1, 1, 1], 2);
66+
_internal_setter.setScalar(a, [1, 1, 1], 2);
6767
// biome-ignore format: the array should not be formatted
6868
expect(a.data).toStrictEqual(new Float32Array([
6969
1, 0, 0, 0,
@@ -75,7 +75,7 @@ describe("setter", () => {
7575
0, 0, 0, 0,
7676
]));
7777

78-
_internal_setter.set_scalar(a, [1, 2, 3], 3);
78+
_internal_setter.setScalar(a, [1, 2, 3], 3);
7979
// biome-ignore format: the array should not be formatted
8080
expect(a.data).toStrictEqual(new Float32Array([
8181
1, 0, 0, 0,
@@ -87,7 +87,7 @@ describe("setter", () => {
8787
0, 0, 0, 3,
8888
]));
8989

90-
_internal_setter.set_scalar(a, [1, 2, 2], 4);
90+
_internal_setter.setScalar(a, [1, 2, 2], 4);
9191
// biome-ignore format: the array should not be formatted
9292
expect(a.data).toStrictEqual(new Float32Array([
9393
1, 0, 0, 0,
@@ -100,15 +100,15 @@ describe("setter", () => {
100100
]));
101101
});
102102

103-
it("setter.set_scalar - mixed", async () => {
103+
it("setter.setScalar - mixed", async () => {
104104
let a = _internal_setter.prepare(
105105
new Float32Array(2 * 3 * 4),
106106
[2, 3, 4],
107107
get_strides([2, 3, 4], "C"),
108108
);
109109

110110
let sel = [slice_indices(slice(null), 2), slice_indices(slice(2), 3), 0];
111-
_internal_setter.set_scalar(a, sel, 1);
111+
_internal_setter.setScalar(a, sel, 1);
112112
// biome-ignore format: the array should not be formatted
113113
expect(a.data).toStrictEqual(new Float32Array([
114114
1, 0, 0, 0,
@@ -121,7 +121,7 @@ describe("setter", () => {
121121
]));
122122

123123
sel = [0, slice_indices(slice(null), 3), slice_indices(slice(null), 4)];
124-
_internal_setter.set_scalar(a, sel, 2);
124+
_internal_setter.setScalar(a, sel, 2);
125125

126126
// biome-ignore format: the array should not be formatted
127127
expect(a.data).toStrictEqual(new Float32Array([
@@ -135,15 +135,15 @@ describe("setter", () => {
135135
]));
136136
});
137137

138-
it("setter.set_scalar - mixed F order", async () => {
138+
it("setter.setScalar - mixed F order", async () => {
139139
let f = _internal_setter.prepare<"float32">(
140140
new Float32Array(2 * 3 * 4),
141141
[2, 3, 4],
142142
get_strides([2, 3, 4], "F"),
143143
);
144144

145145
let sel = [slice_indices(slice(null), 2), slice_indices(slice(2), 3), 0];
146-
_internal_setter.set_scalar(f, sel, 1);
146+
_internal_setter.setScalar(f, sel, 1);
147147
// biome-ignore format: the array should not be formatted
148148
expect(f.data).toStrictEqual(new Float32Array([
149149
1, 1, 1, 1, 0, 0,
@@ -153,7 +153,7 @@ describe("setter", () => {
153153
]));
154154

155155
sel = [0, slice_indices(slice(null), 3), slice_indices(slice(null), 4)];
156-
_internal_setter.set_scalar(f, sel, 2);
156+
_internal_setter.setScalar(f, sel, 2);
157157

158158
// biome-ignore format: the array should not be formatted
159159
expect(f.data).toStrictEqual(new Float32Array([
@@ -175,7 +175,7 @@ describe("setter", () => {
175175
]));
176176
});
177177

178-
it("set_from_chunk - complete", async () => {
178+
it("setFromChunk - complete", async () => {
179179
let dest = _internal_setter.prepare(
180180
new Float32Array(2 * 3 * 4),
181181
[2, 3, 4],
@@ -194,7 +194,7 @@ describe("setter", () => {
194194
{ from: [0, 2, 1], to: [0, 2, 1] },
195195
];
196196

197-
_internal_setter.set_from_chunk(dest, src, mapping);
197+
_internal_setter.setFromChunk(dest, src, mapping);
198198
// biome-ignore format: the array should not be formatted
199199
expect(dest.data).toStrictEqual(new Float32Array([
200200
1, 1, 0, 0,
@@ -207,7 +207,7 @@ describe("setter", () => {
207207
]));
208208
});
209209

210-
it("set_from_chunk - from complete to strided", async () => {
210+
it("setFromChunk - from complete to strided", async () => {
211211
let dest = _internal_setter.prepare(
212212
new Float32Array(2 * 3 * 4),
213213
[2, 3, 4],
@@ -226,7 +226,7 @@ describe("setter", () => {
226226
{ from: [0, 2, 1], to: [0, 4, 2] },
227227
];
228228

229-
_internal_setter.set_from_chunk(dest, src, mapping);
229+
_internal_setter.setFromChunk(dest, src, mapping);
230230
// biome-ignore format: the array should not be formatted
231231
expect(dest.data).toStrictEqual(new Float32Array([
232232
2, 0, 2, 0,
@@ -239,7 +239,7 @@ describe("setter", () => {
239239
]));
240240
});
241241

242-
it("set_from_chunk - from strided to complete", async () => {
242+
it("setFromChunk - from strided to complete", async () => {
243243
let dest = _internal_setter.prepare(
244244
new Float32Array(2 * 2 * 2),
245245
[2, 2, 2],
@@ -267,11 +267,11 @@ describe("setter", () => {
267267
{ to: [0, 2, 1], from: [0, 4, 2] },
268268
];
269269

270-
_internal_setter.set_from_chunk(dest, src, mapping);
270+
_internal_setter.setFromChunk(dest, src, mapping);
271271
expect(dest.data).toStrictEqual(new Float32Array(2 * 2 * 2).fill(2));
272272
});
273273

274-
it("set_from_chunk - src squeezed", async () => {
274+
it("setFromChunk - src squeezed", async () => {
275275
let dest = _internal_setter.prepare(
276276
new Float32Array(2 * 3 * 4),
277277
[2, 3, 4],
@@ -290,7 +290,7 @@ describe("setter", () => {
290290
{ to: 1, from: null },
291291
];
292292

293-
_internal_setter.set_from_chunk(dest, src, mapping);
293+
_internal_setter.setFromChunk(dest, src, mapping);
294294
// biome-ignore format: the array should not be formatted
295295
expect(dest.data).toStrictEqual(new Float32Array([
296296
0, 2, 0, 0,
@@ -303,7 +303,7 @@ describe("setter", () => {
303303
]));
304304
});
305305

306-
it("set_from_chunk - dest squeezed", async () => {
306+
it("setFromChunk - dest squeezed", async () => {
307307
let dest = _internal_setter.prepare(
308308
new Float32Array(4),
309309
[4],
@@ -331,11 +331,11 @@ describe("setter", () => {
331331
{ from: 1, to: null },
332332
];
333333

334-
_internal_setter.set_from_chunk(dest, src, mapping);
334+
_internal_setter.setFromChunk(dest, src, mapping);
335335
expect(dest.data).toStrictEqual(new Float32Array([2, 0, 0, 2]));
336336
});
337337

338-
it("set_from_chunk - complete F order", async () => {
338+
it("setFromChunk - complete F order", async () => {
339339
let dest = _internal_setter.prepare<"float32">(
340340
new Float32Array(2 * 3 * 4),
341341
[2, 3, 4],
@@ -354,7 +354,7 @@ describe("setter", () => {
354354
{ from: [0, 2, 1], to: [0, 2, 1] },
355355
];
356356

357-
_internal_setter.set_from_chunk(dest, src, mapping);
357+
_internal_setter.setFromChunk(dest, src, mapping);
358358
// biome-ignore format: the array should not be formatted
359359
expect(to_c(dest).data).toStrictEqual(new Float32Array([
360360
1, 1, 0, 0,
@@ -367,7 +367,7 @@ describe("setter", () => {
367367
]));
368368
});
369369

370-
it("set_from_chunk - F order", async () => {
370+
it("setFromChunk - F order", async () => {
371371
let dest = _internal_setter.prepare<"float32">(
372372
new Float32Array(2 * 3 * 4),
373373
[2, 3, 4],
@@ -386,7 +386,7 @@ describe("setter", () => {
386386
{ to: 1, from: null },
387387
];
388388

389-
_internal_setter.set_from_chunk(dest, src, mapping);
389+
_internal_setter.setFromChunk(dest, src, mapping);
390390
// biome-ignore format: the array should not be formatted
391391
expect(to_c(dest).data).toStrictEqual(new Float32Array([
392392
0, 2, 0, 0,
@@ -399,7 +399,7 @@ describe("setter", () => {
399399
]));
400400
});
401401

402-
it("set_from_chunk - dest=F order, src=C order", async () => {
402+
it("setFromChunk - dest=F order, src=C order", async () => {
403403
let dest = _internal_setter.prepare<"float32">(
404404
new Float32Array(2 * 3 * 4),
405405
[2, 3, 4],
@@ -418,7 +418,7 @@ describe("setter", () => {
418418
{ to: 1, from: null },
419419
];
420420

421-
_internal_setter.set_from_chunk(dest, src, mapping);
421+
_internal_setter.setFromChunk(dest, src, mapping);
422422
// biome-ignore format: the array should not be formatted
423423
expect(to_c(dest).data).toStrictEqual(new Float32Array([
424424
0, 2, 0, 0,
@@ -431,7 +431,7 @@ describe("setter", () => {
431431
]));
432432
});
433433

434-
it("set_from_chunk - dest=C order, src=F order", async () => {
434+
it("setFromChunk - dest=C order, src=F order", async () => {
435435
let dest = _internal_setter.prepare<"float32">(
436436
new Float32Array(2 * 3 * 4),
437437
[2, 3, 4],
@@ -450,7 +450,7 @@ describe("setter", () => {
450450
{ to: 1, from: null },
451451
];
452452

453-
_internal_setter.set_from_chunk(dest, src, mapping);
453+
_internal_setter.setFromChunk(dest, src, mapping);
454454
// biome-ignore format: the array should not be formatted
455455
expect(dest.data).toStrictEqual(new Float32Array([
456456
0, 2, 0, 0,

packages/@zarrita-ndarray/__tests__/slice.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const DATA = {
1414
describe("builtin slice", async () => {
1515
let arr = await create(new Map(), {
1616
shape: [2, 3, 4],
17-
data_type: "int32",
18-
chunk_shape: [1, 2, 2],
17+
dtype: "int32",
18+
chunkShape: [1, 2, 2],
1919
});
2020
await set(arr, null, ndarray(DATA.data, DATA.shape, DATA.stride));
2121

packages/@zarrita-ndarray/src/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,32 @@ export const _internal_setter: {
1111
shape: number[],
1212
stride: number[],
1313
) => ndarray.NdArray<zarr.TypedArray<D>>;
14-
set_scalar: <D extends zarr.DataType>(
14+
setScalar: <D extends zarr.DataType>(
1515
target: ndarray.NdArray<zarr.TypedArray<D>>,
1616
selection: (zarr.Indices | number)[],
1717
value: zarr.Scalar<D>,
1818
) => void;
19-
set_from_chunk: <D extends zarr.DataType>(
19+
setFromChunk: <D extends zarr.DataType>(
2020
a: ndarray.NdArray<zarr.TypedArray<D>>,
2121
b: ndarray.NdArray<zarr.TypedArray<D>>,
2222
proj: zarr.Projection[],
2323
) => void;
2424
} = {
2525
prepare: ndarray,
26-
set_scalar<D extends zarr.DataType>(
26+
setScalar<D extends zarr.DataType>(
2727
dest: ndarray.NdArray<zarr.TypedArray<D>>,
2828
selection: (number | zarr.Indices)[],
2929
value: zarr.Scalar<D>,
3030
) {
3131
// @ts-expect-error - ndarray-ops types are incorrect
3232
ops.assigns(view(dest, selection), value);
3333
},
34-
set_from_chunk<D extends zarr.DataType>(
34+
setFromChunk<D extends zarr.DataType>(
3535
dest: ndarray.NdArray<zarr.TypedArray<D>>,
3636
src: ndarray.NdArray<zarr.TypedArray<D>>,
3737
mapping: zarr.Projection[],
3838
) {
39-
const s = unzip_selections(mapping);
39+
const s = unzipSelections(mapping);
4040
ops.assign(view(dest, s.to), view(src, s.from));
4141
},
4242
};
@@ -81,7 +81,7 @@ export async function set<D extends zarr.DataType>(
8181
);
8282
}
8383

84-
function unzip_selections(mapping: zarr.Projection[]): {
84+
function unzipSelections(mapping: zarr.Projection[]): {
8585
to: (number | zarr.Indices)[];
8686
from: (number | zarr.Indices)[];
8787
} {

0 commit comments

Comments
 (0)