@@ -3556,22 +3556,14 @@ def resample(self, rule, how=None, axis=0, fill_method=None,
3556
3556
----------
3557
3557
rule : string
3558
3558
the offset string or object representing target conversion
3559
- how : string
3560
- method for down- or re-sampling, default to 'mean' for
3561
- downsampling
3562
3559
axis : int, optional, default 0
3563
- fill_method : string, default None
3564
- fill_method for upsampling
3565
3560
closed : {'right', 'left'}
3566
3561
Which side of bin interval is closed
3567
3562
label : {'right', 'left'}
3568
3563
Which bin edge label to label bucket with
3569
3564
convention : {'start', 'end', 's', 'e'}
3570
- kind : "period"/"timestamp"
3571
3565
loffset : timedelta
3572
3566
Adjust the resampled time labels
3573
- limit : int, default None
3574
- Maximum size gap to when reindexing with fill_method
3575
3567
base : int, default 0
3576
3568
For frequencies that evenly subdivide 1 day, the "origin" of the
3577
3569
aggregated intervals. For example, for '5min' frequency, base could
@@ -3600,7 +3592,7 @@ def resample(self, rule, how=None, axis=0, fill_method=None,
3600
3592
Downsample the series into 3 minute bins and sum the values
3601
3593
of the timestamps falling into a bin.
3602
3594
3603
- >>> series.resample('3T', how=' sum' )
3595
+ >>> series.resample('3T'). sum( )
3604
3596
2000-01-01 00:00:00 3
3605
3597
2000-01-01 00:03:00 12
3606
3598
2000-01-01 00:06:00 21
@@ -3616,7 +3608,7 @@ def resample(self, rule, how=None, axis=0, fill_method=None,
3616
3608
To include this value close the right side of the bin interval as
3617
3609
illustrated in the example below this one.
3618
3610
3619
- >>> series.resample('3T', how='sum', label='right')
3611
+ >>> series.resample('3T', label='right').sum( )
3620
3612
2000-01-01 00:03:00 3
3621
3613
2000-01-01 00:06:00 12
3622
3614
2000-01-01 00:09:00 21
@@ -3625,7 +3617,7 @@ def resample(self, rule, how=None, axis=0, fill_method=None,
3625
3617
Downsample the series into 3 minute bins as above, but close the right
3626
3618
side of the bin interval.
3627
3619
3628
- >>> series.resample('3T', how='sum', label='right', closed='right')
3620
+ >>> series.resample('3T', label='right', closed='right').sum( )
3629
3621
2000-01-01 00:00:00 0
3630
3622
2000-01-01 00:03:00 6
3631
3623
2000-01-01 00:06:00 15
@@ -3634,7 +3626,7 @@ def resample(self, rule, how=None, axis=0, fill_method=None,
3634
3626
3635
3627
Upsample the series into 30 second bins.
3636
3628
3637
- >>> series.resample('30S')[0:5] #select first 5 rows
3629
+ >>> series.resample('30S').upsample() [0:5] #select first 5 rows
3638
3630
2000-01-01 00:00:00 0
3639
3631
2000-01-01 00:00:30 NaN
3640
3632
2000-01-01 00:01:00 1
@@ -3645,7 +3637,7 @@ def resample(self, rule, how=None, axis=0, fill_method=None,
3645
3637
Upsample the series into 30 second bins and fill the ``NaN``
3646
3638
values using the ``pad`` method.
3647
3639
3648
- >>> series.resample('30S', fill_method=' pad' )[0:5]
3640
+ >>> series.resample('30S'). pad( )[0:5]
3649
3641
2000-01-01 00:00:00 0
3650
3642
2000-01-01 00:00:30 0
3651
3643
2000-01-01 00:01:00 1
@@ -3656,34 +3648,62 @@ def resample(self, rule, how=None, axis=0, fill_method=None,
3656
3648
Upsample the series into 30 second bins and fill the
3657
3649
``NaN`` values using the ``bfill`` method.
3658
3650
3659
- >>> series.resample('30S', fill_method=' bfill' )[0:5]
3651
+ >>> series.resample('30S'). bfill( )[0:5]
3660
3652
2000-01-01 00:00:00 0
3661
3653
2000-01-01 00:00:30 1
3662
3654
2000-01-01 00:01:00 1
3663
3655
2000-01-01 00:01:30 2
3664
3656
2000-01-01 00:02:00 2
3665
3657
Freq: 30S, dtype: int64
3666
3658
3667
- Pass a custom function to ``how``.
3659
+ Pass a custom function via ``apply``
3668
3660
3669
3661
>>> def custom_resampler(array_like):
3670
3662
... return np.sum(array_like)+5
3671
3663
3672
- >>> series.resample('3T', how= custom_resampler)
3664
+ >>> series.resample('3T').apply( custom_resampler)
3673
3665
2000-01-01 00:00:00 8
3674
3666
2000-01-01 00:03:00 17
3675
3667
2000-01-01 00:06:00 26
3676
3668
Freq: 3T, dtype: int64
3677
3669
3678
3670
"""
3671
+ from pandas .tseries .resample import resample
3679
3672
3680
- from pandas .tseries .resample import TimeGrouper
3681
3673
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
3687
3707
3688
3708
def first (self , offset ):
3689
3709
"""
0 commit comments