@@ -193,7 +193,7 @@ def test_reverse_strides_and_subspace_bufferinit(self):
193
193
c = np .arange (10 ).reshape (5 , 2 )[::- 1 ]
194
194
a [b , :] = c
195
195
assert_equal (a [0 ], [0 , 1 ])
196
-
196
+
197
197
def test_reversed_strides_result_allocation (self ):
198
198
# Test a bug when calculating the output strides for a result array
199
199
# when the subspace size was 1 (and test other cases as well)
@@ -367,6 +367,37 @@ def test_unaligned(self):
367
367
d [b % 2 == 0 ]
368
368
d [b % 2 == 0 ] = x [::2 ]
369
369
370
+ def test_tuple_subclass (self ):
371
+ arr = np .ones ((5 , 5 ))
372
+
373
+ # A tuple subclass should also be an nd-index
374
+ class TupleSubclass (tuple ):
375
+ pass
376
+ index = ([1 ], [1 ])
377
+ index = TupleSubclass (index )
378
+ assert_ (arr [index ].shape == (1 ,))
379
+ # Unlike the non nd-index:
380
+ assert_ (arr [index ,].shape != (1 ,))
381
+
382
+ def test_broken_sequence_not_nd_index (self ):
383
+ # See gh-5063:
384
+ # If we have an object which claims to be a sequence, but fails
385
+ # on item getting, this should not be converted to an nd-index (tuple)
386
+ # If this object happens to be a valid index otherwise, it should work
387
+ # This object here is very dubious and probably bad though:
388
+ class SequenceLike (object ):
389
+ def __index__ (self ):
390
+ return 0
391
+
392
+ def __len__ (self ):
393
+ return 1
394
+
395
+ def __getitem__ (self , item ):
396
+ raise IndexError ('Not possible' )
397
+
398
+ arr = np .arange (10 )
399
+ assert_array_equal (arr [SequenceLike ()], arr [SequenceLike (),])
400
+
370
401
371
402
class TestFieldIndexing (TestCase ):
372
403
def test_scalar_return_type (self ):
0 commit comments