Skip to content

Commit 7bafc4f

Browse files
author
Nick Eubank
committed
conflict resolved
2 parents fc7f9c3 + fe735be commit 7bafc4f

File tree

14 files changed

+385
-216
lines changed

14 files changed

+385
-216
lines changed

doc/source/advanced.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -675,10 +675,7 @@ values NOT in the categories, similarly to how you can reindex ANY pandas index.
675675
}).set_index('B')
676676
677677
In [11]: df3.index
678-
Out[11]:
679-
CategoricalIndex([u'a', u'a', u'b', u'b', u'c', u'a'],
680-
categories=[u'a', u'b', u'c'],
681-
ordered=False)
678+
Out[11]: CategoricalIndex([u'a', u'a', u'b', u'b', u'c', u'a'], categories=[u'a', u'b', u'c'], ordered=False, name=u'B', dtype='category')
682679
683680
In [12]: pd.concat([df2,df3]
684681
TypeError: categories must match existing categories when appending

doc/source/whatsnew/v0.16.1.txt

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ Highlights include:
1313
- New section on how-to-contribute to *pandas*, see :ref:`here <contributing>`
1414
- Revised "Merge, join, and concatenate" documentation, including graphical examples to make it easier to understand each operations, see :ref:`here <merging>`
1515
- New method ``sample`` for drawing random samples from Series, DataFrames and Panels. See :ref:`here <whatsnew_0161.enhancements.sample>`
16-
- ``BusinessHour`` date-offset is now supported, see :ref:`here <timeseries.businesshour>`
16+
- The default ``Index`` printing has changed to a more uniform format, see :ref:`here <whatsnew_0161.index_repr>`
17+
- ``BusinessHour`` datetime-offset is now supported, see :ref:`here <timeseries.businesshour>`
18+
1719
- Further enhancement to the ``.str`` accessor to make string operations easier, see :ref:`here <whatsnew_0161.enhancements.string>`
1820

1921
.. contents:: What's new in v0.16.1
@@ -268,36 +270,51 @@ API changes
268270

269271
- By default, ``read_csv`` and ``read_table`` will now try to infer the compression type based on the file extension. Set ``compression=None`` to restore the previous behavior (no decompression). (:issue:`9770`)
270272

271-
Backwards incompatible API changes
272-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
273-
- default behavior for HDF write functions with "table" format is now to keep rows that are all missing except for index. (:issue:`9382`)
273+
.. _whatsnew_0161.index_repr:
274+
275+
Index Representation
276+
~~~~~~~~~~~~~~~~~~~~
277+
278+
The string representation of ``Index`` and its sub-classes have now been unified. These will show a single-line display if there are few values; a wrapped multi-line display for a lot of values (but less than ``display.max_seq_items``; if lots of items (> ``display.max_seq_items``) will show a truncated display (the head and tail of the data). The formatting for ``MultiIndex`` is unchanges (a multi-line wrapped display). The display width responds to the option ``display.max_seq_items``, which is defaulted to 100. (:issue:`6482`)
274279

275-
Previously,
280+
Previous Behavior
276281

277282
.. code-block:: python
278283

279-
In [1]:
280-
df_with_missing = pd.DataFrame({'col1':[0, np.nan, 2], 'col2':[1, np.nan, 3]})
281-
df_with_missing.to_hdf('file.h5', 'df_with_missing', format = 't')
282-
283-
pd.read_hdf('file.h5', 'df_with_missing')
284-
285-
Out [1]:
286-
col1 col2
287-
0 0 1
288-
2 2 3
284+
In [2]: pd.Index(range(4),name='foo')
285+
Out[2]: Int64Index([0, 1, 2, 3], dtype='int64')
289286

287+
In [3]: pd.Index(range(104),name='foo')
288+
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')
290289

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

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

295-
df_with_missing = pd.DataFrame({'col1':[0, np.nan, 2], 'col2':[1, np.nan, 3]})
296-
df_with_missing.to_hdf('file.h5', 'df_with_missing', format = 't')
297-
298-
pd.read_hdf('file.h5', 'df_with_missing')
302+
New Behavior
299303

304+
.. ipython:: python
300305

306+
pd.set_option('display.width',100)
307+
pd.Index(range(4),name='foo')
308+
pd.Index(range(25),name='foo')
309+
pd.Index(range(104),name='foo')
310+
pd.Index(['datetime', 'sA', 'sB', 'sC', 'flow', 'error', 'temp', 'ref', 'a_bit_a_longer_one']*2)
311+
pd.CategoricalIndex(['a','bb','ccc','dddd'],ordered=True,name='foobar')
312+
pd.CategoricalIndex(['a','bb','ccc','dddd']*10,ordered=True,name='foobar')
313+
pd.CategoricalIndex(['a','bb','ccc','dddd']*100,ordered=True,name='foobar')
314+
pd.CategoricalIndex(np.arange(1000),ordered=True,name='foobar')
315+
pd.date_range('20130101',periods=4,name='foo',tz='US/Eastern')
316+
pd.date_range('20130101',periods=25,name='foo',tz='US/Eastern')
317+
pd.date_range('20130101',periods=104,name='foo',tz='US/Eastern')
301318

302319
.. _whatsnew_0161.deprecations:
303320

@@ -403,3 +420,4 @@ Bug Fixes
403420
- Updated BigQuery connector to no longer use deprecated ``oauth2client.tools.run()`` (:issue:`8327`)
404421
- Bug in subclassed ``DataFrame``. It may not return the correct class, when slicing or subsetting it. (:issue:`9632`)
405422
- Bug in ``.median()`` where non-float null values are not handled correctly (:issue:`10040`)
423+
- Bug in Series.fillna() where it raises if a numerically convertible string is given (:issue:`10092`)

pandas/core/common.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3132,7 +3132,7 @@ def in_ipython_frontend():
31323132
# working with straight ascii.
31333133

31343134

3135-
def _pprint_seq(seq, _nest_lvl=0, **kwds):
3135+
def _pprint_seq(seq, _nest_lvl=0, max_seq_items=None, **kwds):
31363136
"""
31373137
internal. pprinter for iterables. you should probably use pprint_thing()
31383138
rather then calling this directly.
@@ -3144,12 +3144,15 @@ def _pprint_seq(seq, _nest_lvl=0, **kwds):
31443144
else:
31453145
fmt = u("[%s]") if hasattr(seq, '__setitem__') else u("(%s)")
31463146

3147-
nitems = get_option("max_seq_items") or len(seq)
3147+
if max_seq_items is False:
3148+
nitems = len(seq)
3149+
else:
3150+
nitems = max_seq_items or get_option("max_seq_items") or len(seq)
31483151

31493152
s = iter(seq)
31503153
r = []
31513154
for i in range(min(nitems, len(seq))): # handle sets, no slicing
3152-
r.append(pprint_thing(next(s), _nest_lvl + 1, **kwds))
3155+
r.append(pprint_thing(next(s), _nest_lvl + 1, max_seq_items=max_seq_items, **kwds))
31533156
body = ", ".join(r)
31543157

31553158
if nitems < len(seq):
@@ -3160,7 +3163,7 @@ def _pprint_seq(seq, _nest_lvl=0, **kwds):
31603163
return fmt % body
31613164

31623165

3163-
def _pprint_dict(seq, _nest_lvl=0, **kwds):
3166+
def _pprint_dict(seq, _nest_lvl=0, max_seq_items=None, **kwds):
31643167
"""
31653168
internal. pprinter for iterables. you should probably use pprint_thing()
31663169
rather then calling this directly.
@@ -3170,11 +3173,14 @@ def _pprint_dict(seq, _nest_lvl=0, **kwds):
31703173

31713174
pfmt = u("%s: %s")
31723175

3173-
nitems = get_option("max_seq_items") or len(seq)
3176+
if max_seq_items is False:
3177+
nitems = len(seq)
3178+
else:
3179+
nitems = max_seq_items or get_option("max_seq_items") or len(seq)
31743180

31753181
for k, v in list(seq.items())[:nitems]:
3176-
pairs.append(pfmt % (pprint_thing(k, _nest_lvl + 1, **kwds),
3177-
pprint_thing(v, _nest_lvl + 1, **kwds)))
3182+
pairs.append(pfmt % (pprint_thing(k, _nest_lvl + 1, max_seq_items=max_seq_items, **kwds),
3183+
pprint_thing(v, _nest_lvl + 1, max_seq_items=max_seq_items, **kwds)))
31783184

31793185
if nitems < len(seq):
31803186
return fmt % (", ".join(pairs) + ", ...")
@@ -3183,7 +3189,7 @@ def _pprint_dict(seq, _nest_lvl=0, **kwds):
31833189

31843190

31853191
def pprint_thing(thing, _nest_lvl=0, escape_chars=None, default_escapes=False,
3186-
quote_strings=False):
3192+
quote_strings=False, max_seq_items=None):
31873193
"""
31883194
This function is the sanctioned way of converting objects
31893195
to a unicode representation.
@@ -3202,6 +3208,8 @@ def pprint_thing(thing, _nest_lvl=0, escape_chars=None, default_escapes=False,
32023208
replacements
32033209
default_escapes : bool, default False
32043210
Whether the input escape characters replaces or adds to the defaults
3211+
max_seq_items : False, int, default None
3212+
Pass thru to other pretty printers to limit sequence printing
32053213
32063214
Returns
32073215
-------
@@ -3240,11 +3248,11 @@ def as_escaped_unicode(thing, escape_chars=escape_chars):
32403248
return compat.text_type(thing)
32413249
elif (isinstance(thing, dict) and
32423250
_nest_lvl < get_option("display.pprint_nest_depth")):
3243-
result = _pprint_dict(thing, _nest_lvl, quote_strings=True)
3251+
result = _pprint_dict(thing, _nest_lvl, quote_strings=True, max_seq_items=max_seq_items)
32443252
elif is_sequence(thing) and _nest_lvl < \
32453253
get_option("display.pprint_nest_depth"):
32463254
result = _pprint_seq(thing, _nest_lvl, escape_chars=escape_chars,
3247-
quote_strings=quote_strings)
3255+
quote_strings=quote_strings, max_seq_items=max_seq_items)
32483256
elif isinstance(thing, compat.string_types) and quote_strings:
32493257
if compat.PY3:
32503258
fmt = "'%s'"

0 commit comments

Comments
 (0)