Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/pandas/_config/display.py: 67%
24 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
1"""
2Unopinionated display configuration.
3"""
5from __future__ import annotations
7import locale
8import sys
10from pandas._config import config as cf
12# -----------------------------------------------------------------------------
13# Global formatting options
14_initial_defencoding: str | None = None
17def detect_console_encoding() -> str:
18 """
19 Try to find the most capable encoding supported by the console.
20 slightly modified from the way IPython handles the same issue.
21 """
22 global _initial_defencoding
24 encoding = None
25 try:
26 encoding = sys.stdout.encoding or sys.stdin.encoding
27 except (AttributeError, OSError):
28 pass
30 # try again for something better
31 if not encoding or "ascii" in encoding.lower(): 31 ↛ 32line 31 didn't jump to line 32, because the condition on line 31 was never true
32 try:
33 encoding = locale.getpreferredencoding()
34 except locale.Error:
35 # can be raised by locale.setlocale(), which is
36 # called by getpreferredencoding
37 # (on some systems, see stdlib locale docs)
38 pass
40 # when all else fails. this will usually be "ascii"
41 if not encoding or "ascii" in encoding.lower(): 41 ↛ 42line 41 didn't jump to line 42, because the condition on line 41 was never true
42 encoding = sys.getdefaultencoding()
44 # GH#3360, save the reported defencoding at import time
45 # MPL backends may change it. Make available for debugging.
46 if not _initial_defencoding: 46 ↛ 49line 46 didn't jump to line 49, because the condition on line 46 was never false
47 _initial_defencoding = sys.getdefaultencoding()
49 return encoding
52pc_encoding_doc = """
53: str/unicode
54 Defaults to the detected encoding of the console.
55 Specifies the encoding to be used for strings returned by to_string,
56 these are generally strings meant to be displayed on the console.
57"""
59with cf.config_prefix("display"):
60 cf.register_option(
61 "encoding", detect_console_encoding(), pc_encoding_doc, validator=cf.is_text
62 )