-
-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3478857
implement _config.display, move remaning locale utilities; update tests
jbrockmendel c093df1
update imports
jbrockmendel 1bb6dfd
flake8 fixup
jbrockmendel da3d3ed
flake8 fixup
jbrockmendel 9ff3b34
Merge branch 'master' of https://github.com/pandas-dev/pandas into up…
jbrockmendel e9f5962
implement dates.py, isort fixups
jbrockmendel a985016
Merge branch 'master' of https://github.com/pandas-dev/pandas into up…
jbrockmendel 1314b81
move misplaced file
jbrockmendel f06c21a
isort fixup
jbrockmendel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
""" | ||
pandas._config is considered explicitly upstream of everything else in pandas, | ||
should have no intra-pandas dependencies. | ||
|
||
importing `dates` and `display` ensures that keys needed by _libs | ||
are initialized. | ||
""" | ||
__all__ = ["config", "get_option", "set_option", "reset_option", | ||
"describe_option", "option_context", "options"] | ||
__all__ = ["config", "detect_console_encoding", "get_option", "set_option", | ||
"reset_option", "describe_option", "option_context", "options"] | ||
from pandas._config import config | ||
from pandas._config import dates # noqa:F401 | ||
from pandas._config.config import ( | ||
describe_option, get_option, option_context, options, reset_option, | ||
set_option) | ||
from pandas._config.display import detect_console_encoding |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
""" | ||
config for datetime formatting | ||
""" | ||
from pandas._config import config as cf | ||
|
||
pc_date_dayfirst_doc = """ | ||
: boolean | ||
When True, prints and parses dates with the day first, eg 20/01/2005 | ||
""" | ||
|
||
pc_date_yearfirst_doc = """ | ||
: boolean | ||
When True, prints and parses dates with the year first, eg 2005/01/20 | ||
""" | ||
|
||
with cf.config_prefix('display'): | ||
# 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
""" | ||
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. | ||
""" | ||
|
||
with cf.config_prefix('display'): | ||
cf.register_option('encoding', detect_console_encoding(), pc_encoding_doc, | ||
validator=cf.is_text) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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