2
2
3
3
from datetime import datetime
4
4
import re
5
- from warnings import catch_warnings , simplefilter
6
5
import weakref
7
6
8
7
import numpy as np
20
19
from pandas .tests .indexing .common import Base , _mklbl
21
20
import pandas .util .testing as tm
22
21
23
- ignore_ix = pytest .mark .filterwarnings ("ignore:\\ n.ix:FutureWarning" )
24
-
25
22
# ------------------------------------------------------------------------
26
23
# Indexing test cases
27
24
@@ -75,7 +72,6 @@ def test_setitem_ndarray_1d(self):
75
72
(lambda x : x , "getitem" ),
76
73
(lambda x : x .loc , "loc" ),
77
74
(lambda x : x .iloc , "iloc" ),
78
- pytest .param (lambda x : x .ix , "ix" , marks = ignore_ix ),
79
75
],
80
76
)
81
77
def test_getitem_ndarray_3d (self , index , obj , idxr , idxr_id ):
@@ -141,7 +137,6 @@ def test_getitem_ndarray_3d(self, index, obj, idxr, idxr_id):
141
137
(lambda x : x , "setitem" ),
142
138
(lambda x : x .loc , "loc" ),
143
139
(lambda x : x .iloc , "iloc" ),
144
- pytest .param (lambda x : x .ix , "ix" , marks = ignore_ix ),
145
140
],
146
141
)
147
142
def test_setitem_ndarray_3d (self , index , obj , idxr , idxr_id ):
@@ -163,27 +158,20 @@ def test_setitem_ndarray_3d(self, index, obj, idxr, idxr_id):
163
158
r"^\[\[\[" # pandas.core.indexing.IndexingError
164
159
)
165
160
166
- if (
167
- (idxr_id == "iloc" )
168
- or (
169
- (
170
- isinstance (obj , Series )
171
- and idxr_id == "setitem"
172
- and index .inferred_type
173
- in [
174
- "floating" ,
175
- "string" ,
176
- "datetime64" ,
177
- "period" ,
178
- "timedelta64" ,
179
- "boolean" ,
180
- "categorical" ,
181
- ]
182
- )
183
- )
184
- or (
185
- idxr_id == "ix"
186
- and index .inferred_type in ["string" , "datetime64" , "period" , "boolean" ]
161
+ if (idxr_id == "iloc" ) or (
162
+ (
163
+ isinstance (obj , Series )
164
+ and idxr_id == "setitem"
165
+ and index .inferred_type
166
+ in [
167
+ "floating" ,
168
+ "string" ,
169
+ "datetime64" ,
170
+ "period" ,
171
+ "timedelta64" ,
172
+ "boolean" ,
173
+ "categorical" ,
174
+ ]
187
175
)
188
176
):
189
177
idxr [nd3 ] = 0
@@ -427,10 +415,6 @@ def test_indexing_mixed_frame_bug(self):
427
415
df .loc [idx , "test" ] = temp
428
416
assert df .iloc [0 , 2 ] == "-----"
429
417
430
- # if I look at df, then element [0,2] equals '_'. If instead I type
431
- # df.ix[idx,'test'], I get '-----', finally by typing df.iloc[0,2] I
432
- # get '_'.
433
-
434
418
def test_multitype_list_index_access (self ):
435
419
# GH 10610
436
420
df = DataFrame (np .random .random ((10 , 5 )), columns = ["a" ] + [20 , 21 , 22 , 23 ])
@@ -592,21 +576,17 @@ def test_multi_assign(self):
592
576
def test_setitem_list (self ):
593
577
594
578
# GH 6043
595
- # ix with a list
579
+ # iloc with a list
596
580
df = DataFrame (index = [0 , 1 ], columns = [0 ])
597
- with catch_warnings (record = True ):
598
- simplefilter ("ignore" )
599
- df .ix [1 , 0 ] = [1 , 2 , 3 ]
600
- df .ix [1 , 0 ] = [1 , 2 ]
581
+ df .iloc [1 , 0 ] = [1 , 2 , 3 ]
582
+ df .iloc [1 , 0 ] = [1 , 2 ]
601
583
602
584
result = DataFrame (index = [0 , 1 ], columns = [0 ])
603
- with catch_warnings (record = True ):
604
- simplefilter ("ignore" )
605
- result .ix [1 , 0 ] = [1 , 2 ]
585
+ result .iloc [1 , 0 ] = [1 , 2 ]
606
586
607
587
tm .assert_frame_equal (result , df )
608
588
609
- # ix with an object
589
+ # iloc with an object
610
590
class TO :
611
591
def __init__ (self , value ):
612
592
self .value = value
@@ -623,24 +603,18 @@ def view(self):
623
603
return self
624
604
625
605
df = DataFrame (index = [0 , 1 ], columns = [0 ])
626
- with catch_warnings (record = True ):
627
- simplefilter ("ignore" )
628
- df .ix [1 , 0 ] = TO (1 )
629
- df .ix [1 , 0 ] = TO (2 )
606
+ df .iloc [1 , 0 ] = TO (1 )
607
+ df .iloc [1 , 0 ] = TO (2 )
630
608
631
609
result = DataFrame (index = [0 , 1 ], columns = [0 ])
632
- with catch_warnings (record = True ):
633
- simplefilter ("ignore" )
634
- result .ix [1 , 0 ] = TO (2 )
610
+ result .iloc [1 , 0 ] = TO (2 )
635
611
636
612
tm .assert_frame_equal (result , df )
637
613
638
614
# remains object dtype even after setting it back
639
615
df = DataFrame (index = [0 , 1 ], columns = [0 ])
640
- with catch_warnings (record = True ):
641
- simplefilter ("ignore" )
642
- df .ix [1 , 0 ] = TO (1 )
643
- df .ix [1 , 0 ] = np .nan
616
+ df .iloc [1 , 0 ] = TO (1 )
617
+ df .iloc [1 , 0 ] = np .nan
644
618
result = DataFrame (index = [0 , 1 ], columns = [0 ])
645
619
646
620
tm .assert_frame_equal (result , df )
@@ -777,55 +751,52 @@ def test_contains_with_float_index(self):
777
751
778
752
def test_index_type_coercion (self ):
779
753
780
- with catch_warnings (record = True ):
781
- simplefilter ("ignore" )
782
-
783
- # GH 11836
784
- # if we have an index type and set it with something that looks
785
- # to numpy like the same, but is actually, not
786
- # (e.g. setting with a float or string '0')
787
- # then we need to coerce to object
754
+ # GH 11836
755
+ # if we have an index type and set it with something that looks
756
+ # to numpy like the same, but is actually, not
757
+ # (e.g. setting with a float or string '0')
758
+ # then we need to coerce to object
788
759
789
- # integer indexes
790
- for s in [Series (range (5 )), Series (range (5 ), index = range (1 , 6 ))]:
760
+ # integer indexes
761
+ for s in [Series (range (5 )), Series (range (5 ), index = range (1 , 6 ))]:
791
762
792
- assert s .index .is_integer ()
763
+ assert s .index .is_integer ()
793
764
794
- for indexer in [lambda x : x . ix , lambda x : x .loc , lambda x : x ]:
795
- s2 = s .copy ()
796
- indexer (s2 )[0.1 ] = 0
797
- assert s2 .index .is_floating ()
798
- assert indexer (s2 )[0.1 ] == 0
765
+ for indexer in [lambda x : x .loc , lambda x : x ]:
766
+ s2 = s .copy ()
767
+ indexer (s2 )[0.1 ] = 0
768
+ assert s2 .index .is_floating ()
769
+ assert indexer (s2 )[0.1 ] == 0
799
770
800
- s2 = s .copy ()
801
- indexer (s2 )[0.0 ] = 0
802
- exp = s .index
803
- if 0 not in s :
804
- exp = Index (s .index .tolist () + [0 ])
805
- tm .assert_index_equal (s2 .index , exp )
771
+ s2 = s .copy ()
772
+ indexer (s2 )[0.0 ] = 0
773
+ exp = s .index
774
+ if 0 not in s :
775
+ exp = Index (s .index .tolist () + [0 ])
776
+ tm .assert_index_equal (s2 .index , exp )
806
777
807
- s2 = s .copy ()
808
- indexer (s2 )["0" ] = 0
809
- assert s2 .index .is_object ()
778
+ s2 = s .copy ()
779
+ indexer (s2 )["0" ] = 0
780
+ assert s2 .index .is_object ()
810
781
811
- for s in [Series (range (5 ), index = np .arange (5.0 ))]:
782
+ for s in [Series (range (5 ), index = np .arange (5.0 ))]:
812
783
813
- assert s .index .is_floating ()
784
+ assert s .index .is_floating ()
814
785
815
- for idxr in [lambda x : x . ix , lambda x : x .loc , lambda x : x ]:
786
+ for idxr in [lambda x : x .loc , lambda x : x ]:
816
787
817
- s2 = s .copy ()
818
- idxr (s2 )[0.1 ] = 0
819
- assert s2 .index .is_floating ()
820
- assert idxr (s2 )[0.1 ] == 0
788
+ s2 = s .copy ()
789
+ idxr (s2 )[0.1 ] = 0
790
+ assert s2 .index .is_floating ()
791
+ assert idxr (s2 )[0.1 ] == 0
821
792
822
- s2 = s .copy ()
823
- idxr (s2 )[0.0 ] = 0
824
- tm .assert_index_equal (s2 .index , s .index )
793
+ s2 = s .copy ()
794
+ idxr (s2 )[0.0 ] = 0
795
+ tm .assert_index_equal (s2 .index , s .index )
825
796
826
- s2 = s .copy ()
827
- idxr (s2 )["0" ] = 0
828
- assert s2 .index .is_object ()
797
+ s2 = s .copy ()
798
+ idxr (s2 )["0" ] = 0
799
+ assert s2 .index .is_object ()
829
800
830
801
831
802
class TestMisc (Base ):
@@ -887,22 +858,7 @@ def run_tests(df, rhs, right):
887
858
tm .assert_frame_equal (left , right )
888
859
889
860
left = df .copy ()
890
- with catch_warnings (record = True ):
891
- # XXX: finer-filter here.
892
- simplefilter ("ignore" )
893
- left .ix [slice_one , slice_two ] = rhs
894
- tm .assert_frame_equal (left , right )
895
-
896
- left = df .copy ()
897
- with catch_warnings (record = True ):
898
- simplefilter ("ignore" )
899
- left .ix [idx_one , idx_two ] = rhs
900
- tm .assert_frame_equal (left , right )
901
-
902
- left = df .copy ()
903
- with catch_warnings (record = True ):
904
- simplefilter ("ignore" )
905
- left .ix [lbl_one , lbl_two ] = rhs
861
+ left .iloc [slice_one , slice_two ] = rhs
906
862
tm .assert_frame_equal (left , right )
907
863
908
864
xs = np .arange (20 ).reshape (5 , 4 )
@@ -933,7 +889,7 @@ def assert_slices_equivalent(l_slc, i_slc):
933
889
tm .assert_series_equal (s .loc [l_slc ], s .iloc [i_slc ])
934
890
935
891
if not idx .is_integer :
936
- # For integer indices, ix and plain getitem are position-based.
892
+ # For integer indices, .loc and plain getitem are position-based.
937
893
tm .assert_series_equal (s [l_slc ], s .iloc [i_slc ])
938
894
tm .assert_series_equal (s .loc [l_slc ], s .iloc [i_slc ])
939
895
@@ -951,10 +907,6 @@ def test_slice_with_zero_step_raises(self):
951
907
s [::0 ]
952
908
with pytest .raises (ValueError , match = "slice step cannot be zero" ):
953
909
s .loc [::0 ]
954
- with catch_warnings (record = True ):
955
- simplefilter ("ignore" )
956
- with pytest .raises (ValueError , match = "slice step cannot be zero" ):
957
- s .ix [::0 ]
958
910
959
911
def test_indexing_assignment_dict_already_exists (self ):
960
912
df = DataFrame ({"x" : [1 , 2 , 6 ], "y" : [2 , 2 , 8 ], "z" : [- 5 , 0 , 5 ]}).set_index ("z" )
@@ -965,17 +917,12 @@ def test_indexing_assignment_dict_already_exists(self):
965
917
tm .assert_frame_equal (df , expected )
966
918
967
919
def test_indexing_dtypes_on_empty (self ):
968
- # Check that .iloc and .ix return correct dtypes GH9983
920
+ # Check that .iloc returns correct dtypes GH9983
969
921
df = DataFrame ({"a" : [1 , 2 , 3 ], "b" : ["b" , "b2" , "b3" ]})
970
- with catch_warnings (record = True ):
971
- simplefilter ("ignore" )
972
- df2 = df .ix [[], :]
922
+ df2 = df .iloc [[], :]
973
923
974
924
assert df2 .loc [:, "a" ].dtype == np .int64
975
925
tm .assert_series_equal (df2 .loc [:, "a" ], df2 .iloc [:, 0 ])
976
- with catch_warnings (record = True ):
977
- simplefilter ("ignore" )
978
- tm .assert_series_equal (df2 .loc [:, "a" ], df2 .ix [:, 0 ])
979
926
980
927
def test_range_in_series_indexing (self ):
981
928
# range can cause an indexing error
@@ -1048,9 +995,6 @@ def test_no_reference_cycle(self):
1048
995
df = DataFrame ({"a" : [0 , 1 ], "b" : [2 , 3 ]})
1049
996
for name in ("loc" , "iloc" , "at" , "iat" ):
1050
997
getattr (df , name )
1051
- with catch_warnings (record = True ):
1052
- simplefilter ("ignore" )
1053
- getattr (df , "ix" )
1054
998
wr = weakref .ref (df )
1055
999
del df
1056
1000
assert wr () is None
@@ -1235,12 +1179,6 @@ def test_extension_array_cross_section_converts():
1235
1179
AttributeError ,
1236
1180
"type object 'NDFrame' has no attribute '_AXIS_ALIASES'" ,
1237
1181
),
1238
- pytest .param (
1239
- lambda x : x .ix ,
1240
- ValueError ,
1241
- "NDFrameIndexer does not support NDFrame objects with ndim > 2" ,
1242
- marks = ignore_ix ,
1243
- ),
1244
1182
],
1245
1183
)
1246
1184
def test_ndframe_indexing_raises (idxr , error , error_message ):
0 commit comments