@@ -9035,6 +9035,16 @@ def test_apply_mixed_dtype_corner(self):
9035
9035
expected = Series (np .nan , index = [])
9036
9036
assert_series_equal (result , expected )
9037
9037
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
+
9038
9048
def test_apply_empty_infer_type (self ):
9039
9049
no_cols = DataFrame (index = ['a' , 'b' , 'c' ])
9040
9050
no_index = DataFrame (columns = ['a' , 'b' , 'c' ])
@@ -9970,7 +9980,8 @@ def test_count(self):
9970
9980
self ._check_stat_op ('count' , f ,
9971
9981
has_skipna = False ,
9972
9982
has_numeric_only = True ,
9973
- check_dtypes = False )
9983
+ check_dtype = False ,
9984
+ check_dates = True )
9974
9985
9975
9986
# corner case
9976
9987
frame = DataFrame ()
@@ -9999,10 +10010,9 @@ def test_count(self):
9999
10010
def test_sum (self ):
10000
10011
self ._check_stat_op ('sum' , np .sum , has_numeric_only = True )
10001
10012
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 )
10006
10016
10007
10017
def test_stat_operators_attempt_obj_array (self ):
10008
10018
data = {
@@ -10028,7 +10038,7 @@ def test_stat_operators_attempt_obj_array(self):
10028
10038
assert_series_equal (result , expected )
10029
10039
10030
10040
def test_mean (self ):
10031
- self ._check_stat_op ('mean' , np .mean )
10041
+ self ._check_stat_op ('mean' , np .mean , check_dates = True )
10032
10042
10033
10043
def test_product (self ):
10034
10044
self ._check_stat_op ('product' , np .prod )
@@ -10039,10 +10049,10 @@ def wrapper(x):
10039
10049
return np .nan
10040
10050
return np .median (x )
10041
10051
10042
- self ._check_stat_op ('median' , wrapper )
10052
+ self ._check_stat_op ('median' , wrapper , check_dates = True )
10043
10053
10044
10054
def test_min (self ):
10045
- self ._check_stat_op ('min' , np .min )
10055
+ self ._check_stat_op ('min' , np .min , check_dates = True )
10046
10056
self ._check_stat_op ('min' , np .min , frame = self .intframe )
10047
10057
10048
10058
def test_cummin (self ):
@@ -10092,7 +10102,7 @@ def test_cummax(self):
10092
10102
self .assertEqual (np .shape (cummax_xs ), np .shape (self .tsframe ))
10093
10103
10094
10104
def test_max (self ):
10095
- self ._check_stat_op ('max' , np .max )
10105
+ self ._check_stat_op ('max' , np .max , check_dates = True )
10096
10106
self ._check_stat_op ('max' , np .max , frame = self .intframe )
10097
10107
10098
10108
def test_mad (self ):
@@ -10154,7 +10164,8 @@ def alt(x):
10154
10164
assert_series_equal (df .kurt (), df .kurt (level = 0 ).xs ('bar' ))
10155
10165
10156
10166
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 ):
10158
10169
if frame is None :
10159
10170
frame = self .frame
10160
10171
# set some NAs
@@ -10163,14 +10174,16 @@ def _check_stat_op(self, name, alternative, frame=None, has_skipna=True,
10163
10174
10164
10175
f = getattr (frame , name )
10165
10176
10166
- if not ( 'max' in name or 'min' in name or 'count' in name ) :
10177
+ if check_dates :
10167
10178
df = DataFrame ({'b' : date_range ('1/1/2001' , periods = 2 )})
10168
10179
_f = getattr (df , name )
10169
- #print(df )
10170
- self .assertFalse ( len ( _f () ))
10180
+ result = _f ( )
10181
+ self .assert_ ( isinstance ( result , Series ))
10171
10182
10172
10183
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 ))
10174
10187
10175
10188
if has_skipna :
10176
10189
def skipna_wrapper (x ):
@@ -10184,21 +10197,27 @@ def wrapper(x):
10184
10197
10185
10198
result0 = f (axis = 0 , skipna = False )
10186
10199
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 )
10188
10203
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
10190
10206
else :
10191
10207
skipna_wrapper = alternative
10192
10208
wrapper = alternative
10193
10209
10194
10210
result0 = f (axis = 0 )
10195
10211
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 )
10197
10215
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 )
10199
10218
10200
10219
# check dtypes
10201
- if check_dtypes :
10220
+ if check_dtype :
10202
10221
lcd_dtype = frame .values .dtype
10203
10222
self .assert_ (lcd_dtype == result0 .dtype )
10204
10223
self .assert_ (lcd_dtype == result1 .dtype )
@@ -10331,7 +10350,8 @@ def wrapper(x):
10331
10350
return np .nan
10332
10351
return np .median (x )
10333
10352
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 )
10335
10355
10336
10356
def test_quantile (self ):
10337
10357
from pandas .compat .scipy import scoreatpercentile
0 commit comments