Skip to content

Commit 2890eab

Browse files
author
brokkoli71
committed
test and fix v3 Group Attributes
1 parent db96a07 commit 2890eab

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

src/main/java/dev/zarr/zarrjava/v3/Group.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static Group create(
5555
@Nonnull StoreHandle storeHandle,
5656
@Nonnull Attributes attributes
5757
) throws IOException, ZarrException {
58-
return new Group(storeHandle, new GroupMetadata(attributes));
58+
return create(storeHandle, new GroupMetadata(attributes));
5959
}
6060

6161
public static Group create(@Nonnull StoreHandle storeHandle) throws IOException, ZarrException {

src/main/java/dev/zarr/zarrjava/v3/GroupMetadata.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package dev.zarr.zarrjava.v3;
22

33
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
45
import com.fasterxml.jackson.annotation.JsonProperty;
56
import dev.zarr.zarrjava.ZarrException;
67
import dev.zarr.zarrjava.core.Attributes;
78

89
import javax.annotation.Nonnull;
910
import javax.annotation.Nullable;
1011

12+
@JsonIgnoreProperties(ignoreUnknown = true)
1113
public final class GroupMetadata extends dev.zarr.zarrjava.core.GroupMetadata {
1214

1315
static final String NODE_TYPE = "group";

src/test/java/dev/zarr/zarrjava/ZarrPythonTests.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ public void testGroupReadWriteV2() throws Exception {
414414

415415
array.write(testdata(dataType));
416416

417-
run_python_script("zarr_python_group_v2.py", storeHandle.toPath().toString(), storeHandle2.toPath().toString());
417+
run_python_script("zarr_python_group_v2.py", storeHandle.toPath().toString(), storeHandle2.toPath().toString(), "" + 2);
418418

419419
Group group2 = Group.open(storeHandle2);
420420
Assertions.assertEquals("value", group2.metadata().attributes().get("attr"));
@@ -426,4 +426,31 @@ public void testGroupReadWriteV2() throws Exception {
426426
Assertions.assertArrayEquals(new int[]{16, 16, 16}, result.getShape());
427427
assertIsTestdata(result, dataType);
428428
}
429+
430+
@Test
431+
public void testGroupReadWriteV3() throws Exception {
432+
StoreHandle storeHandle = new FilesystemStore(TESTOUTPUT).resolve("group_write");
433+
StoreHandle storeHandle2 = new FilesystemStore(TESTOUTPUT).resolve("group_read");
434+
dev.zarr.zarrjava.v3.Group group = dev.zarr.zarrjava.v3.Group.create(storeHandle, new Attributes(b -> b.set("attr", "value")));
435+
dev.zarr.zarrjava.v3.DataType dataType = DataType.INT32;
436+
dev.zarr.zarrjava.v3.Array array = group.createGroup("group").createArray("array", arrayMetadataBuilder -> arrayMetadataBuilder
437+
.withShape(16, 16, 16)
438+
.withDataType(dataType)
439+
.withChunkShape(2, 4, 8)
440+
);
441+
442+
array.write(testdata(dataType));
443+
444+
run_python_script("zarr_python_group_v2.py", storeHandle.toPath().toString(), storeHandle2.toPath().toString(), "" + 3);
445+
446+
dev.zarr.zarrjava.v3.Group group2 = dev.zarr.zarrjava.v3.Group.open(storeHandle2);
447+
Assertions.assertEquals("value", group2.metadata().attributes().get("attr"));
448+
dev.zarr.zarrjava.v3.Group subgroup = (dev.zarr.zarrjava.v3.Group) group2.get("group2");
449+
Assertions.assertNotNull(subgroup);
450+
dev.zarr.zarrjava.v3.Array array2 = (dev.zarr.zarrjava.v3.Array) subgroup.get("array2");
451+
Assertions.assertNotNull(array2);
452+
ucar.ma2.Array result = array2.read();
453+
Assertions.assertArrayEquals(new int[]{16, 16, 16}, result.getShape());
454+
assertIsTestdata(result, dataType);
455+
}
429456
}

src/test/python-scripts/zarr_python_group_v2.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@
77
from zarr.storage import LocalStore
88

99
store_path_read = Path(sys.argv[1])
10+
store_path_write = Path(sys.argv[2])
11+
zarr_format = int(sys.argv[3])
12+
assert zarr_format in (2,3), f"unexpected zarr format: {zarr_format}"
1013

1114
expected_data = np.arange(16 * 16 * 16, dtype='int32').reshape(16, 16, 16)
1215

13-
g = zarr.open_group(store=LocalStore(store_path_read), zarr_format=2)
16+
g = zarr.open_group(store=LocalStore(store_path_read), zarr_format=zarr_format)
1417
assert g.attrs['attr'] == 'value'
1518
a = g['group']['array']
1619
read_data = a[:, :]
1720
assert np.array_equal(read_data, expected_data), f"got:\n {read_data} \nbut expected:\n {expected_data}"
1821

19-
store_path_write = Path(sys.argv[2])
20-
g2 = zarr.create_group(store=LocalStore(store_path_write), zarr_format=2)
22+
g2 = zarr.create_group(store=LocalStore(store_path_write), zarr_format=zarr_format)
2123
g2.attrs['attr'] = 'value'
2224
a2 = g2.create_group('group2').create_array(
2325
name='array2',

0 commit comments

Comments
 (0)