diff --git a/pandas/core/config.py b/pandas/core/config.py index 01664fffb1e27..b88241abeb68f 100644 --- a/pandas/core/config.py +++ b/pandas/core/config.py @@ -53,8 +53,10 @@ import re import warnings -import pandas.compat as compat -from pandas.compat import lmap, map, u +try: + unicode +except NameError: + unicode = str DeprecatedOption = namedtuple('DeprecatedOption', 'key msg rkey removal_ver') RegisteredOption = namedtuple('RegisteredOption', @@ -140,7 +142,7 @@ def _describe_option(pat='', _print_desc=True): if len(keys) == 0: raise OptionError('No such keys(s)') - s = u('') + s = u'' for k in keys: # filter by pat s += _build_option_description(k) @@ -634,7 +636,7 @@ def _build_option_description(k): o = _get_registered_option(k) d = _get_deprecated_option(k) - s = u('{k} ').format(k=k) + s = u'{k} '.format(k=k) if o.doc: s += '\n'.join(o.doc.strip().split('\n')) @@ -642,14 +644,14 @@ def _build_option_description(k): s += 'No description available.' if o: - s += (u('\n [default: {default}] [currently: {current}]') + s += (u'\n [default: {default}] [currently: {current}]' .format(default=o.defval, current=_get_option(k, True))) if d: - s += u('\n (Deprecated') - s += (u(', use `{rkey}` instead.') + s += u'\n (Deprecated' + s += (u', use `{rkey}` instead.' .format(rkey=d.rkey if d.rkey else '')) - s += u(')') + s += u')' s += '\n\n' return s @@ -736,10 +738,11 @@ def inner(key, *args, **kwds): get_option = _get_option register_option = _register_option + +# ----------------------------------------------------------------------- # These factories and methods are handy for use as the validator # arg in register_option - def is_type_factory(_type): """ @@ -777,8 +780,7 @@ def is_instance_factory(_type): """ if isinstance(_type, (tuple, list)): _type = tuple(_type) - from pandas.io.formats.printing import pprint_thing - type_repr = "|".join(map(pprint_thing, _type)) + type_repr = "|".join(map(str, _type)) else: type_repr = "'{typ}'".format(typ=_type) @@ -796,11 +798,11 @@ def is_one_of_factory(legal_values): legal_values = [c for c in legal_values if not callable(c)] def inner(x): - from pandas.io.formats.printing import pprint_thing as pp if x not in legal_values: if not any(c(x) for c in callables): - pp_values = pp("|".join(lmap(pp, legal_values))) + uvals = [str(lval) for lval in legal_values] + pp_values = "|".join(uvals) msg = "Value must be one of {pp_values}" if len(callables): msg += " or a callable" @@ -815,7 +817,7 @@ def inner(x): is_bool = is_type_factory(bool) is_float = is_type_factory(float) is_str = is_type_factory(str) -is_unicode = is_type_factory(compat.text_type) +is_unicode = is_type_factory(unicode) is_text = is_instance_factory((str, bytes)) @@ -835,3 +837,23 @@ def is_callable(obj): if not callable(obj): raise ValueError("Value must be a callable") return True + + +# ----------------------------------------------------------------------- +# Options needed in _libs + +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 config_prefix('display'): + register_option('date_dayfirst', False, pc_date_dayfirst_doc, + validator=is_bool) + register_option('date_yearfirst', False, pc_date_yearfirst_doc, + validator=is_bool) diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index d42a1ab72b156..1dcacfb737503 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -110,16 +110,6 @@ def use_numexpr_cb(key): pandas objects (if it is available). """ -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 -""" - pc_pprint_nest_depth = """ : int Controls the number of nested levels to process when pretty-printing @@ -331,10 +321,6 @@ def table_schema_cb(key): validator=is_text) cf.register_option('notebook_repr_html', True, pc_nb_repr_h_doc, validator=is_bool) - cf.register_option('date_dayfirst', False, pc_date_dayfirst_doc, - validator=is_bool) - cf.register_option('date_yearfirst', False, pc_date_yearfirst_doc, - validator=is_bool) cf.register_option('pprint_nest_depth', 3, pc_pprint_nest_depth, validator=is_int) cf.register_option('multi_sparse', True, pc_multi_sparse_doc,