Skip to content

API: DatetimeIndex and PeriodIndex string representation #7601

Closed
@sinhrks

Description

@sinhrks

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')

Metadata

Metadata

Assignees

No one assigned

    Labels

    DatetimeDatetime data dtypeOutput-Formatting__repr__ of pandas objects, to_stringPeriodPeriod data type

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions