Skip to content

Commit ef23df1

Browse files
committed
Merge pull request #10108 from rosnfeld/issue_10087
BUG: categorical doesn't handle display.width of None in Python 3 (GH10087)
2 parents eafd22d + 6728826 commit ef23df1

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

doc/source/whatsnew/v0.17.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,5 @@ Performance Improvements
5757

5858
Bug Fixes
5959
~~~~~~~~~
60+
61+
- Bug in ``Categorical`` repr with ``display.width`` of ``None`` in Python 3 (:issue:`10087`)

pandas/core/categorical.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1310,8 +1310,7 @@ def _repr_categories_info(self):
13101310
levheader = "Categories (%d, %s): " % (len(self.categories),
13111311
self.categories.dtype)
13121312
width, height = get_terminal_size()
1313-
max_width = (width if get_option("display.width") == 0
1314-
else get_option("display.width"))
1313+
max_width = get_option("display.width") or width
13151314
if com.in_ipython_frontend():
13161315
# 0 = no breaks
13171316
max_width = 0

pandas/tests/test_categorical.py

+9
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,15 @@ def test_empty_print(self):
521521
expected = ("[], Categories (0, object): []")
522522
self.assertEqual(expected, repr(factor))
523523

524+
def test_print_none_width(self):
525+
# GH10087
526+
a = pd.Series(pd.Categorical([1,2,3,4], name="a"))
527+
exp = u("0 1\n1 2\n2 3\n3 4\n" +
528+
"Name: a, dtype: category\nCategories (4, int64): [1, 2, 3, 4]")
529+
530+
with option_context("display.width", None):
531+
self.assertEqual(exp, repr(a))
532+
524533
def test_periodindex(self):
525534
idx1 = PeriodIndex(['2014-01', '2014-01', '2014-02', '2014-02',
526535
'2014-03', '2014-03'], freq='M')

0 commit comments

Comments
 (0)