Skip to content

Commit 3f6e316

Browse files
committed
Merge remote branch 'y-p/config_module'
* y-p/config_module: TST: Add tests/test_config.py for new core.config module ENH: Migrate print_config usage to use core.config, register options on pkg load ENH: Add new core.config API functions to the pandas top level module ENH: Add core.config module for managing package-wide configurables ENH: Make `pprint_nest_depth` settable via print_setoptions, update docstring.
2 parents a87194b + 5e98eae commit 3f6e316

File tree

12 files changed

+958
-101
lines changed

12 files changed

+958
-101
lines changed

pandas/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
from pandas.version import version as __version__
2323
from pandas.info import __doc__
2424

25+
# let init-time option registration happen
26+
import pandas.core.config_init
27+
2528
from pandas.core.api import *
2629
from pandas.sparse.api import *
2730
from pandas.stats.api import *

pandas/core/api.py

+3
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@
2929
# legacy
3030
from pandas.core.daterange import DateRange # deprecated
3131
import pandas.core.datetools as datetools
32+
33+
from pandas.core.config import get_option,set_option,reset_option,\
34+
reset_options,describe_options

pandas/core/common.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
from pandas.util.py3compat import StringIO, BytesIO
2121

22+
from pandas.core.config import get_option
23+
2224
# XXX: HACK for NumPy 1.5.1 to suppress warnings
2325
try:
2426
np.seterr(all='ignore')
@@ -1113,7 +1115,7 @@ def in_interactive_session():
11131115
# 2) If you need to send something to the console, use console_encode().
11141116
#
11151117
# console_encode() should (hopefully) choose the right encoding for you
1116-
# based on the encoding set in fmt.print_config.encoding.
1118+
# based on the encoding set in option "print_config.encoding"
11171119
#
11181120
# 3) if you need to write something out to file, use
11191121
# pprint_thing_encoded(encoding).
@@ -1165,16 +1167,17 @@ def pprint_thing(thing, _nest_lvl=0):
11651167
result - unicode object on py2, str on py3. Always Unicode.
11661168
11671169
"""
1168-
from pandas.core.format import print_config
1170+
11691171
if thing is None:
11701172
result = ''
11711173
elif (py3compat.PY3 and hasattr(thing,'__next__')) or \
11721174
hasattr(thing,'next'):
11731175
return unicode(thing)
11741176
elif (isinstance(thing, dict) and
1175-
_nest_lvl < print_config.pprint_nest_depth):
1177+
_nest_lvl < get_option("print_config.pprint_nest_depth")):
11761178
result = _pprint_dict(thing, _nest_lvl)
1177-
elif _is_sequence(thing) and _nest_lvl < print_config.pprint_nest_depth:
1179+
elif _is_sequence(thing) and _nest_lvl < \
1180+
get_option("print_config.pprint_nest_depth"):
11781181
result = _pprint_seq(thing, _nest_lvl)
11791182
else:
11801183
# when used internally in the package, everything
@@ -1202,12 +1205,12 @@ def pprint_thing_encoded(object, encoding='utf-8', errors='replace'):
12021205

12031206

12041207
def console_encode(object):
1205-
from pandas.core.format import print_config
12061208
"""
12071209
this is the sanctioned way to prepare something for
12081210
sending *to the console*, it delegates to pprint_thing() to get
12091211
a unicode representation of the object relies on the global encoding
12101212
set in print_config.encoding. Use this everywhere
12111213
where you output to the console.
12121214
"""
1213-
return pprint_thing_encoded(object, print_config.encoding)
1215+
return pprint_thing_encoded(object,
1216+
get_option("print_config.encoding"))

0 commit comments

Comments
 (0)