Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v0.17.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ Performance Improvements

Bug Fixes
~~~~~~~~~

- Bug in ``Categorical`` repr with ``display.width`` of ``None`` in Python 3 (:issue:`10087`)
3 changes: 1 addition & 2 deletions pandas/core/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1310,8 +1310,7 @@ def _repr_categories_info(self):
levheader = "Categories (%d, %s): " % (len(self.categories),
self.categories.dtype)
width, height = get_terminal_size()
max_width = (width if get_option("display.width") == 0
else get_option("display.width"))
max_width = get_option("display.width") or width
if com.in_ipython_frontend():
# 0 = no breaks
max_width = 0
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,15 @@ def test_empty_print(self):
expected = ("[], Categories (0, object): []")
self.assertEqual(expected, repr(factor))

def test_print_none_width(self):
# GH10087
a = pd.Series(pd.Categorical([1,2,3,4], name="a"))
exp = u("0 1\n1 2\n2 3\n3 4\n" +
"Name: a, dtype: category\nCategories (4, int64): [1, 2, 3, 4]")

with option_context("display.width", None):
self.assertEqual(exp, repr(a))

def test_periodindex(self):
idx1 = PeriodIndex(['2014-01', '2014-01', '2014-02', '2014-02',
'2014-03', '2014-03'], freq='M')
Expand Down