From 439316f5d089bbf618e4269a5799805448cdc105 Mon Sep 17 00:00:00 2001 From: y-p Date: Sun, 21 Apr 2013 10:01:55 +0300 Subject: [PATCH 1/2] BUG: don't rely on sys.getdefaultencoding if we don't need to GH3360 --- pandas/core/format.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/core/format.py b/pandas/core/format.py index 1b362fb5c0562..83d7a0361c0ee 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 From 44a400dc95a08264244f99e203513e84110d979f Mon Sep 17 00:00:00 2001 From: y-p Date: Sun, 21 Apr 2013 10:20:54 +0300 Subject: [PATCH 2/2] ENH: save initial sys.getdefaultencoding() value aside for debugging --- pandas/core/format.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pandas/core/format.py b/pandas/core/format.py index 83d7a0361c0ee..fbab7472ba10b 100644 --- a/pandas/core/format.py +++ b/pandas/core/format.py @@ -1641,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: @@ -1664,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