@@ -70,7 +70,7 @@ def test_inf_upcast(self):
7070 # np.inf should cause an index to convert to float
7171
7272 # Test with np.inf in rows
73- df = pd . DataFrame (columns = [0 ])
73+ df = DataFrame (columns = [0 ])
7474 df .loc [1 ] = 1
7575 df .loc [2 ] = 2
7676 df .loc [np .inf ] = 3
@@ -83,7 +83,7 @@ def test_inf_upcast(self):
8383 tm .assert_index_equal (result , expected )
8484
8585 # Test with np.inf in columns
86- df = pd . DataFrame ()
86+ df = DataFrame ()
8787 df .loc [0 , 0 ] = 1
8888 df .loc [1 , 1 ] = 2
8989 df .loc [0 , np .inf ] = 3
@@ -274,8 +274,8 @@ def test_indexing_mixed_frame_bug(self):
274274
275275 def test_multitype_list_index_access (self ):
276276 # 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 ])
279279
280280 with pytest .raises (KeyError ):
281281 df [[22 , 26 , - 8 ]]
@@ -469,16 +469,15 @@ def test_string_slice(self):
469469 # GH 14424
470470 # string indexing against datetimelike with object
471471 # 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 ))
474473 assert df .index .is_all_dates
475474 with pytest .raises (KeyError ):
476475 df ['2011' ]
477476
478477 with pytest .raises (KeyError ):
479478 df .loc ['2011' , 0 ]
480479
481- df = pd . DataFrame ()
480+ df = DataFrame ()
482481 assert not df .index .is_all_dates
483482 with pytest .raises (KeyError ):
484483 df ['2011' ]
@@ -571,7 +570,7 @@ def test_astype_assignment_with_dups(self):
571570
572571 # GH 4686
573572 # 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' )])
575574 df = DataFrame (np .arange (3 ).reshape ((1 , 3 )),
576575 columns = cols , dtype = object )
577576 index = df .index .copy ()
@@ -584,23 +583,23 @@ def test_astype_assignment_with_dups(self):
584583 # expected = Series({'float64': 2, 'object': 1}).sort_index()
585584
586585 @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 ),
593592 ])
594593 def test_index_contains (self , index , val ):
595594 assert val in index
596595
597596 @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 ),
604603 # Checking if np.inf in Int64Index should not cause an OverflowError
605604 # Related to GH 16957
606605 (pd .Int64Index ([0 , 1 , 2 ]), np .inf ),
@@ -705,7 +704,7 @@ def test_float_index_non_scalar_assignment(self):
705704 tm .assert_frame_equal (df , df2 )
706705
707706 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 ])
709708 for el , item in s .iteritems ():
710709 assert s .at [el ] == item
711710 for i in range (len (s )):
@@ -744,7 +743,7 @@ def run_tests(df, rhs, right):
744743
745744 xs = np .arange (20 ).reshape (5 , 4 )
746745 cols = ['jim' , 'joe' , 'jolie' , 'joline' ]
747- df = pd . DataFrame (xs , columns = cols , index = list ('abcde' ))
746+ df = DataFrame (xs , columns = cols , index = list ('abcde' ))
748747
749748 # right hand side; permute the indices and multiplpy by -2
750749 rhs = - 2 * df .iloc [3 :0 :- 1 , 2 :0 :- 1 ]
@@ -795,9 +794,9 @@ def test_slice_with_zero_step_raises(self):
795794 lambda : s .ix [::0 ])
796795
797796 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' )
801800 expected = df .copy ()
802801 rhs = dict (x = 9 , y = 99 )
803802 df .loc [5 ] = rhs
@@ -819,15 +818,15 @@ def test_range_in_series_indexing(self):
819818 # range can cause an indexing error
820819 # GH 11652
821820 for x in [5 , 999999 , 1000000 ]:
822- s = pd . Series (index = range (x ))
821+ s = Series (index = range (x ))
823822 s .loc [range (1 )] = 42
824823 tm .assert_series_equal (s .loc [range (1 )], Series (42.0 , index = [0 ]))
825824
826825 s .loc [range (2 )] = 43
827826 tm .assert_series_equal (s .loc [range (2 )], Series (43.0 , index = [0 , 1 ]))
828827
829828 def test_non_reducing_slice (self ):
830- df = pd . DataFrame ([[0 , 1 ], [2 , 3 ]])
829+ df = DataFrame ([[0 , 1 ], [2 , 3 ]])
831830
832831 slices = [
833832 # pd.IndexSlice[:, :],
@@ -841,23 +840,23 @@ def test_non_reducing_slice(self):
841840 slice (None , None , None ),
842841 [0 , 1 ],
843842 np .array ([0 , 1 ]),
844- pd . Series ([0 , 1 ])
843+ Series ([0 , 1 ])
845844 ]
846845 for slice_ in slices :
847846 tslice_ = _non_reducing_slice (slice_ )
848847 assert isinstance (df .loc [tslice_ ], DataFrame )
849848
850849 def test_list_slice (self ):
851850 # 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' ])
854853 expected = pd .IndexSlice [:, ['A' ]]
855854 for subset in slices :
856855 result = _non_reducing_slice (subset )
857856 tm .assert_frame_equal (df .loc [result ], df .loc [expected ])
858857
859858 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 ]})
861860 result = _maybe_numeric_slice (df , slice_ = None )
862861 expected = pd .IndexSlice [:, ['A' ]]
863862 assert result == expected
@@ -870,20 +869,19 @@ def test_maybe_numeric_slice(self):
870869
871870 def test_partial_boolean_frame_indexing (self ):
872871 # 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' ))
877875 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' ))
883881 tm .assert_frame_equal (result , expected )
884882
885883 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 ]})
887885 for name in ('loc' , 'iloc' , 'at' , 'iat' ):
888886 getattr (df , name )
889887 with catch_warnings (record = True ):
0 commit comments