Repository: pandas-dev/pandas

Issue:
BUG: categorical doesn't handle display.width of None in Python 3 
Categorical Series have a special repr that looks at display.width, which can be None if following the Options and Settings docs. Unlike Python 2, in Python 3 an integer vs None comparison throws an exception.

(on current master, and has been true for several releases now)

``` python
Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
>>> pd.core.config.set_option('display.width', None)
>>> import numpy as np
>>> x = pd.Series(np.random.randn(100))
>>> pd.cut(x, 10)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/andrew/git/pandas-rosnfeld-py3/pandas/core/base.py", line 67, in __repr__
    return str(self)
  File "/home/andrew/git/pandas-rosnfeld-py3/pandas/core/base.py", line 46, in __str__
    return self.__unicode__()
  File "/home/andrew/git/pandas-rosnfeld-py3/pandas/core/series.py", line 897, in __unicode__
    max_rows=max_rows)
  File "/home/andrew/git/pandas-rosnfeld-py3/pandas/core/series.py", line 962, in to_string
    name=name, max_rows=max_rows)
  File "/home/andrew/git/pandas-rosnfeld-py3/pandas/core/series.py", line 992, in _get_repr
    result = formatter.to_string()
  File "/home/andrew/git/pandas-rosnfeld-py3/pandas/core/format.py", line 222, in to_string
    footer = self._get_footer()
  File "/home/andrew/git/pandas-rosnfeld-py3/pandas/core/format.py", line 196, in _get_footer
    level_info = self.tr_series.values._repr_categories_info()
  File "/home/andrew/git/pandas-rosnfeld-py3/pandas/core/categorical.py", line 1323, in _repr_categories_info
    if max_width != 0 and cur_col_len + sep_len + len(val) > max_width:
TypeError: unorderable types: int() > NoneType()
```



Discussion:
should be a simple fix. PR's are welcome.

Sure, I'll try and get to it soon.


Resolving patch:
diff --git a/pandas/core/categorical.py b/pandas/core/categorical.py
--- a/pandas/core/categorical.py
+++ b/pandas/core/categorical.py
@@ -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


Test patch:
diff --git a/pandas/tests/test_categorical.py b/pandas/tests/test_categorical.py
--- a/pandas/tests/test_categorical.py
+++ b/pandas/tests/test_categorical.py
@@ -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')