Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in previously-daskified Data.flip #329

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cf/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -10945,7 +10945,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 @@ -10957,7 +10957,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 @@ -1794,7 +1794,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 @@ -1816,26 +1815,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