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

repr for PeriodIndex does not handle <=2 elements well #5372

Closed
cancan101 opened this issue Oct 29, 2013 · 0 comments · Fixed by #5376
Closed

repr for PeriodIndex does not handle <=2 elements well #5372

cancan101 opened this issue Oct 29, 2013 · 0 comments · Fixed by #5376
Labels
Dtype Conversions Unexpected or buggy dtype conversions Output-Formatting __repr__ of pandas objects, to_string
Milestone

Comments

@cancan101
Copy link
Contributor

The repr for PeriodIndex uses ellipses (i.e. ...) for all number of elements. Ellipses should only be used for more than two elements. DatetimeIndex correctly does this:

In [9]: pd.period_range('2013Q1', periods=1, freq="Q")
Out[9]: 
<class 'pandas.tseries.period.PeriodIndex'>
freq: Q-DEC
[2013Q1, ..., 2013Q1]
length: 1

In [11]: pd.period_range('2013Q1', periods=2, freq="Q")
Out[11]: 
<class 'pandas.tseries.period.PeriodIndex'>
freq: Q-DEC
[2013Q1, ..., 2013Q2]
length: 2

In [10]: pd.period_range('2013Q1', periods=3, freq="Q")
Out[10]: 
<class 'pandas.tseries.period.PeriodIndex'>
freq: Q-DEC
[2013Q1, ..., 2013Q3]
length: 3

compare to:

In [16]: pd.date_range('2013-01-01', periods=3, freq="Q")
Out[16]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-03-31 00:00:00, ..., 2013-09-30 00:00:00]
Length: 3, Freq: Q-DEC, Timezone: None

In [13]: pd.date_range('2013-01-01', periods=2, freq="Q")
Out[13]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-03-31 00:00:00, 2013-06-30 00:00:00]
Length: 2, Freq: Q-DEC, Timezone: None

In [14]: pd.date_range('2013-01-01', periods=1, freq="Q")
Out[14]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-03-31 00:00:00]
Length: 1, Freq: Q-DEC, Timezone: None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant