Skip to content

Commit 14a0329

Browse files
committed
setting fill value to none instead of manipulating files
1 parent 65b220b commit 14a0329

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

test/cli/test_prune.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import numpy as np
12
import os.path
23
import sys
34

@@ -24,23 +25,18 @@ class PruneDataTest(CliTest):
2425
def setUp(self) -> None:
2526
rimraf(self.TEST_CUBE)
2627
cube = new_cube(time_periods=3,
27-
variables=dict(precipitation=1.0,
28-
temperature=1.0)) \
28+
variables=dict(precipitation=np.nan,
29+
temperature=np.nan)) \
2930
.chunk(dict(time=1, lat=90, lon=90))
30-
31-
write_cube(cube, self.TEST_CUBE, "zarr", cube_asserted=True)
32-
33-
# we need to manually edit the fill values, otherwise, as of zarr 2.11,
34-
# empty chunks are not written
35-
import json
36-
with open(f'{self.TEST_CUBE}/.zmetadata') as metadata:
37-
metadata_dict = json.load(metadata)
38-
metadata_dict['metadata']['precipitation/.zarray']['fill_value'] \
39-
= 1.0
40-
metadata_dict['metadata']['temperature/.zarray']['fill_value'] \
41-
= 1.0
42-
with open(f'{self.TEST_CUBE}/.zmetadata', 'w') as metadata:
43-
json.dump(metadata_dict, metadata)
31+
encoding = {
32+
'precipitation': {
33+
'_FillValue': None
34+
},
35+
'temperature': {
36+
'_FillValue': None
37+
}
38+
}
39+
cube.to_zarr(self.TEST_CUBE, encoding=encoding)
4440

4541
def tearDown(self) -> None:
4642
rimraf(self.TEST_CUBE)

0 commit comments

Comments
 (0)