BUG: resample fixes · pandas-dev/pandas@14cf67f (original) (raw)
`@@ -102,7 +102,7 @@ def _typ(self):
`
102
102
`def _deprecated(self):
`
103
103
`warnings.warn(".resample() is now a deferred operation\n"
`
104
104
`"use .resample(...).mean() instead of .resample(...)",
`
105
``
`-
FutureWarning, stacklevel=2)
`
``
105
`+
FutureWarning, stacklevel=3)
`
106
106
`return self.mean()
`
107
107
``
108
108
`def _make_deprecated_binop(op):
`
`@@ -154,9 +154,7 @@ def getattr(self, attr):
`
154
154
`if attr in self._deprecated_invalids:
`
155
155
`raise ValueError(".resample() is now a deferred operation\n"
`
156
156
`"\tuse .resample(...).mean() instead of "
`
157
``
`-
".resample(...)\n"
`
158
``
`-
"\tassignment will have no effect as you "
`
159
``
`-
"are working on a copy")
`
``
157
`+
".resample(...)")
`
160
158
`if attr not in self._deprecated_valids:
`
161
159
`self = self._deprecated()
`
162
160
`return object.getattribute(self, attr)
`
`@@ -167,6 +165,17 @@ def setattr(self, attr, value):
`
167
165
`self.class.name))
`
168
166
`object.setattr(self, attr, value)
`
169
167
``
``
168
`+
def getitem(self, key):
`
``
169
`+
try:
`
``
170
`+
return super(Resampler, self).getitem(key)
`
``
171
`+
except (KeyError, com.AbstractMethodError):
`
``
172
+
``
173
`+
compat for deprecated
`
``
174
`+
if isinstance(self.obj, com.ABCSeries):
`
``
175
`+
return self._deprecated()[key]
`
``
176
+
``
177
`+
raise
`
``
178
+
170
179
`def setitem(self, attr, value):
`
171
180
`raise ValueError("cannot set items on {0}".format(
`
172
181
`self.class.name))
`
`@@ -208,6 +217,11 @@ def _assure_grouper(self):
`
208
217
`""" make sure that we are creating our binner & grouper """
`
209
218
`self._set_binner()
`
210
219
``
``
220
`+
def plot(self, *args, **kwargs):
`
``
221
`+
for compat with prior versions, we want to
`
``
222
`+
have the warnings shown here and just have this work
`
``
223
`+
return self._deprecated().plot(*args, **kwargs)
`
``
224
+
211
225
`def aggregate(self, arg, *args, **kwargs):
`
212
226
`"""
`
213
227
` Apply aggregation function or functions to resampled groups, yielding
`
`@@ -468,6 +482,52 @@ def f(self, _method=method):
`
468
482
`setattr(Resampler, method, f)
`
469
483
``
470
484
``
``
485
`+
def _maybe_process_deprecations(r, how=None, fill_method=None, limit=None):
`
``
486
`+
""" potentially we might have a deprecation warning, show it
`
``
487
`+
but call the appropriate methods anyhow """
`
``
488
+
``
489
`+
if how is not None:
`
``
490
+
``
491
`+
.resample(..., how='sum')
`
``
492
`+
if isinstance(how, compat.string_types):
`
``
493
`+
method = "{0}()".format(how)
`
``
494
+
``
495
`+
.resample(..., how=lambda x: ....)
`
``
496
`+
else:
`
``
497
`+
method = ".apply()"
`
``
498
+
``
499
`+
if we have both a how and fill_method, then show
`
``
500
`+
the following warning
`
``
501
`+
if fill_method is None:
`
``
502
`+
warnings.warn("how in .resample() is deprecated\n"
`
``
503
`+
"the new syntax is "
`
``
504
`+
".resample(...).{method}".format(
`
``
505
`+
method=method),
`
``
506
`+
FutureWarning, stacklevel=3)
`
``
507
`+
r = r.aggregate(how)
`
``
508
+
``
509
`+
if fill_method is not None:
`
``
510
+
``
511
`+
show the prior function call
`
``
512
`+
method = '.' + method if how is not None else ''
`
``
513
+
``
514
`+
args = "limit={0}".format(limit) if limit is not None else ""
`
``
515
`+
warnings.warn("fill_method is deprecated to .resample()\n"
`
``
516
`+
"the new syntax is .resample(...){method}"
`
``
517
`+
".{fill_method}({args})".format(
`
``
518
`+
method=method,
`
``
519
`+
fill_method=fill_method,
`
``
520
`+
args=args),
`
``
521
`+
FutureWarning, stacklevel=3)
`
``
522
+
``
523
`+
if how is not None:
`
``
524
`+
r = getattr(r, fill_method)(limit=limit)
`
``
525
`+
else:
`
``
526
`+
r = r.aggregate(fill_method, limit=limit)
`
``
527
+
``
528
`+
return r
`
``
529
+
``
530
+
471
531
`class DatetimeIndexResampler(Resampler):
`
472
532
``
473
533
`def _get_binner_for_time(self):
`