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

BUG/API PeriodIndex handles int list/array differently #14048

Closed
sinhrks opened this issue Aug 19, 2016 · 4 comments
Closed

BUG/API PeriodIndex handles int list/array differently #14048

sinhrks opened this issue Aug 19, 2016 · 4 comments
Labels

Comments

@sinhrks
Copy link
Member

sinhrks commented Aug 19, 2016

When we pass a list of numbers, it parsed as date as it is. The same values is regarded as ordinal if it is passed as an array.

Code Sample, a copy-pastable example if possible

raw = [2005, 2007, 2009]

pd.PeriodIndex(raw, freq='A')
# PeriodIndex(['2005', '2007', '2009'], dtype='period[A-DEC]', freq='A-DEC')

pd.PeriodIndex(np.array(raw), freq='A')
# PeriodIndex(['3975', '3977', '3979'], dtype='period[A-DEC]', freq='A-DEC')

Expected Output

Because PeriodIndex has a data and ordinal arg, it should be regarded as:

  • date if it is passed via data kwd
  • ordinal if it is passed via ordinal kwd

output of pd.show_versions()

on current master.

@sinhrks sinhrks added Bug API Design Period Period data type labels Aug 19, 2016
@jreback jreback added this to the Next Major Release milestone Aug 20, 2016
@jreback
Copy link
Contributor

jreback commented Aug 20, 2016

yeah these should be the same. construction of PeriodIndex from integers must be to the codes. Other dtypes can be interpreted (e.g. strings). We could have some flexibility in a to_period method (which can/should be the public interface).

@jreback
Copy link
Contributor

jreback commented Aug 20, 2016

IIRC we discussed this somewhere else, pls link it if you can find it.

@max-sixty
Copy link
Contributor

ref #13277

@TomAugspurger
Copy link
Contributor

This has been fixed somewhere along the way.

In [37]: pd.PeriodIndex(np.array(raw), freq='A')
    ...:
Out[37]: PeriodIndex(['2005', '2007', '2009'], dtype='period[A-DEC]', freq='A-DEC')

I think that things are reasonable well tested, so closing.

@TomAugspurger TomAugspurger modified the milestones: Contributions Welcome, No action Oct 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants