@@ -70,7 +70,7 @@ def test_inf_upcast(self):
70
70
# np.inf should cause an index to convert to float
71
71
72
72
# Test with np.inf in rows
73
- df = pd . DataFrame (columns = [0 ])
73
+ df = DataFrame (columns = [0 ])
74
74
df .loc [1 ] = 1
75
75
df .loc [2 ] = 2
76
76
df .loc [np .inf ] = 3
@@ -83,7 +83,7 @@ def test_inf_upcast(self):
83
83
tm .assert_index_equal (result , expected )
84
84
85
85
# Test with np.inf in columns
86
- df = pd . DataFrame ()
86
+ df = DataFrame ()
87
87
df .loc [0 , 0 ] = 1
88
88
df .loc [1 , 1 ] = 2
89
89
df .loc [0 , np .inf ] = 3
@@ -274,8 +274,8 @@ def test_indexing_mixed_frame_bug(self):
274
274
275
275
def test_multitype_list_index_access (self ):
276
276
# GH 10610
277
- df = pd . DataFrame (np .random .random ((10 , 5 )),
278
- columns = ["a" ] + [20 , 21 , 22 , 23 ])
277
+ df = DataFrame (np .random .random ((10 , 5 )),
278
+ columns = ["a" ] + [20 , 21 , 22 , 23 ])
279
279
280
280
with pytest .raises (KeyError ):
281
281
df [[22 , 26 , - 8 ]]
@@ -469,16 +469,15 @@ def test_string_slice(self):
469
469
# GH 14424
470
470
# string indexing against datetimelike with object
471
471
# dtype should properly raises KeyError
472
- df = pd .DataFrame ([1 ], pd .Index ([pd .Timestamp ('2011-01-01' )],
473
- dtype = object ))
472
+ df = DataFrame ([1 ], Index ([pd .Timestamp ('2011-01-01' )], dtype = object ))
474
473
assert df .index .is_all_dates
475
474
with pytest .raises (KeyError ):
476
475
df ['2011' ]
477
476
478
477
with pytest .raises (KeyError ):
479
478
df .loc ['2011' , 0 ]
480
479
481
- df = pd . DataFrame ()
480
+ df = DataFrame ()
482
481
assert not df .index .is_all_dates
483
482
with pytest .raises (KeyError ):
484
483
df ['2011' ]
@@ -571,7 +570,7 @@ def test_astype_assignment_with_dups(self):
571
570
572
571
# GH 4686
573
572
# assignment with dups that has a dtype change
574
- cols = pd . MultiIndex .from_tuples ([('A' , '1' ), ('B' , '1' ), ('A' , '2' )])
573
+ cols = MultiIndex .from_tuples ([('A' , '1' ), ('B' , '1' ), ('A' , '2' )])
575
574
df = DataFrame (np .arange (3 ).reshape ((1 , 3 )),
576
575
columns = cols , dtype = object )
577
576
index = df .index .copy ()
@@ -584,23 +583,23 @@ def test_astype_assignment_with_dups(self):
584
583
# expected = Series({'float64': 2, 'object': 1}).sort_index()
585
584
586
585
@pytest .mark .parametrize ("index,val" , [
587
- (pd . Index ([0 , 1 , 2 ]), 2 ),
588
- (pd . Index ([0 , 1 , '2' ]), '2' ),
589
- (pd . Index ([0 , 1 , 2 , np .inf , 4 ]), 4 ),
590
- (pd . Index ([0 , 1 , 2 , np .nan , 4 ]), 4 ),
591
- (pd . Index ([0 , 1 , 2 , np .inf ]), np .inf ),
592
- (pd . Index ([0 , 1 , 2 , np .nan ]), np .nan ),
586
+ (Index ([0 , 1 , 2 ]), 2 ),
587
+ (Index ([0 , 1 , '2' ]), '2' ),
588
+ (Index ([0 , 1 , 2 , np .inf , 4 ]), 4 ),
589
+ (Index ([0 , 1 , 2 , np .nan , 4 ]), 4 ),
590
+ (Index ([0 , 1 , 2 , np .inf ]), np .inf ),
591
+ (Index ([0 , 1 , 2 , np .nan ]), np .nan ),
593
592
])
594
593
def test_index_contains (self , index , val ):
595
594
assert val in index
596
595
597
596
@pytest .mark .parametrize ("index,val" , [
598
- (pd . Index ([0 , 1 , 2 ]), '2' ),
599
- (pd . Index ([0 , 1 , '2' ]), 2 ),
600
- (pd . Index ([0 , 1 , 2 , np .inf ]), 4 ),
601
- (pd . Index ([0 , 1 , 2 , np .nan ]), 4 ),
602
- (pd . Index ([0 , 1 , 2 , np .inf ]), np .nan ),
603
- (pd . Index ([0 , 1 , 2 , np .nan ]), np .inf ),
597
+ (Index ([0 , 1 , 2 ]), '2' ),
598
+ (Index ([0 , 1 , '2' ]), 2 ),
599
+ (Index ([0 , 1 , 2 , np .inf ]), 4 ),
600
+ (Index ([0 , 1 , 2 , np .nan ]), 4 ),
601
+ (Index ([0 , 1 , 2 , np .inf ]), np .nan ),
602
+ (Index ([0 , 1 , 2 , np .nan ]), np .inf ),
604
603
# Checking if np.inf in Int64Index should not cause an OverflowError
605
604
# Related to GH 16957
606
605
(pd .Int64Index ([0 , 1 , 2 ]), np .inf ),
@@ -705,7 +704,7 @@ def test_float_index_non_scalar_assignment(self):
705
704
tm .assert_frame_equal (df , df2 )
706
705
707
706
def test_float_index_at_iat (self ):
708
- s = pd . Series ([1 , 2 , 3 ], index = [0.1 , 0.2 , 0.3 ])
707
+ s = Series ([1 , 2 , 3 ], index = [0.1 , 0.2 , 0.3 ])
709
708
for el , item in s .iteritems ():
710
709
assert s .at [el ] == item
711
710
for i in range (len (s )):
@@ -744,7 +743,7 @@ def run_tests(df, rhs, right):
744
743
745
744
xs = np .arange (20 ).reshape (5 , 4 )
746
745
cols = ['jim' , 'joe' , 'jolie' , 'joline' ]
747
- df = pd . DataFrame (xs , columns = cols , index = list ('abcde' ))
746
+ df = DataFrame (xs , columns = cols , index = list ('abcde' ))
748
747
749
748
# right hand side; permute the indices and multiplpy by -2
750
749
rhs = - 2 * df .iloc [3 :0 :- 1 , 2 :0 :- 1 ]
@@ -795,9 +794,9 @@ def test_slice_with_zero_step_raises(self):
795
794
lambda : s .ix [::0 ])
796
795
797
796
def test_indexing_assignment_dict_already_exists (self ):
798
- df = pd . DataFrame ({'x' : [1 , 2 , 6 ],
799
- 'y' : [2 , 2 , 8 ],
800
- 'z' : [- 5 , 0 , 5 ]}).set_index ('z' )
797
+ df = DataFrame ({'x' : [1 , 2 , 6 ],
798
+ 'y' : [2 , 2 , 8 ],
799
+ 'z' : [- 5 , 0 , 5 ]}).set_index ('z' )
801
800
expected = df .copy ()
802
801
rhs = dict (x = 9 , y = 99 )
803
802
df .loc [5 ] = rhs
@@ -819,15 +818,15 @@ def test_range_in_series_indexing(self):
819
818
# range can cause an indexing error
820
819
# GH 11652
821
820
for x in [5 , 999999 , 1000000 ]:
822
- s = pd . Series (index = range (x ))
821
+ s = Series (index = range (x ))
823
822
s .loc [range (1 )] = 42
824
823
tm .assert_series_equal (s .loc [range (1 )], Series (42.0 , index = [0 ]))
825
824
826
825
s .loc [range (2 )] = 43
827
826
tm .assert_series_equal (s .loc [range (2 )], Series (43.0 , index = [0 , 1 ]))
828
827
829
828
def test_non_reducing_slice (self ):
830
- df = pd . DataFrame ([[0 , 1 ], [2 , 3 ]])
829
+ df = DataFrame ([[0 , 1 ], [2 , 3 ]])
831
830
832
831
slices = [
833
832
# pd.IndexSlice[:, :],
@@ -841,23 +840,23 @@ def test_non_reducing_slice(self):
841
840
slice (None , None , None ),
842
841
[0 , 1 ],
843
842
np .array ([0 , 1 ]),
844
- pd . Series ([0 , 1 ])
843
+ Series ([0 , 1 ])
845
844
]
846
845
for slice_ in slices :
847
846
tslice_ = _non_reducing_slice (slice_ )
848
847
assert isinstance (df .loc [tslice_ ], DataFrame )
849
848
850
849
def test_list_slice (self ):
851
850
# like dataframe getitem
852
- slices = [['A' ], pd . Series (['A' ]), np .array (['A' ])]
853
- df = pd . DataFrame ({'A' : [1 , 2 ], 'B' : [3 , 4 ]}, index = ['A' , 'B' ])
851
+ slices = [['A' ], Series (['A' ]), np .array (['A' ])]
852
+ df = DataFrame ({'A' : [1 , 2 ], 'B' : [3 , 4 ]}, index = ['A' , 'B' ])
854
853
expected = pd .IndexSlice [:, ['A' ]]
855
854
for subset in slices :
856
855
result = _non_reducing_slice (subset )
857
856
tm .assert_frame_equal (df .loc [result ], df .loc [expected ])
858
857
859
858
def test_maybe_numeric_slice (self ):
860
- df = pd . DataFrame ({'A' : [1 , 2 ], 'B' : ['c' , 'd' ], 'C' : [True , False ]})
859
+ df = DataFrame ({'A' : [1 , 2 ], 'B' : ['c' , 'd' ], 'C' : [True , False ]})
861
860
result = _maybe_numeric_slice (df , slice_ = None )
862
861
expected = pd .IndexSlice [:, ['A' ]]
863
862
assert result == expected
@@ -870,20 +869,19 @@ def test_maybe_numeric_slice(self):
870
869
871
870
def test_partial_boolean_frame_indexing (self ):
872
871
# GH 17170
873
- df = pd .DataFrame (np .arange (9. ).reshape (3 , 3 ),
874
- index = list ('abc' ),
875
- columns = list ('ABC' ))
876
- index_df = pd .DataFrame (1 , index = list ('ab' ), columns = list ('AB' ))
872
+ df = DataFrame (np .arange (9. ).reshape (3 , 3 ),
873
+ index = list ('abc' ), columns = list ('ABC' ))
874
+ index_df = DataFrame (1 , index = list ('ab' ), columns = list ('AB' ))
877
875
result = df [index_df .notnull ()]
878
- expected = pd . DataFrame (np .array ([[0. , 1. , np .nan ],
879
- [3. , 4. , np .nan ],
880
- [np .nan ] * 3 ]),
881
- index = list ('abc' ),
882
- columns = list ('ABC' ))
876
+ expected = DataFrame (np .array ([[0. , 1. , np .nan ],
877
+ [3. , 4. , np .nan ],
878
+ [np .nan ] * 3 ]),
879
+ index = list ('abc' ),
880
+ columns = list ('ABC' ))
883
881
tm .assert_frame_equal (result , expected )
884
882
885
883
def test_no_reference_cycle (self ):
886
- df = pd . DataFrame ({'a' : [0 , 1 ], 'b' : [2 , 3 ]})
884
+ df = DataFrame ({'a' : [0 , 1 ], 'b' : [2 , 3 ]})
887
885
for name in ('loc' , 'iloc' , 'at' , 'iat' ):
888
886
getattr (df , name )
889
887
with catch_warnings (record = True ):
0 commit comments