-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
[REF] Move remaining locale functions to _config.localization #25861
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
Changes from 4 commits
3478857
c093df1
1bb6dfd
da3d3ed
9ff3b34
e9f5962
a985016
1314b81
f06c21a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
""" | ||
Unopinionated display configuration. | ||
""" | ||
import locale | ||
import sys | ||
|
||
from pandas._config import config as cf | ||
|
||
# ----------------------------------------------------------------------------- | ||
# Global formatting options | ||
_initial_defencoding = None | ||
|
||
|
||
def detect_console_encoding(): | ||
""" | ||
Try to find the most capable encoding supported by the console. | ||
slightly modified from the way IPython handles the same issue. | ||
""" | ||
global _initial_defencoding | ||
|
||
encoding = None | ||
try: | ||
encoding = sys.stdout.encoding or sys.stdin.encoding | ||
except (AttributeError, IOError): | ||
pass | ||
|
||
# try again for something better | ||
if not encoding or 'ascii' in encoding.lower(): | ||
try: | ||
encoding = locale.getpreferredencoding() | ||
except Exception: | ||
pass | ||
|
||
# when all else fails. this will usually be "ascii" | ||
if not encoding or 'ascii' in encoding.lower(): | ||
encoding = sys.getdefaultencoding() | ||
|
||
# GH#3360, 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 | ||
|
||
|
||
pc_encoding_doc = """ | ||
: str/unicode | ||
Defaults to the detected encoding of the console. | ||
Specifies the encoding to be used for strings returned by to_string, | ||
these are generally strings meant to be displayed on the console. | ||
""" | ||
|
||
pc_date_dayfirst_doc = """ | ||
: boolean | ||
When True, prints and parses dates with the day first, eg 20/01/2005 | ||
""" | ||
|
||
pc_date_yearfirst_doc = """ | ||
: boolean | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these are pretty orthogonal right ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Handling dayfirst and yearfirst finishes breaking the reliance of tslibs on core. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right but they shouldn't be in this file. not problem separateing them out, but not here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they're under the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i would put them in another file under _config There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done + green |
||
When True, prints and parses dates with the year first, eg 2005/01/20 | ||
""" | ||
|
||
|
||
with cf.config_prefix('display'): | ||
cf.register_option('encoding', detect_console_encoding(), pc_encoding_doc, | ||
validator=cf.is_text) | ||
|
||
# Needed upstream of `_libs` because these are used in tslibs.parsing | ||
cf.register_option('date_dayfirst', False, pc_date_dayfirst_doc, | ||
validator=cf.is_bool) | ||
cf.register_option('date_yearfirst', False, pc_date_yearfirst_doc, | ||
validator=cf.is_bool) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn’t u check the global first? (if it’s set)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment near the bottom suggests this is kept for debugging purposes related to matplotlib