@@ -144,15 +144,15 @@ def _shallow_copy(self, obj=None, **kwargs):
144
144
kwargs [attr ] = getattr (self , attr )
145
145
return self ._constructor (obj , ** kwargs )
146
146
147
- def _prep_values (self , values = None , kill_inf = True , how = None ):
147
+ def _prep_values (self , values = None , kill_inf = True , how = None , as_float = True ):
148
148
149
149
if values is None :
150
150
values = getattr (self ._selected_obj , 'values' , self ._selected_obj )
151
151
152
152
# coerce dtypes as appropriate
153
153
if com .is_float_dtype (values .dtype ):
154
154
pass
155
- elif com .is_integer_dtype (values .dtype ):
155
+ elif com .is_integer_dtype (values .dtype ) and as_float :
156
156
values = values .astype (float )
157
157
elif com .is_timedelta64_dtype (values .dtype ):
158
158
values = values .view ('i8' ).astype (float )
@@ -198,6 +198,7 @@ def _wrap_results(self, results, blocks, obj):
198
198
results : list of ndarrays
199
199
blocks : list of blocks
200
200
obj : conformed data (may be resampled)
201
+ as_float: bool, cast results to float
201
202
"""
202
203
203
204
final = []
@@ -408,7 +409,7 @@ def _constructor(self):
408
409
return Rolling
409
410
410
411
def _apply (self , func , window = None , center = None , check_minp = None , how = None ,
411
- ** kwargs ):
412
+ as_float = True , ** kwargs ):
412
413
"""
413
414
Rolling statistical measure using supplied function. Designed to be
414
415
used with passed-in Cython array-based functions.
@@ -421,6 +422,8 @@ def _apply(self, func, window=None, center=None, check_minp=None, how=None,
421
422
check_minp : function, default to _use_window
422
423
how : string, default to None (DEPRECATED)
423
424
how to resample
425
+ as_float: bool, default to True
426
+ Cast result to float, otherwise return as original type
424
427
425
428
Returns
426
429
-------
@@ -438,7 +441,7 @@ def _apply(self, func, window=None, center=None, check_minp=None, how=None,
438
441
results = []
439
442
for b in blocks :
440
443
try :
441
- values = self ._prep_values (b .values )
444
+ values = self ._prep_values (b .values , as_float = as_float )
442
445
except TypeError :
443
446
results .append (b .values .copy ())
444
447
continue
@@ -535,25 +538,29 @@ def sum(self, **kwargs):
535
538
Parameters
536
539
----------
537
540
how : string, default 'max' (DEPRECATED)
538
- Method for down- or re-sampling""" )
541
+ Method for down- or re-sampling
542
+ as_float : bool, default True
543
+ Cast to float, otherwise return as original type""" )
539
544
540
- def max (self , how = None , ** kwargs ):
545
+ def max (self , how = None , as_float = True , ** kwargs ):
541
546
if self .freq is not None and how is None :
542
547
how = 'max'
543
- return self ._apply ('roll_max' , how = how , ** kwargs )
548
+ return self ._apply ('roll_max' , how = how , as_float = as_float , ** kwargs )
544
549
545
550
_shared_docs ['min' ] = dedent ("""
546
551
%(name)s minimum
547
552
548
553
Parameters
549
554
----------
550
555
how : string, default 'min' (DEPRECATED)
551
- Method for down- or re-sampling""" )
556
+ Method for down- or re-sampling
557
+ as_float : bool, default True
558
+ Cast to float, otherwise return as original type""" )
552
559
553
- def min (self , how = None , ** kwargs ):
560
+ def min (self , how = None , as_float = True , ** kwargs ):
554
561
if self .freq is not None and how is None :
555
562
how = 'min'
556
- return self ._apply ('roll_min' , how = how , ** kwargs )
563
+ return self ._apply ('roll_min' , how = how , as_float = as_float , ** kwargs )
557
564
558
565
def mean (self , ** kwargs ):
559
566
return self ._apply ('roll_mean' , ** kwargs )
0 commit comments