diff --git a/changelog/778.removal.rst b/changelog/778.removal.rst new file mode 100644 index 000000000..0b21f77f3 --- /dev/null +++ b/changelog/778.removal.rst @@ -0,0 +1 @@ +The ability to create an `.NDCollection` object with numerical keys is deprecated as it leads to ambiguous behavior when slicing the collection. diff --git a/ndcube/ndcollection.py b/ndcube/ndcollection.py index 0b37e4e91..30790b5d1 100644 --- a/ndcube/ndcollection.py +++ b/ndcube/ndcollection.py @@ -1,9 +1,11 @@ +import numbers import textwrap import collections.abc import numpy as np import ndcube.utils.collection as collection_utils +from ndcube.utils.exceptions import warn_deprecated __all__ = ["NDCollection"] @@ -14,7 +16,7 @@ class NDCollection(dict): Parameters ---------- - data: sequence of `tuple` of (`str`, `~ndcube.NDCube` or `~ndcube.NDCubeSequence`) + key_data_pairs: sequence of `tuple` of (`str`, `~ndcube.NDCube` or `~ndcube.NDCubeSequence`) The names and data cubes/sequences to held in the collection. aligned_axes: `tuple` of `int`, `tuple` of `tuple` of `int`, 'all', or None, optional @@ -47,6 +49,12 @@ class NDCollection(dict): """ def __init__(self, key_data_pairs, aligned_axes=None, meta=None, **kwargs): + for key, _ in key_data_pairs: + if isinstance(key, numbers.Number): + warn_deprecated( + "Passing numerical keys to NDCollection is deprecated as they" + " lead to ambiguity when slicing the collection." + ) # Enter data and metadata into object. super().__init__(key_data_pairs) self.meta = meta