Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* The transpose method of a Cube now results in a transposed view of the original data rather than a transposed copy.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this really captures the lazy-loading aspect...?

5 changes: 1 addition & 4 deletions lib/iris/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -2806,10 +2806,7 @@ def transpose(self, new_order=None):
elif len(new_order) != self.data.ndim:
raise ValueError('Incorrect number of dimensions.')

# The data needs to be copied, otherwise this view of the transposed
# data will not be contiguous. Ensure not to assign via the cube.data
# setter property since we are reshaping the cube payload in-place.
self._my_data = np.transpose(self.data, new_order).copy()
self._my_data = self.lazy_data().transpose(new_order)

dim_mapping = {src: dest for dest, src in enumerate(new_order)}

Expand Down
9 changes: 9 additions & 0 deletions lib/iris/tests/unit/cube/test_Cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -1410,5 +1410,14 @@ def test_fail_cell_measure_dims(self):
cm_dims = self.cube.cell_measure_dims(a_cell_measure)


class Test_transpose(tests.IrisTest):
def test_lazy_data(self):
data = np.arange(12).reshape(3, 4)
cube = Cube(biggus.NumpyArrayAdapter(data))
cube.transpose()
self.assertTrue(cube.has_lazy_data())
self.assertArrayEqual(data.T, cube.data)


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