@@ -1564,3 +1564,39 @@ def test_index(self):
1564
1564
idx = Index (['1 day' , '1 day' , '-1 day' , '-1 day 2 min' ,
1565
1565
'2 min' , '2 min' ], dtype = 'timedelta64[ns]' )
1566
1566
tm .assert_series_equal (algos .mode (idx ), exp )
1567
+
1568
+
1569
+ class TestTake (object ):
1570
+
1571
+ def test_bounds_check_large (self ):
1572
+ arr = np .array ([1 , 2 ])
1573
+ with pytest .raises (IndexError ):
1574
+ algos .take (arr , [2 , 3 ], allow_fill = True )
1575
+
1576
+ with pytest .raises (IndexError ):
1577
+ algos .take (arr , [2 , 3 ], allow_fill = False )
1578
+
1579
+ def test_bounds_check_small (self ):
1580
+ arr = np .array ([1 , 2 , 3 ], dtype = np .int64 )
1581
+ indexer = [0 , - 1 , - 2 ]
1582
+ with pytest .raises (ValueError ):
1583
+ algos .take (arr , indexer , allow_fill = True )
1584
+
1585
+ result = algos .take (arr , indexer )
1586
+ expected = np .array ([1 , 3 , 2 ], dtype = np .int64 )
1587
+ tm .assert_numpy_array_equal (result , expected )
1588
+
1589
+ @pytest .mark .parametrize ('allow_fill' , [True , False ])
1590
+ def test_take_empty (self , allow_fill ):
1591
+ arr = np .array ([], dtype = np .int64 )
1592
+ # empty take is ok
1593
+ result = algos .take (arr , [], allow_fill = allow_fill )
1594
+ tm .assert_numpy_array_equal (arr , result )
1595
+
1596
+ with pytest .raises (IndexError ):
1597
+ algos .take (arr , [0 ], allow_fill = allow_fill )
1598
+
1599
+ def test_take_na_empty (self ):
1600
+ result = algos .take ([], [- 1 , - 1 ], allow_fill = True , fill_value = 0 )
1601
+ expected = np .array ([0 , 0 ], dtype = np .int64 )
1602
+ tm .assert_numpy_array_equal (result , expected )
0 commit comments