Skip to content

Commit

Permalink
Merge pull request #778 from Cadair/no_numbers_collection
Browse files Browse the repository at this point in the history
Deprecate passing numerical keys to NDCollection
  • Loading branch information
Cadair authored Nov 6, 2024
2 parents 57b4c92 + cfd72fa commit a7f34b9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/778.removal.rst
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 9 additions & 1 deletion ndcube/ndcollection.py
Original file line number Diff line number Diff line change
@@ -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"]

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a7f34b9

Please sign in to comment.