@@ -9035,6 +9035,16 @@ def test_apply_mixed_dtype_corner(self):
90359035 expected = Series (np .nan , index = [])
90369036 assert_series_equal (result , expected )
90379037
9038+ df = DataFrame ({'A' : ['foo' ],
9039+ 'B' : [1. ]})
9040+ result = df .apply (lambda x : x ['A' ], axis = 1 )
9041+ expected = Series (['foo' ],index = [0 ])
9042+ assert_series_equal (result , expected )
9043+
9044+ result = df .apply (lambda x : x ['B' ], axis = 1 )
9045+ expected = Series ([1. ],index = [0 ])
9046+ assert_series_equal (result , expected )
9047+
90389048 def test_apply_empty_infer_type (self ):
90399049 no_cols = DataFrame (index = ['a' , 'b' , 'c' ])
90409050 no_index = DataFrame (columns = ['a' , 'b' , 'c' ])
@@ -9970,7 +9980,8 @@ def test_count(self):
99709980 self ._check_stat_op ('count' , f ,
99719981 has_skipna = False ,
99729982 has_numeric_only = True ,
9973- check_dtypes = False )
9983+ check_dtype = False ,
9984+ check_dates = True )
99749985
99759986 # corner case
99769987 frame = DataFrame ()
@@ -9999,10 +10010,9 @@ def test_count(self):
999910010 def test_sum (self ):
1000010011 self ._check_stat_op ('sum' , np .sum , has_numeric_only = True )
1000110012
10002- def test_sum_mixed_numeric (self ):
10003- raise nose .SkipTest ("skipping for now" )
10004- # mixed types
10005- self ._check_stat_op ('sum' , np .sum , frame = self .mixed_float , has_numeric_only = True )
10013+ # mixed types (with upcasting happening)
10014+ self ._check_stat_op ('sum' , np .sum , frame = self .mixed_float .astype ('float32' ),
10015+ has_numeric_only = True , check_dtype = False , check_less_precise = True )
1000610016
1000710017 def test_stat_operators_attempt_obj_array (self ):
1000810018 data = {
@@ -10028,7 +10038,7 @@ def test_stat_operators_attempt_obj_array(self):
1002810038 assert_series_equal (result , expected )
1002910039
1003010040 def test_mean (self ):
10031- self ._check_stat_op ('mean' , np .mean )
10041+ self ._check_stat_op ('mean' , np .mean , check_dates = True )
1003210042
1003310043 def test_product (self ):
1003410044 self ._check_stat_op ('product' , np .prod )
@@ -10039,10 +10049,10 @@ def wrapper(x):
1003910049 return np .nan
1004010050 return np .median (x )
1004110051
10042- self ._check_stat_op ('median' , wrapper )
10052+ self ._check_stat_op ('median' , wrapper , check_dates = True )
1004310053
1004410054 def test_min (self ):
10045- self ._check_stat_op ('min' , np .min )
10055+ self ._check_stat_op ('min' , np .min , check_dates = True )
1004610056 self ._check_stat_op ('min' , np .min , frame = self .intframe )
1004710057
1004810058 def test_cummin (self ):
@@ -10092,7 +10102,7 @@ def test_cummax(self):
1009210102 self .assertEqual (np .shape (cummax_xs ), np .shape (self .tsframe ))
1009310103
1009410104 def test_max (self ):
10095- self ._check_stat_op ('max' , np .max )
10105+ self ._check_stat_op ('max' , np .max , check_dates = True )
1009610106 self ._check_stat_op ('max' , np .max , frame = self .intframe )
1009710107
1009810108 def test_mad (self ):
@@ -10154,7 +10164,8 @@ def alt(x):
1015410164 assert_series_equal (df .kurt (), df .kurt (level = 0 ).xs ('bar' ))
1015510165
1015610166 def _check_stat_op (self , name , alternative , frame = None , has_skipna = True ,
10157- has_numeric_only = False , check_dtypes = True ):
10167+ has_numeric_only = False , check_dtype = True , check_dates = False ,
10168+ check_less_precise = False ):
1015810169 if frame is None :
1015910170 frame = self .frame
1016010171 # set some NAs
@@ -10163,14 +10174,16 @@ def _check_stat_op(self, name, alternative, frame=None, has_skipna=True,
1016310174
1016410175 f = getattr (frame , name )
1016510176
10166- if not ( 'max' in name or 'min' in name or 'count' in name ) :
10177+ if check_dates :
1016710178 df = DataFrame ({'b' : date_range ('1/1/2001' , periods = 2 )})
1016810179 _f = getattr (df , name )
10169- #print(df )
10170- self .assertFalse ( len ( _f () ))
10180+ result = _f ( )
10181+ self .assert_ ( isinstance ( result , Series ))
1017110182
1017210183 df ['a' ] = lrange (len (df ))
10173- self .assert_ (len (getattr (df , name )()))
10184+ result = getattr (df , name )()
10185+ self .assert_ (isinstance (result , Series ))
10186+ self .assert_ (len (result ))
1017410187
1017510188 if has_skipna :
1017610189 def skipna_wrapper (x ):
@@ -10184,21 +10197,27 @@ def wrapper(x):
1018410197
1018510198 result0 = f (axis = 0 , skipna = False )
1018610199 result1 = f (axis = 1 , skipna = False )
10187- assert_series_equal (result0 , frame .apply (wrapper ))
10200+ assert_series_equal (result0 , frame .apply (wrapper ),
10201+ check_dtype = check_dtype ,
10202+ check_less_precise = check_less_precise )
1018810203 assert_series_equal (result1 , frame .apply (wrapper , axis = 1 ),
10189- check_dtype = False ) # HACK: win32
10204+ check_dtype = False ,
10205+ check_less_precise = check_less_precise ) # HACK: win32
1019010206 else :
1019110207 skipna_wrapper = alternative
1019210208 wrapper = alternative
1019310209
1019410210 result0 = f (axis = 0 )
1019510211 result1 = f (axis = 1 )
10196- assert_series_equal (result0 , frame .apply (skipna_wrapper ))
10212+ assert_series_equal (result0 , frame .apply (skipna_wrapper ),
10213+ check_dtype = check_dtype ,
10214+ check_less_precise = check_less_precise )
1019710215 assert_series_equal (result1 , frame .apply (skipna_wrapper , axis = 1 ),
10198- check_dtype = False )
10216+ check_dtype = False ,
10217+ check_less_precise = check_less_precise )
1019910218
1020010219 # check dtypes
10201- if check_dtypes :
10220+ if check_dtype :
1020210221 lcd_dtype = frame .values .dtype
1020310222 self .assert_ (lcd_dtype == result0 .dtype )
1020410223 self .assert_ (lcd_dtype == result1 .dtype )
@@ -10331,7 +10350,8 @@ def wrapper(x):
1033110350 return np .nan
1033210351 return np .median (x )
1033310352
10334- self ._check_stat_op ('median' , wrapper , frame = self .intframe , check_dtypes = False )
10353+ self ._check_stat_op ('median' , wrapper , frame = self .intframe ,
10354+ check_dtype = False , check_dates = True )
1033510355
1033610356 def test_quantile (self ):
1033710357 from pandas .compat .scipy import scoreatpercentile
0 commit comments