@@ -3556,22 +3556,14 @@ def resample(self, rule, how=None, axis=0, fill_method=None,
35563556 ----------
35573557 rule : string
35583558 the offset string or object representing target conversion
3559- how : string
3560- method for down- or re-sampling, default to 'mean' for
3561- downsampling
35623559 axis : int, optional, default 0
3563- fill_method : string, default None
3564- fill_method for upsampling
35653560 closed : {'right', 'left'}
35663561 Which side of bin interval is closed
35673562 label : {'right', 'left'}
35683563 Which bin edge label to label bucket with
35693564 convention : {'start', 'end', 's', 'e'}
3570- kind : "period"/"timestamp"
35713565 loffset : timedelta
35723566 Adjust the resampled time labels
3573- limit : int, default None
3574- Maximum size gap to when reindexing with fill_method
35753567 base : int, default 0
35763568 For frequencies that evenly subdivide 1 day, the "origin" of the
35773569 aggregated intervals. For example, for '5min' frequency, base could
@@ -3600,7 +3592,7 @@ def resample(self, rule, how=None, axis=0, fill_method=None,
36003592 Downsample the series into 3 minute bins and sum the values
36013593 of the timestamps falling into a bin.
36023594
3603- >>> series.resample('3T', how=' sum' )
3595+ >>> series.resample('3T'). sum( )
36043596 2000-01-01 00:00:00 3
36053597 2000-01-01 00:03:00 12
36063598 2000-01-01 00:06:00 21
@@ -3616,7 +3608,7 @@ def resample(self, rule, how=None, axis=0, fill_method=None,
36163608 To include this value close the right side of the bin interval as
36173609 illustrated in the example below this one.
36183610
3619- >>> series.resample('3T', how='sum', label='right')
3611+ >>> series.resample('3T', label='right').sum( )
36203612 2000-01-01 00:03:00 3
36213613 2000-01-01 00:06:00 12
36223614 2000-01-01 00:09:00 21
@@ -3625,7 +3617,7 @@ def resample(self, rule, how=None, axis=0, fill_method=None,
36253617 Downsample the series into 3 minute bins as above, but close the right
36263618 side of the bin interval.
36273619
3628- >>> series.resample('3T', how='sum', label='right', closed='right')
3620+ >>> series.resample('3T', label='right', closed='right').sum( )
36293621 2000-01-01 00:00:00 0
36303622 2000-01-01 00:03:00 6
36313623 2000-01-01 00:06:00 15
@@ -3634,7 +3626,7 @@ def resample(self, rule, how=None, axis=0, fill_method=None,
36343626
36353627 Upsample the series into 30 second bins.
36363628
3637- >>> series.resample('30S')[0:5] #select first 5 rows
3629+ >>> series.resample('30S').upsample() [0:5] #select first 5 rows
36383630 2000-01-01 00:00:00 0
36393631 2000-01-01 00:00:30 NaN
36403632 2000-01-01 00:01:00 1
@@ -3645,7 +3637,7 @@ def resample(self, rule, how=None, axis=0, fill_method=None,
36453637 Upsample the series into 30 second bins and fill the ``NaN``
36463638 values using the ``pad`` method.
36473639
3648- >>> series.resample('30S', fill_method=' pad' )[0:5]
3640+ >>> series.resample('30S'). pad( )[0:5]
36493641 2000-01-01 00:00:00 0
36503642 2000-01-01 00:00:30 0
36513643 2000-01-01 00:01:00 1
@@ -3656,34 +3648,62 @@ def resample(self, rule, how=None, axis=0, fill_method=None,
36563648 Upsample the series into 30 second bins and fill the
36573649 ``NaN`` values using the ``bfill`` method.
36583650
3659- >>> series.resample('30S', fill_method=' bfill' )[0:5]
3651+ >>> series.resample('30S'). bfill( )[0:5]
36603652 2000-01-01 00:00:00 0
36613653 2000-01-01 00:00:30 1
36623654 2000-01-01 00:01:00 1
36633655 2000-01-01 00:01:30 2
36643656 2000-01-01 00:02:00 2
36653657 Freq: 30S, dtype: int64
36663658
3667- Pass a custom function to ``how``.
3659+ Pass a custom function via ``apply``
36683660
36693661 >>> def custom_resampler(array_like):
36703662 ... return np.sum(array_like)+5
36713663
3672- >>> series.resample('3T', how= custom_resampler)
3664+ >>> series.resample('3T').apply( custom_resampler)
36733665 2000-01-01 00:00:00 8
36743666 2000-01-01 00:03:00 17
36753667 2000-01-01 00:06:00 26
36763668 Freq: 3T, dtype: int64
36773669
36783670 """
3671+ from pandas .tseries .resample import resample
36793672
3680- from pandas .tseries .resample import TimeGrouper
36813673 axis = self ._get_axis_number (axis )
3682- sampler = TimeGrouper (rule , label = label , closed = closed , how = how ,
3683- axis = axis , kind = kind , loffset = loffset ,
3684- fill_method = fill_method , convention = convention ,
3685- limit = limit , base = base )
3686- return sampler .resample (self ).__finalize__ (self )
3674+ r = resample (self , freq = rule , label = label , closed = closed ,
3675+ axis = axis , kind = kind , loffset = loffset ,
3676+ fill_method = fill_method , convention = convention ,
3677+ limit = limit , base = base )
3678+
3679+ # deprecation warning
3680+ # but call the method anyhow
3681+ if fill_method is not None :
3682+ args = "limit={0}" .format (limit ) if limit is not None else ""
3683+ warnings .warn ("fill_method is deprecated to .resample()\n the new syntax is "
3684+ ".resample(...).{fill_method}({args})" .format (fill_method = fill_method ,
3685+ args = args ),
3686+ FutureWarning , stacklevel = 2 )
3687+ return r .aggregate (fill_method , limit = limit )
3688+
3689+ # deprecation warning
3690+ # but call the method anyhow
3691+ if how is not None :
3692+
3693+ # .resample(..., how='sum')
3694+ if isinstance (how , compat .string_types ):
3695+ method = "{0}()" .format (how )
3696+
3697+ # .resample(..., how=lambda x: ....)
3698+ else :
3699+ method = ".apply(<func>)"
3700+
3701+ warnings .warn ("how in .resample() is deprecated\n the new syntax is "
3702+ ".resample(...).{method}" .format (method = method ),
3703+ FutureWarning , stacklevel = 2 )
3704+ return r .aggregate (how )
3705+
3706+ return r
36873707
36883708 def first (self , offset ):
36893709 """
0 commit comments