ERR: Resample pad on existing freq causes recursion error · Issue #12770 · pandas-dev/pandas (original) (raw)
Not a big bug, but not ideal behavior:
In [26]: series=pd.Series(range(10), pd.period_range(start='2000', periods=10, name='date', freq='M'))
In [25]: series Out[25]: date 2000-01 0 2000-02 1 2000-03 2 2000-04 3 2000-05 4 2000-06 5 2000-07 6 2000-08 7 2000-09 8 2000-10 9 Freq: M, dtype: int64
In [30]: series.resample('M').first()
ValueError Traceback (most recent call last) in () ----> 1 series.resample('M').first()
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/tseries/resample.py in f(self, _method) 465 466 def f(self, _method=method): --> 467 return self._downsample(_method) 468 f.doc = getattr(GroupBy, method).doc 469 setattr(Resampler, method, f)
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/tseries/resample.py in _downsample(self, how, **kwargs) 709 'resampled to {freq}'.format( 710 axfreq=ax.freq, --> 711 freq=self.freq)) 712 713 def _upsample(self, method, limit=None):
ValueError: Frequency cannot be resampled to
--> which is fair, even if I could imagine it returning itself
In [31]: series.resample('M').pad()
RecursionError Traceback (most recent call last) in () ----> 1 series.resample('M').pad()
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/tseries/resample.py in pad(self, limit) 393 DataFrame.fillna 394 """ --> 395 return self._upsample('pad', limit=limit) 396 ffill = pad 397
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/tseries/resample.py in _upsample(self, method, limit) 736 737 if not is_superperiod(ax.freq, self.freq): --> 738 return self.asfreq() 739 740 # Start vs. end of period
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/tseries/resample.py in asfreq(self) 435 essentially a reindex with (no filling) 436 """ --> 437 return self._upsample(None) 438 439 def std(self, ddof=1):
...............
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/tseries/period.py in _generate_range(cls, start, end, periods, freq, fields) 200 raise ValueError('Can either instantiate from fields ' 201 'or endpoints, but not both') --> 202 subarr, freq = _get_ordinal_range(start, end, periods, freq) 203 elif field_count > 0: 204 subarr, freq = _range_from_fields(freq=freq, **fields)
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/tseries/period.py in _get_ordinal_range(start, end, periods, freq, mult) 995 996 if start is not None: --> 997 start = Period(start, freq) 998 if end is not None: 999 end = Period(end, freq)
pandas/src/period.pyx in pandas._period.Period.init (pandas/src/period.c:10867)()
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/importlib/_bootstrap.py in find_and_load(name, import)
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/importlib/_bootstrap.py in enter(self)
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/importlib/_bootstrap.py in _get_module_lock(name)
RecursionError: maximum recursion depth exceeded
Expected Output
Raise on the initial resample? Return itself? Deliberately raise on pad
?
output of pd.show_versions()
18.0