Skip to content

Commit 66e3fed

Browse files
committed
Accept array_annotation values of tuple type
1 parent 727207e commit 66e3fed

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

neo/core/dataobject.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def _normalize_array_annotations(value, length):
2020
2121
Parameters
2222
----------
23-
value : np.ndarray or list or dict
23+
value : np.ndarray or list or tuple or dict
2424
Value to be checked for consistency.
2525
length : int
2626
Required length of the array annotation.
@@ -48,7 +48,7 @@ def _normalize_array_annotations(value, length):
4848
raise ValueError("Array annotations must not be None")
4949
# If not array annotation, pass on to regular check and make it a list, that is checked again
5050
# This covers array annotations with length 1
51-
elif not isinstance(value, (list, np.ndarray)) or (
51+
elif not isinstance(value, (list, np.ndarray, tuple)) or (
5252
isinstance(value, pq.Quantity) and value.shape == ()):
5353
_check_annotations(value)
5454
value = _normalize_array_annotations(np.array([value]), length)

neo/test/coretest/test_dataobject.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ def test_check_arr_ann(self):
7979
self.assertIsInstance(list_ann['anno1'], np.ndarray)
8080
self.assertIsInstance(list_ann['anno2'], np.ndarray)
8181

82+
# Tuple are also made to np.ndarrays
83+
list_ann = {'anno1': (3, 6), 'anno2': ('ABC', 'DEF')}
84+
list_ann = _normalize_array_annotations(list_ann, datobj._get_arr_ann_length())
85+
self.assertIsInstance(list_ann['anno1'], np.ndarray)
86+
self.assertIsInstance(list_ann['anno2'], np.ndarray)
87+
8288
def test_implicit_dict_check(self):
8389
# DataObject instance that handles checking
8490
datobj = DataObject([1, 2]) # Inherits from Quantity, so some data is required

0 commit comments

Comments
 (0)