From c459427595feea9689cc09b61da87ac4afbb4cc7 Mon Sep 17 00:00:00 2001 From: Nabil Freij Date: Sun, 27 Sep 2026 21:36:38 -0700 Subject: [PATCH 1/3] Keep the order of NDCollection.aligned_axis_physical_types stable Each tuple was built from a set of strings, so its order changed with Python's hash seed and printing a collection gave different output from run to run. The common types now keep the order of the first member. --- ndcube/ndcollection.py | 6 ++++-- ndcube/tests/test_ndcollection.py | 6 ++---- 2 files changed, 6 insertions(+), 6 deletions(-) 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 From 5b94b92ada04e4106bb3483beb81f761baa8cf0e Mon Sep 17 00:00:00 2001 From: Nabil Freij Date: Sun, 27 Sep 2026 21:37:11 -0700 Subject: [PATCH 2/3] Add changelog entry for #983 --- changelog/983.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/983.bugfix.rst diff --git a/changelog/983.bugfix.rst b/changelog/983.bugfix.rst new file mode 100644 index 000000000..e5f025127 --- /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 first member of the collection, instead of an order that changed from run to run. From 4608527b0f03f1d52c4ac19e56650c33b8cef989 Mon Sep 17 00:00:00 2001 From: Nabil Freij Date: Thu, 1 Oct 2026 12:11:24 -0700 Subject: [PATCH 3/3] Update 983.bugfix.rst --- changelog/983.bugfix.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/983.bugfix.rst b/changelog/983.bugfix.rst index e5f025127..f647bd145 100644 --- a/changelog/983.bugfix.rst +++ b/changelog/983.bugfix.rst @@ -1 +1 @@ -`~ndcube.NDCollection.aligned_axis_physical_types` now returns the physical types in the order of the first member of the collection, instead of an order that changed from run to run. + ~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.