[Pandas-dev] Upcoming Index repr changes

Joris Van den Bossche jorisvandenbossche at gmail.com
Fri Apr 17 06:07:41 EDT 2015


Hi all,

We have a PR pending to unify the string representation of the different
Index objects: https://github.com/pydata/pandas/pull/9901

What are the most important changes:

   - We propose to reduce the default number of values shown from 100 to 10
   (an option controllable as pd.options.display.max_seq_items).
   - The datetime-like indices (DatetimeIndex, TimedeltaIndex, PeriodIndex)
   were always somewhat different and get a new repr that is now more
   consistent with how it is for other Index types like Int64Index. This is
   the biggest change.

So for eg Int64Index not much changes (only 'name' is now also shown, and
the number of shown values has changed), but for DatetimeIndex the change
is larger.

*But we would like to get some feedback on this!*

Do you like the changes? For DatetimeIndex? For the number of shown values?
Would you want different behaviour for repr() and str()?

Some examples of the changes with the current state of the PR are shown
below:

Previous Behavior

In [1]: pd.get_option('max_seq_items')
Out[1]: 100

In [2]: pd.Index(range(4), name='foo')
Out[2]: Int64Index([0, 1, 2, 3], dtype='int64')

In [3]: pd.Index(range(104), name='foo')
Out[3]: Int64Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72,
73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
92, 93, 94, 95, 96, 97, 98, 99, ...], dtype='int64')

In [4]: pd.date_range('20130101', periods=4, name='foo', tz='US/Eastern')
Out[4]:
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-01-01 00:00:00-05:00, ..., 2013-01-04 00:00:00-05:00]
Length: 4, Freq: D, Timezone: US/Eastern

In [5]: pd.date_range('20130101', periods=104, name='foo', tz='US/Eastern')
Out[5]:
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-01-01 00:00:00-05:00, ..., 2013-04-14 00:00:00-04:00]
Length: 104, Freq: D, Timezone: US/Eastern

New Behavior

In [1]: pd.get_option('max_seq_items')
Out[1]: 10

In [9]: pd.Index(range(4), name='foo')
Out[9]: Int64Index([0, 1, 2, 3], dtype='int64', name=u'foo')

In [10]: pd.Index(range(104), name='foo')
Out[10]: Int64Index([0, 1, ..., 102, 103], dtype='int64', name=u'foo',
length=104)

In [11]: pd.date_range('20130101', periods=4, name='foo', tz='US/Eastern')
Out[11]: DatetimeIndex(['2013-01-01 00:00:00-05:00', '2013-01-02
00:00:00-05:00', '2013-01-03 00:00:00-05:00', '2013-01-04 00:00:00-05:00'],
dtype='datetime64[ns]', name=u'foo', freq='D', tz='US/Eastern')

In [12]: pd.date_range('20130101', periods=104 ,name='foo', tz='US/Eastern')
Out[12]: DatetimeIndex(['2013-01-01 00:00:00-05:00', '2013-01-02
00:00:00-05:00', ..., '2013-04-13 00:00:00-04:00', '2013-04-14
00:00:00-04:00'], dtype='datetime64[ns]', name=u'foo', length=104,
freq='D', tz='US/Eastern')
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pandas-dev/attachments/20150417/81ddb6ff/attachment.html>


More information about the Pandas-dev mailing list