Repository: pandas-dev/pandas

Issue:
ENH: option setting syntax enhancements
https://github.com/pydata/pandas/pull/3663

maybe allow these:

`pd.set_option(pat,val,pat,val`



Discussion:

Resolving patch:
diff --git a/pandas/core/config.py b/pandas/core/config.py
--- a/pandas/core/config.py
+++ b/pandas/core/config.py
@@ -94,7 +94,7 @@ def _get_option(pat, silent=False):
     return root[k]
 
 
-def _set_option(pat, value, silent=False):
+def _set_single_option(pat, value, silent):
     key = _get_single_key(pat, silent)
 
     o = _get_registered_option(key)
@@ -109,6 +109,40 @@ def _set_option(pat, value, silent=False):
         o.cb(key)
 
 
+def _set_multiple_options(args, silent):
+    for k, v in zip(args[::2], args[1::2]):
+        _set_single_option(k, v, silent)
+
+
+def _set_option(*args, **kwargs):
+    # must at least 1 arg deal with constraints later
+    nargs = len(args)
+    if not nargs or nargs % 2 != 0:
+        raise AssertionError("Must provide an even number of non-keyword "
+                             "arguments")
+
+    # must be 0 or 1 kwargs
+    nkwargs = len(kwargs)
+    if nkwargs not in (0, 1):
+        raise AssertionError("The can only be 0 or 1 keyword arguments")
+
+    # if 1 kwarg then it must be silent=True or silent=False
+    if nkwargs:
+        k, = kwargs.keys()
+        v, = kwargs.values()
+
+        if k != 'silent':
+            raise ValueError("the only allowed keyword argument is 'silent', "
+                             "you passed '{0}'".format(k))
+        if not isinstance(v, bool):
+            raise TypeError("the type of the keyword argument passed must be "
+                            "bool, you passed a {0}".format(v.__class__))
+
+    # default to false
+    silent = kwargs.get('silent', False)
+    _set_multiple_options(args, silent)
+
+
 def _describe_option(pat='', _print_desc=True):
 
     keys = _select_options(pat)
@@ -186,7 +220,7 @@ def __dir__(self):
 # of options, and option descriptions.
 
 
-class CallableDyanmicDoc(object):
+class CallableDynamicDoc(object):
 
     def __init__(self, func, doc_tmpl):
         self.__doc_tmpl__ = doc_tmpl
@@ -301,10 +335,10 @@ def __doc__(self):
 
 # bind the functions with their docstrings into a Callable
 # and use that as the functions exposed in pd.api
-get_option = CallableDyanmicDoc(_get_option, _get_option_tmpl)
-set_option = CallableDyanmicDoc(_set_option, _set_option_tmpl)
-reset_option = CallableDyanmicDoc(_reset_option, _reset_option_tmpl)
-describe_option = CallableDyanmicDoc(_describe_option, _describe_option_tmpl)
+get_option = CallableDynamicDoc(_get_option, _get_option_tmpl)
+set_option = CallableDynamicDoc(_set_option, _set_option_tmpl)
+reset_option = CallableDynamicDoc(_reset_option, _reset_option_tmpl)
+describe_option = CallableDynamicDoc(_describe_option, _describe_option_tmpl)
 options = DictWrapper(_global_config)
 
 ######################################################
@@ -505,13 +539,7 @@ def _get_registered_option(key):
     -------
     RegisteredOption (namedtuple) if key is deprecated, None otherwise
     """
-
-    try:
-        d = _registered_options[key]
-    except KeyError:
-        return None
-    else:
-        return d
+    return _registered_options.get(key)
 
 
 def _translate_key(key):


Test patch:
diff --git a/pandas/tests/test_config.py b/pandas/tests/test_config.py
--- a/pandas/tests/test_config.py
+++ b/pandas/tests/test_config.py
@@ -169,6 +169,44 @@ def test_set_option(self):
 
         self.assertRaises(KeyError, self.cf.set_option, 'no.such.key', None)
 
+
+    def test_set_option_empty_args(self):
+        self.assertRaises(AssertionError, self.cf.set_option)
+
+    def test_set_option_uneven_args(self):
+        self.assertRaises(AssertionError, self.cf.set_option, 'a.b', 2, 'b.c')
+
+
+    def test_set_option_2_kwargs(self):
+        self.assertRaises(AssertionError, self.cf.set_option, 'a.b', 2,
+                          silenadf=2, asdf=2)
+
+    def test_set_option_invalid_kwargs_key(self):
+        self.assertRaises(ValueError, self.cf.set_option, 'a.b', 2,
+                          silenadf=2)
+
+    def test_set_option_invalid_kwargs_value_type(self):
+        self.assertRaises(TypeError, self.cf.set_option, 'a.b', 2,
+                          silent=2)
+
+    def test_set_option_invalid_single_argument_type(self):
+        self.assertRaises(AssertionError, self.cf.set_option, 2)
+
+    def test_set_option_multiple(self):
+        self.cf.register_option('a', 1, 'doc')
+        self.cf.register_option('b.c', 'hullo', 'doc2')
+        self.cf.register_option('b.b', None, 'doc2')
+
+        self.assertEqual(self.cf.get_option('a'), 1)
+        self.assertEqual(self.cf.get_option('b.c'), 'hullo')
+        self.assertTrue(self.cf.get_option('b.b') is None)
+
+        self.cf.set_option('a', '2', 'b.c', None, 'b.b', 10.0)
+
+        self.assertEqual(self.cf.get_option('a'), '2')
+        self.assertTrue(self.cf.get_option('b.c') is None)
+        self.assertEqual(self.cf.get_option('b.b'), 10.0)
+
     def test_validation(self):
         self.cf.register_option('a', 1, 'doc', validator=self.cf.is_int)
         self.cf.register_option('b.c', 'hullo', 'doc2',