Skip to content

Commit

Permalink
Merge pull request #329 from sadielbartholomew/daskified-flip-fix
Browse files Browse the repository at this point in the history
Fix bug in previously-daskified `Data.flip`
  • Loading branch information
sadielbartholomew authored Feb 28, 2022
2 parents 7b17e46 + 25076fb commit 08cab16
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
5 changes: 3 additions & 2 deletions cf/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -10884,7 +10884,7 @@ def flip(self, axes=None, inplace=False, i=False):
"""
d = _inplace_enabled_define_and_cleanup(self)

if axes is not None and not axes and axes != 0:
if axes is not None and not axes and axes != 0: # i.e. empty sequence
return d

if axes is None:
Expand All @@ -10896,7 +10896,8 @@ def flip(self, axes=None, inplace=False, i=False):
return d

index = [
slice(None, None, -1) if i in axes else slice(None) for i in iaxes
slice(None, None, -1) if i in iaxes else slice(None)
for i in range(d.ndim)
]

dx = d._get_dask()
Expand Down
7 changes: 1 addition & 6 deletions cf/test/test_Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1788,7 +1788,6 @@ def test_Data_datum(self):
self.assertIs(d.datum([0, -1]), cf.masked)
self.assertIs(d.datum(-1, -1), cf.masked)

@unittest.skipIf(TEST_DASKIFIED_ONLY, "TypeError: 'int' is not iterable")
def test_Data_flip(self):
if self.test_only and inspect.stack()[0][3] not in self.test_only:
return
Expand All @@ -1810,26 +1809,22 @@ def test_Data_flip(self):
self.assertTrue((d.array == array).all())

array = np.arange(3 * 4 * 5).reshape(3, 4, 5) + 1
d = cf.Data(array.copy(), "metre", chunk=False)
d.chunk(total=[0], omit_axes=[1, 2])
d = cf.Data(array.copy(), "metre", chunks=-1)

self.assertEqual(d._pmshape, (3,))
self.assertEqual(d[0].shape, (1, 4, 5))
self.assertEqual(d[-1].shape, (1, 4, 5))
self.assertEqual(d[0].maximum(), 4 * 5)
self.assertEqual(d[-1].maximum(), 3 * 4 * 5)

for i in (2, 1):
e = d.flip(i)
self.assertEqual(e._pmshape, (3,))
self.assertEqual(e[0].shape, (1, 4, 5))
self.assertEqual(e[-1].shape, (1, 4, 5))
self.assertEqual(e[0].maximum(), 4 * 5)
self.assertEqual(e[-1].maximum(), 3 * 4 * 5)

i = 0
e = d.flip(i)
self.assertEqual(e._pmshape, (3,))
self.assertEqual(e[0].shape, (1, 4, 5))
self.assertEqual(e[-1].shape, (1, 4, 5))
self.assertEqual(e[0].maximum(), 3 * 4 * 5)
Expand Down

0 comments on commit 08cab16

Please sign in to comment.