Skip to content

ERR: Resample pad on existing freq causes recursion error #12770

Closed
@max-sixty

Description

@max-sixty

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)
<ipython-input-30-4637af8f5d6f> in <module>()
----> 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 <MonthEnd> cannot be resampled to <MonthEnd>

# --> which is fair, even if I could imagine it returning itself

In [31]: series.resample('M').pad()

---------------------------------------------------------------------------
RecursionError                            Traceback (most recent call last)
<ipython-input-24-9df8c7209780> in <module>()
----> 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions