diff --git a/changelog/983.bugfix.rst b/changelog/983.bugfix.rst new file mode 100644 index 000000000..f647bd145 --- /dev/null +++ b/changelog/983.bugfix.rst @@ -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. diff --git a/ndcube/ndcollection.py b/ndcube/ndcollection.py index 7f84e7d31..b78e6745c 100644 --- a/ndcube/ndcollection.py +++ b/ndcube/ndcollection.py @@ -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): diff --git a/ndcube/tests/test_ndcollection.py b/ndcube/tests/test_ndcollection.py index 158112cd9..55251bf0e 100644 --- a/ndcube/tests/test_ndcollection.py +++ b/ndcube/tests/test_ndcollection.py @@ -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