Skip to content

Support Resampling Weeks to/from FY5253Quarter #12377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
cancan101 opened this issue Feb 18, 2016 · 1 comment
Open

Support Resampling Weeks to/from FY5253Quarter #12377

cancan101 opened this issue Feb 18, 2016 · 1 comment
Labels
Bug Frequency DateOffsets Period Period data type Resample resample method

Comments

@cancan101
Copy link
Contributor

52–53-week fiscal year are designed to end on the same day of the week each quarter / year. Therefore it should be possible to upsample / downsample to/from weeks. I made an initial attempt at this in #5148 but that PR was never merged. This logic still makes sense.

/CC @fdion

Currently attempts to do so yield:

import pandas as pd
from pandas.tseries.offsets import FY5253Quarter, Week, WeekDay
from pandas.tseries.period import Period, PeriodIndex, period_range
from datetime import datetime

offset_fyq = FY5253Quarter(weekday=WeekDay.SAT, startingMonth=12,
                       variation="last", qtr_with_extra_week=4)
freq_week = Week(weekday=WeekDay.SAT)

prange = period_range(datetime(2013, 1, 5),
                               periods=2 * 13,
                               freq=freq_week)

df = pd.DataFrame({"A": [1] * 13 + [2] * 13}, index=prange)
resampled = df.resample(offset_fyq, fill_method="mean")
ValueError                                Traceback (most recent call last)
<ipython-input-8-38fa44432b0b> in <module>()
     13 
     14 df = pd.DataFrame({"A": [1] * 13 + [2] * 13}, index=prange)
---> 15 resampled = df.resample(offset_fyq, fill_method="mean")

/Users/alex/.virtualenvs/work/lib/python2.7/site-packages/pandas/core/generic.pyc in resample(self, rule, how, axis, fill_method, closed, label, convention, kind, loffset, limit, base)
   3641                               fill_method=fill_method, convention=convention,
   3642                               limit=limit, base=base)
-> 3643         return sampler.resample(self).__finalize__(self)
   3644 
   3645     def first(self, offset):

/Users/alex/.virtualenvs/work/lib/python2.7/site-packages/pandas/tseries/resample.pyc in resample(self, obj)
     90 
     91             if self.kind is None or self.kind == 'period':
---> 92                 rs = self._resample_periods()
     93             else:
     94                 obj = self.obj.to_timestamp(how=self.convention)

/Users/alex/.virtualenvs/work/lib/python2.7/site-packages/pandas/tseries/resample.pyc in _resample_periods(self)
    340             return obj.reindex(new_index)
    341         else:
--> 342             start = axlabels[0].asfreq(self.freq, how=self.convention)
    343             end = axlabels[-1].asfreq(self.freq, how='end')
    344 

pandas/src/period.pyx in pandas._period.Period.asfreq (pandas/src/period.c:14801)()

/Users/alex/.virtualenvs/work/lib/python2.7/site-packages/pandas/tseries/frequencies.pyc in get_freq_code(freqstr)
    253             # e.g., freqstr = ('T', 5)
    254             try:
--> 255                 code = _period_str_to_code(freqstr[0])
    256                 stride = freqstr[1]
    257             except:

/Users/alex/.virtualenvs/work/lib/python2.7/site-packages/pandas/tseries/frequencies.pyc in _period_str_to_code(freqstr)
    809                           FutureWarning, stacklevel=3)
    810         except KeyError:
--> 811             raise ValueError("Unknown freqstr: %s" % freqstr)
    812 
    813         return _period_code_map[alias]

ValueError: Unknown freqstr: REQ-L-DEC-SAT-4

Also should be able to downsample to Day and upsample to FY5254

@jreback
Copy link
Contributor

jreback commented Feb 18, 2016

well you need to provide a parse these strings and convert them to proper offsets. That is the first step. Certainly would take a PR on that limited issue. Best to fix things like this in stages and not in big PR's.

@jreback jreback added this to the Next Major Release milestone Feb 18, 2016
@mroeschke mroeschke added the Resample resample method label Jun 28, 2020
@mroeschke mroeschke added the Period Period data type label Apr 23, 2021
@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Frequency DateOffsets Period Period data type Resample resample method
Projects
None yet
Development

No branches or pull requests

4 participants