Skip to content

Commit

Permalink
setting fill value to none instead of manipulating files
Browse files Browse the repository at this point in the history
  • Loading branch information
TonioF committed Feb 10, 2022
1 parent 65b220b commit 14a0329
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions test/cli/test_prune.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import numpy as np
import os.path
import sys

Expand All @@ -24,23 +25,18 @@ class PruneDataTest(CliTest):
def setUp(self) -> None:
rimraf(self.TEST_CUBE)
cube = new_cube(time_periods=3,
variables=dict(precipitation=1.0,
temperature=1.0)) \
variables=dict(precipitation=np.nan,
temperature=np.nan)) \
.chunk(dict(time=1, lat=90, lon=90))

write_cube(cube, self.TEST_CUBE, "zarr", cube_asserted=True)

# we need to manually edit the fill values, otherwise, as of zarr 2.11,
# empty chunks are not written
import json
with open(f'{self.TEST_CUBE}/.zmetadata') as metadata:
metadata_dict = json.load(metadata)
metadata_dict['metadata']['precipitation/.zarray']['fill_value'] \
= 1.0
metadata_dict['metadata']['temperature/.zarray']['fill_value'] \
= 1.0
with open(f'{self.TEST_CUBE}/.zmetadata', 'w') as metadata:
json.dump(metadata_dict, metadata)
encoding = {
'precipitation': {
'_FillValue': None
},
'temperature': {
'_FillValue': None
}
}
cube.to_zarr(self.TEST_CUBE, encoding=encoding)

def tearDown(self) -> None:
rimraf(self.TEST_CUBE)
Expand Down

0 comments on commit 14a0329

Please sign in to comment.