@@ -66,21 +66,6 @@ def test_getitem_dupe_cols(self):
66
66
with pytest .raises (KeyError , match = re .escape (msg )):
67
67
df [["baf" ]]
68
68
69
- @pytest .mark .parametrize ("key_type" , [iter , np .array , Series , Index ])
70
- def test_loc_iterable (self , float_frame , key_type ):
71
- idx = key_type (["A" , "B" , "C" ])
72
- result = float_frame .loc [:, idx ]
73
- expected = float_frame .loc [:, ["A" , "B" , "C" ]]
74
- tm .assert_frame_equal (result , expected )
75
-
76
- def test_loc_timedelta_0seconds (self ):
77
- # GH#10583
78
- df = DataFrame (np .random .normal (size = (10 , 4 )))
79
- df .index = pd .timedelta_range (start = "0s" , periods = 10 , freq = "s" )
80
- expected = df .loc [pd .Timedelta ("0s" ) :, :]
81
- result = df .loc ["0s" :, :]
82
- tm .assert_frame_equal (expected , result )
83
-
84
69
@pytest .mark .parametrize (
85
70
"idx_type" ,
86
71
[
@@ -125,28 +110,20 @@ def test_getitem_listlike(self, idx_type, levels, float_frame):
125
110
with pytest .raises (KeyError , match = "not in index" ):
126
111
frame [idx ]
127
112
128
- @pytest .mark .parametrize (
129
- "val,expected" , [(2 ** 63 - 1 , Series ([1 ])), (2 ** 63 , Series ([2 ]))]
130
- )
131
- def test_loc_uint64 (self , val , expected ):
132
- # see gh-19399
133
- df = DataFrame ([1 , 2 ], index = [2 ** 63 - 1 , 2 ** 63 ])
134
- result = df .loc [val ]
135
-
136
- expected .name = val
137
- tm .assert_series_equal (result , expected )
138
-
139
113
def test_getitem_callable (self , float_frame ):
140
114
# GH 12533
141
115
result = float_frame [lambda x : "A" ]
142
- tm .assert_series_equal (result , float_frame .loc [:, "A" ])
116
+ expected = float_frame .loc [:, "A" ]
117
+ tm .assert_series_equal (result , expected )
143
118
144
119
result = float_frame [lambda x : ["A" , "B" ]]
120
+ expected = float_frame .loc [:, ["A" , "B" ]]
145
121
tm .assert_frame_equal (result , float_frame .loc [:, ["A" , "B" ]])
146
122
147
123
df = float_frame [:3 ]
148
124
result = df [lambda x : [True , False , True ]]
149
- tm .assert_frame_equal (result , float_frame .iloc [[0 , 2 ], :])
125
+ expected = float_frame .iloc [[0 , 2 ], :]
126
+ tm .assert_frame_equal (result , expected )
150
127
151
128
def test_setitem_list (self , float_frame ):
152
129
@@ -181,11 +158,6 @@ def test_setitem_list(self, float_frame):
181
158
expected = Series (["1" , "2" ], df .columns , name = 1 )
182
159
tm .assert_series_equal (result , expected )
183
160
184
- def test_setitem_list_not_dataframe (self , float_frame ):
185
- data = np .random .randn (len (float_frame ), 2 )
186
- float_frame [["A" , "B" ]] = data
187
- tm .assert_almost_equal (float_frame [["A" , "B" ]].values , data )
188
-
189
161
def test_setitem_list_of_tuples (self , float_frame ):
190
162
tuples = list (zip (float_frame ["A" ], float_frame ["B" ]))
191
163
float_frame ["tuples" ] = tuples
@@ -273,14 +245,6 @@ def test_setitem_multi_index(self):
273
245
df [("joe" , "last" )] = df [("jolie" , "first" )].loc [i , j ]
274
246
tm .assert_frame_equal (df [("joe" , "last" )], df [("jolie" , "first" )])
275
247
276
- def test_setitem_callable (self ):
277
- # GH 12533
278
- df = DataFrame ({"A" : [1 , 2 , 3 , 4 ], "B" : [5 , 6 , 7 , 8 ]})
279
- df [lambda x : "A" ] = [11 , 12 , 13 , 14 ]
280
-
281
- exp = DataFrame ({"A" : [11 , 12 , 13 , 14 ], "B" : [5 , 6 , 7 , 8 ]})
282
- tm .assert_frame_equal (df , exp )
283
-
284
248
def test_setitem_other_callable (self ):
285
249
# GH 13299
286
250
def inc (x ):
@@ -518,18 +482,13 @@ def test_setitem(self, float_frame):
518
482
df .loc [0 ] = np .nan
519
483
tm .assert_frame_equal (df , expected )
520
484
521
- @pytest .mark .parametrize ("dtype" , ["int32" , "int64" , "float32" , "float64" ])
522
- def test_setitem_dtype (self , dtype , float_frame ):
523
- arr = np .random .randn (len (float_frame ))
524
-
525
- float_frame [dtype ] = np .array (arr , dtype = dtype )
526
- assert float_frame [dtype ].dtype .name == dtype
527
-
528
485
def test_setitem_tuple (self , float_frame ):
529
486
float_frame ["A" , "B" ] = float_frame ["A" ]
530
- tm .assert_series_equal (
531
- float_frame ["A" , "B" ], float_frame ["A" ], check_names = False
532
- )
487
+ assert ("A" , "B" ) in float_frame .columns
488
+
489
+ result = float_frame ["A" , "B" ]
490
+ expected = float_frame ["A" ]
491
+ tm .assert_series_equal (result , expected , check_names = False )
533
492
534
493
def test_setitem_always_copy (self , float_frame ):
535
494
s = float_frame ["A" ].copy ()
@@ -588,25 +547,6 @@ def test_setitem_boolean(self, float_frame):
588
547
np .putmask (expected .values , mask .values , df .values * 2 )
589
548
tm .assert_frame_equal (df , expected )
590
549
591
- @pytest .mark .parametrize (
592
- "mask_type" ,
593
- [lambda df : df > np .abs (df ) / 2 , lambda df : (df > np .abs (df ) / 2 ).values ],
594
- ids = ["dataframe" , "array" ],
595
- )
596
- def test_setitem_boolean_mask (self , mask_type , float_frame ):
597
-
598
- # Test for issue #18582
599
- df = float_frame .copy ()
600
- mask = mask_type (df )
601
-
602
- # index with boolean mask
603
- result = df .copy ()
604
- result [mask ] = np .nan
605
-
606
- expected = df .copy ()
607
- expected .values [np .array (mask )] = np .nan
608
- tm .assert_frame_equal (result , expected )
609
-
610
550
def test_setitem_cast (self , float_frame ):
611
551
float_frame ["D" ] = float_frame ["D" ].astype ("i8" )
612
552
assert float_frame ["D" ].dtype == np .int64
@@ -821,19 +761,6 @@ def test_getitem_empty_frame_with_boolean(self):
821
761
df2 = df [df > 0 ]
822
762
tm .assert_frame_equal (df , df2 )
823
763
824
- def test_slice_floats (self ):
825
- index = [52195.504153 , 52196.303147 , 52198.369883 ]
826
- df = DataFrame (np .random .rand (3 , 2 ), index = index )
827
-
828
- s1 = df .loc [52195.1 :52196.5 ]
829
- assert len (s1 ) == 2
830
-
831
- s1 = df .loc [52195.1 :52196.6 ]
832
- assert len (s1 ) == 2
833
-
834
- s1 = df .loc [52195.1 :52198.9 ]
835
- assert len (s1 ) == 3
836
-
837
764
def test_getitem_fancy_slice_integers_step (self ):
838
765
df = DataFrame (np .random .randn (10 , 5 ))
839
766
@@ -883,15 +810,6 @@ def test_fancy_getitem_slice_mixed(self, float_frame, float_string_frame):
883
810
884
811
assert (float_frame ["C" ] == 4 ).all ()
885
812
886
- def test_setitem_slice_position (self ):
887
- # GH#31469
888
- df = DataFrame (np .zeros ((100 , 1 )))
889
- df [- 4 :] = 1
890
- arr = np .zeros ((100 , 1 ))
891
- arr [- 4 :] = 1
892
- expected = DataFrame (arr )
893
- tm .assert_frame_equal (df , expected )
894
-
895
813
def test_getitem_setitem_non_ix_labels (self ):
896
814
df = tm .makeTimeDataFrame ()
897
815
@@ -1000,14 +918,13 @@ def test_getitem_fancy_ints(self, float_frame):
1000
918
expected = float_frame .loc [:, float_frame .columns [[2 , 0 , 1 ]]]
1001
919
tm .assert_frame_equal (result , expected )
1002
920
1003
- def test_getitem_setitem_fancy_exceptions (self , float_frame ):
1004
- ix = float_frame .iloc
921
+ def test_iloc_getitem_setitem_fancy_exceptions (self , float_frame ):
1005
922
with pytest .raises (IndexingError , match = "Too many indexers" ):
1006
- ix [:, :, :]
923
+ float_frame . iloc [:, :, :]
1007
924
1008
925
with pytest .raises (IndexError , match = "too many indices for array" ):
1009
926
# GH#32257 we let numpy do validation, get their exception
1010
- ix [:, :, :] = 1
927
+ float_frame . iloc [:, :, :] = 1
1011
928
1012
929
def test_getitem_setitem_boolean_misaligned (self , float_frame ):
1013
930
# boolean index misaligned labels
0 commit comments