Skip to content
Open
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
1 change: 1 addition & 0 deletions changelog/983.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
~ndcube.NDCollection.aligned_axis_physical_types now returns the physical types in the order of the collection's first member, instead of an order that changed from run to run.
6 changes: 4 additions & 2 deletions ndcube/ndcollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ def aligned_axis_physical_types(self):
collection_types = [np.array(cube.array_axis_physical_types,
dtype=object)[np.array(self.aligned_axes[name])]
for name, cube in self.items()]
# Return physical types common to all members of collection for each axis.
return [tuple(set.intersection(*[set(cube_types[i]) for cube_types in collection_types]))
# Return physical types common to all members of collection for each axis,
# in the order of the first member so the result does not depend on set ordering.
return [tuple(physical_type for physical_type in collection_types[0][i]
if all(physical_type in cube_types[i] for cube_types in collection_types[1:]))
for i in range(self.n_aligned_axes)]

def __getitem__(self, item):
Expand Down
6 changes: 2 additions & 4 deletions ndcube/tests/test_ndcollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,5 @@ def test_aligned_dimensions(collection, expected_aligned_dimensions):
('custom:pos.helioprojective.lat', 'custom:pos.helioprojective.lon'),
('em.wl',)])])
def test_aligned_axis_physical_types(collection, expected):
output = collection.aligned_axis_physical_types
assert len(output) == len(expected)
for output_axis_types, expect_axis_types in zip(output, expected):
assert set(output_axis_types) == set(expect_axis_types)
# The types keep the order of the first member, so they do not change from run to run.
assert collection.aligned_axis_physical_types == expected
Loading