File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -81,6 +81,28 @@ def test_dataarray_validate_array_type():
81
81
schema .validate (da )
82
82
83
83
84
+ def test_dataarray_validate_chunks ():
85
+ pytest .importorskip ('dask' )
86
+
87
+ da = xr .DataArray (np .ones (4 ), dims = ['x' ]).chunk ({'x' : 2 })
88
+ schema = DataArraySchema (chunks = {'x' : 2 })
89
+ schema .validate (da )
90
+
91
+ schema = DataArraySchema (chunks = {'x' : (2 , 2 )})
92
+ schema .validate (da )
93
+
94
+ schema = DataArraySchema (chunks = {'x' : [2 , 2 ]})
95
+ schema .validate (da )
96
+
97
+ schema = DataArraySchema (chunks = {'x' : 3 })
98
+ with pytest .raises (SchemaError , match = r'.*(3).*' ):
99
+ schema .validate (da )
100
+
101
+ schema = DataArraySchema (chunks = {'x' : (2 , 1 )})
102
+ with pytest .raises (SchemaError , match = r'.*(2, 1).*' ):
103
+ schema .validate (da )
104
+
105
+
84
106
def test_dataset_empty_constructor ():
85
107
ds_schema = DatasetSchema ()
86
108
assert hasattr (ds_schema , 'validate' )
Original file line number Diff line number Diff line change @@ -103,7 +103,17 @@ def validate(self, da: xr.DataArray) -> xr.DataArray:
103
103
raise NotImplementedError ('coords schema not implemented yet' )
104
104
105
105
if self .chunks :
106
- raise NotImplementedError ('chunk schema not implemented yet' )
106
+ dim_chunks = dict (zip (da .dims , da .chunks ))
107
+ for key , ec in self .chunks .items ():
108
+ if isinstance (ec , int ):
109
+ for ac in dim_chunks [key ][:- 1 ]:
110
+ if ac != ec :
111
+ raise SchemaError (f'{ key } chunks did not match: { ac } != { ec } ' )
112
+
113
+ else : # assumes ec is an iterable
114
+ ac = dim_chunks [key ]
115
+ if tuple (ac ) != tuple (ec ):
116
+ raise SchemaError (f'{ key } chunks did not match: { ac } != { ec } ' )
107
117
108
118
if self .attrs :
109
119
raise NotImplementedError ('attrs schema not implemented yet' )
You can’t perform that action at this time.
0 commit comments