Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
jswhit committed Aug 23, 2023
1 parent a48338d commit 3d0cd65
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/tst_masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# create an n1dim by n2dim random ranarr.
FILE_NAME = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
FILE_NAME2 = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
FILE_NAME3 = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
ndim = 10
ranarr = 100.*uniform(size=(ndim))
ranarr2 = 100.*uniform(size=(ndim))
Expand All @@ -41,6 +42,7 @@ class PrimitiveTypesTestCase(unittest.TestCase):
def setUp(self):
self.file = FILE_NAME
self.file2 = FILE_NAME2
self.file3 = FILE_NAME3
file = netCDF4.Dataset(self.file,'w')
file.createDimension('n', ndim)
foo = file.createVariable('maskeddata', 'f8', ('n',))
Expand Down Expand Up @@ -93,6 +95,19 @@ def setUp(self):
data = dataset['v'][:]
dataset.close()

# issue #1271 (mask is ignored when assigning bool array to uint8 var)
ds = netCDF4.Dataset(self.file3, "w")
dim = ds.createDimension('time', 48)
var = ds.createVariable('blaat', np.uint8, ('time',),
zlib=True, complevel=4, shuffle=True, fletcher32=True,
fill_value=240)
mask = np.full((48,), False)
for x in range(30):
mask[x] = True
mama = ma.array(np.full((48,), True), mask=mask)
var[:] = mama
ds.close()

def tearDown(self):
# Remove the temporary files
os.remove(self.file)
Expand Down Expand Up @@ -148,6 +163,11 @@ def runTest(self):
assert var1[:].mask.all()
assert var2[:].mask.any() == False
dataset.close()
# issue #1271
ds = netCDF4.Dataset(self.file3,"r")
var = ds['blaat']
assert np.count_nonzero(var[:].mask) == 30
ds.close()

if __name__ == '__main__':
unittest.main()

0 comments on commit 3d0cd65

Please sign in to comment.