Skip to content

BUG: don't rely on sys.getdefaultencoding if we don't need to #3409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
2 commits merged into from Apr 21, 2013
Merged
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
12 changes: 10 additions & 2 deletions pandas/core/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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


Expand Down