diff --git a/pandas/core/format.py b/pandas/core/format.py index 1b362fb5c0562..fbab7472ba10b 100644 --- a/pandas/core/format.py +++ b/pandas/core/format.py @@ -165,7 +165,9 @@ def _encode_diff_func(): encoding = get_option("display.encoding") def _encode_diff(x): - return len(x) - len(x.decode(encoding)) + if not isinstance(x,unicode): + return len(x) - len(x.decode(encoding)) + return 0 return _encode_diff @@ -1639,13 +1641,14 @@ def reset_printoptions(): FutureWarning) reset_option("^display\.") - +_initial_defencoding = None def detect_console_encoding(): """ Try to find the most capable encoding supported by the console. slighly modified from the way IPython handles the same issue. """ import locale + global _initial_defencoding encoding = None try: @@ -1662,6 +1665,11 @@ def detect_console_encoding(): if not encoding or 'ascii' in encoding.lower(): # when all else fails. this will usually be "ascii" encoding = sys.getdefaultencoding() + # GH3360, save the reported defencoding at import time + # MPL backends may change it. Make available for debugging. + if not _initial_defencoding: + _initial_defencoding = sys.getdefaultencoding() + return encoding