Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/pandas/_config/display.py : 70%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2Unopinionated display configuration.
3"""
4import locale
5import sys
7from pandas._config import config as cf
9# -----------------------------------------------------------------------------
10# Global formatting options
11_initial_defencoding = None
14def detect_console_encoding():
15 """
16 Try to find the most capable encoding supported by the console.
17 slightly modified from the way IPython handles the same issue.
18 """
19 global _initial_defencoding
21 encoding = None
22 try:
23 encoding = sys.stdout.encoding or sys.stdin.encoding
24 except (AttributeError, IOError):
25 pass
27 # try again for something better
28 if not encoding or "ascii" in encoding.lower():
29 try:
30 encoding = locale.getpreferredencoding()
31 except locale.Error:
32 # can be raised by locale.setlocale(), which is
33 # called by getpreferredencoding
34 # (on some systems, see stdlib locale docs)
35 pass
37 # when all else fails. this will usually be "ascii"
38 if not encoding or "ascii" in encoding.lower():
39 encoding = sys.getdefaultencoding()
41 # GH#3360, save the reported defencoding at import time
42 # MPL backends may change it. Make available for debugging.
43 if not _initial_defencoding:
44 _initial_defencoding = sys.getdefaultencoding()
46 return encoding
49pc_encoding_doc = """
50: str/unicode
51 Defaults to the detected encoding of the console.
52 Specifies the encoding to be used for strings returned by to_string,
53 these are generally strings meant to be displayed on the console.
54"""
56with cf.config_prefix("display"):
57 cf.register_option(
58 "encoding", detect_console_encoding(), pc_encoding_doc, validator=cf.is_text
59 )