Skip to content
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

ENH: Allow period_range to accept freq with mult != 1 #7811

Closed
sinhrks opened this issue Jul 20, 2014 · 1 comment · Fixed by #7832
Closed

ENH: Allow period_range to accept freq with mult != 1 #7811

sinhrks opened this issue Jul 20, 2014 · 1 comment · Fixed by #7832
Labels
Enhancement Frequency DateOffsets Period Period data type
Milestone

Comments

@sinhrks
Copy link
Member

sinhrks commented Jul 20, 2014

date_range can accept freq with mult != 1 and output DatetimeIndex, otherwise period_range raises ValueError.

pd.date_range('2014-01-01 09:00', '2014-01-01 20:00', freq='4H')
# <class 'pandas.tseries.index.DatetimeIndex'>
# [2014-01-01 09:00:00, ..., 2014-01-01 21:00:00]
# Length: 4, Freq: 4H, Timezone: None

pd.date_range('2014-01-01 20:00', '2014-01-01 09:00', freq='-1H')
# <class 'pandas.tseries.index.DatetimeIndex'>
# [2014-01-01 20:00:00, ..., 2014-01-01 09:00:00]
# Length: 12, Freq: -1H, Timezone: None

pd.period_range('2014-01-01 09:00', '2014-01-01 20:00', freq='4H')
# ValueError: Only mult == 1 supported

Is it reasonable to accept period_range and PeriodIndex.__new__ to this kind of freq? What I want to do is creating skipped or reversed ordered PeriodIndex easily.
(Considering internal representation of PeriodIndex, it looks better to result have normal freq, not to add numberized-freq like 4H).

Expected

pd.period_range('2014-01-01 09:00', '2014-01-01 20:00', freq='4H')
# <class 'pandas.tseries.period.PeriodIndex'>
# [2014-01-01 09:00:00, ..., 2014-01-01 21:00:00]
# Length: 4, Freq: H

pd.period_range('2014-01-01 20:00', '2014-01-01 09:00', freq='-1H')
# <class 'pandas.tseries.period.PeriodIndex'>
# [2014-01-01 20:00:00, ..., 2014-01-01 09:00:00]
# Length: 12, Freq: H
@jreback
Copy link
Contributor

jreback commented Jul 21, 2014

I seem to remember an issue looking at this ? can you check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Frequency DateOffsets Period Period data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants