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

PeriodIndex construction with Series (for year, quarter) give TypeError #7701

Closed
jorisvandenbossche opened this issue Jul 9, 2014 · 2 comments · Fixed by #7712
Closed

PeriodIndex construction with Series (for year, quarter) give TypeError #7701

jorisvandenbossche opened this issue Jul 9, 2014 · 2 comments · Fixed by #7712
Labels
API Design Error Reporting Incorrect or improved errors from pandas Period Period data type
Milestone

Comments

@jorisvandenbossche
Copy link
Member

Example from Wes' book:

In [1]: data = pd.DataFrame({'year':[1959,1959,1959,1959,1960,1960,1960,1960], '
quarter':[1,2,3,4,1,2,3,4]})
In [2]: data
Out[2]:
   quarter  year
0        1  1959
1        2  1959
2        3  1959
3        4  1959
4        1  1960
5        2  1960
6        3  1960
7        4  1960

In [3]: pd.PeriodIndex(year=data.year, quarter=data.quarter)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
...
C:\Anaconda\envs\devel\lib\site-packages\numpy\core\fromnumeric.pyc in repeat(a,
 repeats, axis)
    342     except AttributeError:
    343         return _wrapit(a, 'repeat', repeats, axis)
--> 344     return repeat(repeats, axis)
    345
    346

TypeError: repeat() takes exactly 2 arguments (3 given)

The docstring of PeriodIndex says int or array for the year and quarter keywords, and indeed with arrays it does work:

In [4]: pd.PeriodIndex(year=data.year.values, quarter=data.quarter.values)
Out[4]:
<class 'pandas.tseries.period.PeriodIndex'>
[1959Q1, ..., 1960Q4]
Length: 8, Freq: Q

But it previously also worked for Series (I suppose when it was still a subclass?). So, should we keep the current behaviour or make it also work for Series?
In any case, a very strange error message that should be improved.

@cpcloud
Copy link
Member

cpcloud commented Jul 9, 2014

ah didn't see this nice. @jorisvandenbossche i thought i was working on this chapter?

@jorisvandenbossche
Copy link
Member Author

From which chapter is it? (are you on hipchat?) It's maybe in more chapters

@cpcloud cpcloud self-assigned this Jul 10, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Error Reporting Incorrect or improved errors from pandas Period Period data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants