ENH: PeriodIndex can accept freq with mult by sinhrks · Pull Request #7832 · pandas-dev/pandas (original) (raw)

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

@sinhrks

Closes #7811.

@jreback

@jreback

this is a bit odd though when you operate on these:

you are not propogating the given freq to the actual period?

In [10]: PeriodIndex(start='2014-01', freq='3M', periods=4).tolist()
Out[10]: 
[Period('2014-01', 'M'),
 Period('2014-04', 'M'),
 Period('2014-07', 'M'),
 Period('2014-10', 'M')]

In [11]: (PeriodIndex(start='2014-01', freq='3M', periods=4) + 1).tolist()
Out[11]: 
[Period('2014-02', 'M'),
 Period('2014-05', 'M'),
 Period('2014-08', 'M'),
 Period('2014-11', 'M')]

@jreback

@jreback

@sinhrks can you respond to my comments above?

@jreback

@jreback

@blbradley

@jreback Indeed, the frequency given to PeriodIndex is not propagated to each Period within. Do you think it should be propagated? Your earlier response indicates that you do, but I'm checking in to verify.
This unwanted behavior is also shown using period_range:

In [11]: pd.period_range('2-1-2014 00:00', '2-1-2014 3:00', freq='30Min').tolist()

Out[11]:

[Period('2014-02-01 00:00', 'T'), Period('2014-02-01 00:30', 'T'), Period('2014-02-01 01:00', 'T'), Period('2014-02-01 01:30', 'T'), Period('2014-02-01 02:00', 'T'), Period('2014-02-01 02:30', 'T'), Period('2014-02-01 03:00', 'T')]

@jreback

@blbradley yes that sounds right. When the periods are created during iteration (e.g. the tolist()) then the freq should (and currently is passed).

It should also be true when this PR is implementd.

@blbradley

@jreback Thanks. I started trying to implement that. We'll see how it goes.

@sinhrks

@jreback @blbradley OK. In #7811, I initially thought that created PeriodIndex doesn't need custom freq, but it is more natural. I'll consider the implementation.

@blbradley

Period would greatly benefit from being rewritten in Cython (probably as part of tslib) as to take advantage of convert_to_tsobject.

@jreback

@blbradley this is true. But that's a whole separate project (though not THAT difficult). feel free!

@blbradley

@sinhrks I've been revisiting this. One problem is that Period.asfreq does not handle multiples. I think this could be handled by creating a PeriodIndex the same way as DatetimeIndex in pandas.tseries.resample.asfreq.

@blbradley

@sinhrks I would love to collaborate on this. Please respond soon cause I'm actively working on it.

@jreback

@blbradley

@jreback This year sometime! I did some code spikes towards it before, but they were not fruitful.

@sinhrks

Maybe first change Period to take multiple freqs, then revisit this. I'll look into Period code.

@sinhrks

OK, fixed to raise when freq is not positive, and added some tests. Ready for review once again.

@jorisvandenbossche

Maybe the whatsnew notice can give it a bit more attention? (eg an example).
Further, are there any API changes to note as well? (that freq now returns an Offset object instead of string?)

@max-sixty

I can't spot anything else that would stop this going in.
Not sure if my comment on the docstring is wrong or it just got missed - it still states that you can't provide 5T etc

    e.g., 'B' for businessday. Must be a singular rule-code (e.g. 5T is not
    allowed).

@sinhrks

@jorisvandenbossche Yes, updated whatsnew and timeseries doc.

@MaximilianR I think this has been removed from period.pyx after your suggestion. If I miss other remaining, please point the line.

@max-sixty

@sinhrks you're right - something funky was going on with my extensions - thanks

jreback

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's put this in a separate sub-section

@jreback

@sinhrks lgtm. couple of comments. merge after fix and green.

@sinhrks

@jreback OK, fixed the release note and updated pickle/msgpack.

@jreback

ok, pls rebase then merge

@sinhrks

@sinhrks

Rebased and now green. Merging today (Sep 3) if no further comments.

@jreback

jreback added a commit that referenced this pull request

Sep 3, 2015

@jreback

ENH: PeriodIndex can accept freq with mult

@jreback

thanks @sinhrks awesome effort!

merging as I need to rebase tz on top of this

@sinhrks

Thanks for review and merge:)

Labels