Skip to content

PR: adding a core.config module to hold package-wide configurables #2097

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 5 commits into from Nov 27, 2012
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
from pandas.version import version as __version__
from pandas.info import __doc__

# let init-time option registration happen
import pandas.core.config_init

from pandas.core.api import *
from pandas.sparse.api import *
from pandas.stats.api import *
Expand Down
3 changes: 3 additions & 0 deletions pandas/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@
# legacy
from pandas.core.daterange import DateRange # deprecated
import pandas.core.datetools as datetools

from pandas.core.config import get_option,set_option,reset_option,\
reset_options,describe_options
15 changes: 9 additions & 6 deletions pandas/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

from pandas.util.py3compat import StringIO, BytesIO

from pandas.core.config import get_option

# XXX: HACK for NumPy 1.5.1 to suppress warnings
try:
np.seterr(all='ignore')
Expand Down Expand Up @@ -1113,7 +1115,7 @@ def in_interactive_session():
# 2) If you need to send something to the console, use console_encode().
#
# console_encode() should (hopefully) choose the right encoding for you
# based on the encoding set in fmt.print_config.encoding.
# based on the encoding set in option "print_config.encoding"
#
# 3) if you need to write something out to file, use
# pprint_thing_encoded(encoding).
Expand Down Expand Up @@ -1165,16 +1167,17 @@ def pprint_thing(thing, _nest_lvl=0):
result - unicode object on py2, str on py3. Always Unicode.

"""
from pandas.core.format import print_config

if thing is None:
result = ''
elif (py3compat.PY3 and hasattr(thing,'__next__')) or \
hasattr(thing,'next'):
return unicode(thing)
elif (isinstance(thing, dict) and
_nest_lvl < print_config.pprint_nest_depth):
_nest_lvl < get_option("print_config.pprint_nest_depth")):
result = _pprint_dict(thing, _nest_lvl)
elif _is_sequence(thing) and _nest_lvl < print_config.pprint_nest_depth:
elif _is_sequence(thing) and _nest_lvl < \
get_option("print_config.pprint_nest_depth"):
result = _pprint_seq(thing, _nest_lvl)
else:
# when used internally in the package, everything
Expand Down Expand Up @@ -1202,12 +1205,12 @@ def pprint_thing_encoded(object, encoding='utf-8', errors='replace'):


def console_encode(object):
from pandas.core.format import print_config
"""
this is the sanctioned way to prepare something for
sending *to the console*, it delegates to pprint_thing() to get
a unicode representation of the object relies on the global encoding
set in print_config.encoding. Use this everywhere
where you output to the console.
"""
return pprint_thing_encoded(object, print_config.encoding)
return pprint_thing_encoded(object,
get_option("print_config.encoding"))
Loading