22
33from datetime import datetime
44import re
5- from warnings import catch_warnings , simplefilter
65import weakref
76
87import numpy as np
2019from pandas .tests .indexing .common import Base , _mklbl
2120import pandas .util .testing as tm
2221
23- ignore_ix = pytest .mark .filterwarnings ("ignore:\\ n.ix:FutureWarning" )
24-
2522# ------------------------------------------------------------------------
2623# Indexing test cases
2724
@@ -75,7 +72,6 @@ def test_setitem_ndarray_1d(self):
7572 (lambda x : x , "getitem" ),
7673 (lambda x : x .loc , "loc" ),
7774 (lambda x : x .iloc , "iloc" ),
78- pytest .param (lambda x : x .ix , "ix" , marks = ignore_ix ),
7975 ],
8076 )
8177 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):
141137 (lambda x : x , "setitem" ),
142138 (lambda x : x .loc , "loc" ),
143139 (lambda x : x .iloc , "iloc" ),
144- pytest .param (lambda x : x .ix , "ix" , marks = ignore_ix ),
145140 ],
146141 )
147142 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):
163158 r"^\[\[\[" # pandas.core.indexing.IndexingError
164159 )
165160
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+ ]
187175 )
188176 ):
189177 idxr [nd3 ] = 0
@@ -427,10 +415,6 @@ def test_indexing_mixed_frame_bug(self):
427415 df .loc [idx , "test" ] = temp
428416 assert df .iloc [0 , 2 ] == "-----"
429417
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-
434418 def test_multitype_list_index_access (self ):
435419 # GH 10610
436420 df = DataFrame (np .random .random ((10 , 5 )), columns = ["a" ] + [20 , 21 , 22 , 23 ])
@@ -592,21 +576,17 @@ def test_multi_assign(self):
592576 def test_setitem_list (self ):
593577
594578 # GH 6043
595- # ix with a list
579+ # iloc with a list
596580 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 ]
601583
602584 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 ]
606586
607587 tm .assert_frame_equal (result , df )
608588
609- # ix with an object
589+ # iloc with an object
610590 class TO :
611591 def __init__ (self , value ):
612592 self .value = value
@@ -623,24 +603,18 @@ def view(self):
623603 return self
624604
625605 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 )
630608
631609 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 )
635611
636612 tm .assert_frame_equal (result , df )
637613
638614 # remains object dtype even after setting it back
639615 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
644618 result = DataFrame (index = [0 , 1 ], columns = [0 ])
645619
646620 tm .assert_frame_equal (result , df )
@@ -777,55 +751,52 @@ def test_contains_with_float_index(self):
777751
778752 def test_index_type_coercion (self ):
779753
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
788759
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 ))]:
791762
792- assert s .index .is_integer ()
763+ assert s .index .is_integer ()
793764
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
799770
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 )
806777
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 ()
810781
811- for s in [Series (range (5 ), index = np .arange (5.0 ))]:
782+ for s in [Series (range (5 ), index = np .arange (5.0 ))]:
812783
813- assert s .index .is_floating ()
784+ assert s .index .is_floating ()
814785
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 ]:
816787
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
821792
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 )
825796
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 ()
829800
830801
831802class TestMisc (Base ):
@@ -887,22 +858,7 @@ def run_tests(df, rhs, right):
887858 tm .assert_frame_equal (left , right )
888859
889860 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
906862 tm .assert_frame_equal (left , right )
907863
908864 xs = np .arange (20 ).reshape (5 , 4 )
@@ -933,7 +889,7 @@ def assert_slices_equivalent(l_slc, i_slc):
933889 tm .assert_series_equal (s .loc [l_slc ], s .iloc [i_slc ])
934890
935891 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.
937893 tm .assert_series_equal (s [l_slc ], s .iloc [i_slc ])
938894 tm .assert_series_equal (s .loc [l_slc ], s .iloc [i_slc ])
939895
@@ -951,10 +907,6 @@ def test_slice_with_zero_step_raises(self):
951907 s [::0 ]
952908 with pytest .raises (ValueError , match = "slice step cannot be zero" ):
953909 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 ]
958910
959911 def test_indexing_assignment_dict_already_exists (self ):
960912 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):
965917 tm .assert_frame_equal (df , expected )
966918
967919 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
969921 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 [[], :]
973923
974924 assert df2 .loc [:, "a" ].dtype == np .int64
975925 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 ])
979926
980927 def test_range_in_series_indexing (self ):
981928 # range can cause an indexing error
@@ -1048,9 +995,6 @@ def test_no_reference_cycle(self):
1048995 df = DataFrame ({"a" : [0 , 1 ], "b" : [2 , 3 ]})
1049996 for name in ("loc" , "iloc" , "at" , "iat" ):
1050997 getattr (df , name )
1051- with catch_warnings (record = True ):
1052- simplefilter ("ignore" )
1053- getattr (df , "ix" )
1054998 wr = weakref .ref (df )
1055999 del df
10561000 assert wr () is None
@@ -1235,12 +1179,6 @@ def test_extension_array_cross_section_converts():
12351179 AttributeError ,
12361180 "type object 'NDFrame' has no attribute '_AXIS_ALIASES'" ,
12371181 ),
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- ),
12441182 ],
12451183)
12461184def test_ndframe_indexing_raises (idxr , error , error_message ):
0 commit comments