File tree Expand file tree Collapse file tree 2 files changed +14
-12
lines changed Expand file tree Collapse file tree 2 files changed +14
-12
lines changed Original file line number Diff line number Diff line change @@ -91,10 +91,11 @@ def append_set_dimension(self, labels=None):
91
91
index = len (self .dimensions ) + 1
92
92
setdim = SetDimension .create_new (self , index )
93
93
if labels is not None :
94
- if not hasattr (labels , '__iter__' ):
95
- labels = str (labels )
96
- if isinstance (labels , str ):
97
- labels = [labels ]
94
+ if not hasattr (labels , '__iter__' ) or isinstance (labels , str ):
95
+ raise ValueError ('`labels` has to be a list-like object.' )
96
+ for label in labels :
97
+ if not isinstance (label , str ):
98
+ raise ValueError (f'`labels` has to contain string objects, not { type (label )} ' )
98
99
if not isinstance (labels , list ):
99
100
labels = list (labels )
100
101
setdim .labels = labels
Original file line number Diff line number Diff line change @@ -158,15 +158,16 @@ def test_set_dim_labels_array(self):
158
158
setdim = self .array .append_set_dimension (labels )
159
159
assert tuple (labels ) == setdim .labels
160
160
161
- def test_set_dim_labels_single_string (self ):
162
- labels = 'Sample 1'
163
- setdim = self .array .append_set_dimension (labels )
164
- assert tuple ([labels ]) == setdim .labels
161
+ def test_set_dim_invalid_labels (self ):
162
+ # don't accept non list-like labels
163
+ with self .assertRaises (ValueError ):
164
+ self .array .append_set_dimension ('Sample 1' )
165
+ with self .assertRaises (ValueError ):
166
+ self .array .append_set_dimension (1000 )
165
167
166
- def test_set_dim_labels_single_float (self ):
167
- labels = 1000
168
- setdim = self .array .append_set_dimension (labels )
169
- assert tuple ([str (labels )]) == setdim .labels
168
+ # don't accept list of non-string objects
169
+ with self .assertRaises (ValueError ):
170
+ self .array .append_set_dimension ([1 , 2 , 3 ])
170
171
171
172
def test_range_dim_ticks_resize (self ):
172
173
rangedim = self .array .append_range_dimension ([1 , 2 , 100 ])
You can’t perform that action at this time.
0 commit comments