Skip to content

API: DatetimeIndex and PeriodIndex string representation #7601

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

Closed
sinhrks opened this issue Jun 28, 2014 · 1 comment · Fixed by #7602
Closed

API: DatetimeIndex and PeriodIndex string representation #7601

sinhrks opened this issue Jun 28, 2014 · 1 comment · Fixed by #7602
Labels
Datetime Datetime data dtype Output-Formatting __repr__ of pandas objects, to_string Period Period data type
Milestone

Comments

@sinhrks
Copy link
Member

sinhrks commented Jun 28, 2014

DatetimeIndex and PeriodIndex have inconsistent representations. Should PeriodIndex behaves as the same as DatetimeIndex, or DatetimeIndex should have one-liner representation in some methods?

import pandas and pd

# DatetimeIndex ---------------------------------------------------------------
idx = pd.DatetimeIndex(['2011-01-01', '2011-01-02', '2011-01-03'], freq='D')

print(idx)
# <class 'pandas.tseries.index.DatetimeIndex'>
# [2011-01-01, ..., 2011-01-03]
# Length: 3, Freq: D, Timezone: None

idx.__repr__()
# <class 'pandas.tseries.index.DatetimeIndex'>
# [2011-01-01, ..., 2011-01-03]
# Length: 3, Freq: D, Timezone: None

idx.__unicode__()
# <class 'pandas.tseries.index.DatetimeIndex'>
# [2011-01-01, ..., 2011-01-03]
# Length: 3, Freq: D, Timezone: None

idx.__str__()
# <class 'pandas.tseries.index.DatetimeIndex'>
# [2011-01-01, ..., 2011-01-03]
# Length: 3, Freq: D, Timezone: None

idx.__bytes__()
# <class 'pandas.tseries.index.DatetimeIndex'>
# [2011-01-01, ..., 2011-01-03]
# Length: 3, Freq: D, Timezone: None

# PeriodIndex ---------------------------------------------------------------
idx = pd.PeriodIndex(['2011-01-01', '2011-01-02', '2011-01-03'], freq='D')

print(idx)
# PeriodIndex([u'2011-01-01', u'2011-01-02', u'2011-01-03'], freq='D')

idx.__repr__()
# <class 'pandas.tseries.period.PeriodIndex'>
# freq: D
# [2011-01-01, ..., 2011-01-03]
# length: 3

idx.__unicode__()
# PeriodIndex([u'2011-01-01', u'2011-01-02', u'2011-01-03'], freq='D')

idx.__str__()
# PeriodIndex([u'2011-01-01', u'2011-01-02', u'2011-01-03'], freq='D')

idx.__bytes__()
# PeriodIndex([u'2011-01-01', u'2011-01-02', u'2011-01-03'], freq='D')
@jreback
Copy link
Contributor

jreback commented Jun 28, 2014

a PeriodIndex should follow DatetimeIndex format

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Output-Formatting __repr__ of pandas objects, to_string Period Period data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants