Skip to content

Commit 5a28c94

Browse files
committed
getitem tests
1 parent e7043f3 commit 5a28c94

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

cf/test/test_Data.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,12 @@ def test_Data__getitem__(self):
14951495
indices = (cf.Data([1, 3]), cf.Data([0, 1, 2, 3, 4]) > 1)
14961496
self.assertEqual(d[indices].shape, (2, 3))
14971497

1498+
# ... and with a masked array
1499+
d.where(d < 20, cf.masked, inplace=True)
1500+
e = d[cf.Data([0, 7]), 0]
1501+
f = cf.Data([-999, 35], mask=[True, False]).reshape(2, 1)
1502+
self.assertTrue(e.equals(f))
1503+
14981504
def test_Data__setitem__(self):
14991505
"""Test the assignment of data elements on Data."""
15001506
for hardmask in (False, True):

cf/test/test_Field.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,10 @@ def test_Field__getitem__(self):
652652
g = f[0].squeeze()
653653
g[5]
654654

655+
# Test list indices that have a `to_dask_array` method
656+
y = f.dimension_coordinate("Y")
657+
self.assertEqual(f[y > 3].shape, (6, 9))
658+
655659
# Indices result in a subspaced shape that has a size 0 axis
656660
with self.assertRaises(IndexError):
657661
f[..., [False] * f.shape[-1]]
@@ -697,6 +701,11 @@ def test_Field__setitem__(self):
697701
with self.assertRaises(Exception):
698702
f[..., 0:2] = g
699703

704+
# Test list indices that have a `to_dask_array` method
705+
y = f.dimension_coordinate("Y")
706+
f[y > 3] = -314
707+
self.assertEqual(f.where(cf.ne(-314), cf.masked).count(), 6 * 9)
708+
700709
def test_Field__add__(self):
701710
f = self.f.copy()
702711

0 commit comments

Comments
 (0)