Skip to content

Commit bcdb7a9

Browse files
Oriana ChegwiddenOriana Chegwidden
authored andcommitted
adding a chunks schema check
1 parent e26acda commit bcdb7a9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

xarray_schema/core.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,14 @@ def validate(self, da: xr.DataArray) -> xr.DataArray:
103103
raise NotImplementedError('coords schema not implemented yet')
104104

105105
if self.chunks:
106-
raise NotImplementedError('chunk schema not implemented yet')
106+
# ensure that the chunks are what you want them to be
107+
for dim, expected in self.chunks.items():
108+
# for special case of chunksize=-1, make the expected equal to the full length of that dimension
109+
if expected == -1:
110+
expected = len(da[dim])
111+
actual = da.chunks[dim][0]
112+
if actual != expected:
113+
raise SchemaError(f'chunk mismatch for dimension {dim}: {actual} != {expected}')
107114

108115
if self.attrs:
109116
raise NotImplementedError('attrs schema not implemented yet')

0 commit comments

Comments
 (0)