-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: Added dict support for pd.set_option
#61151
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
base: main
Are you sure you want to change the base?
Changes from 7 commits
fcdf5bd
36271dd
698fd61
5e2146b
8a720d2
4cd314a
b32c46a
4794cfc
32c58d4
7a560c0
2263ba3
055690e
7167a6b
f120459
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,9 +199,9 @@ def set_option(*args) -> None: | |
|
||
Parameters | ||
---------- | ||
*args : str | object | ||
*args : str | object | dict | ||
Arguments provided in pairs, which will be interpreted as (pattern, value) | ||
pairs. | ||
pairs, or as a single dictionary containing multiple option-value pairs. | ||
pattern: str | ||
Regexp which should match a single option | ||
value: object | ||
|
@@ -248,11 +248,51 @@ def set_option(*args) -> None: | |
[2 rows x 5 columns] | ||
>>> pd.reset_option("display.max_columns") | ||
""" | ||
# must at least 1 arg deal with constraints later | ||
# Handle dictionary input | ||
if len(args) == 1 and isinstance(args[0], dict): | ||
options_dict = args[0] | ||
for k, v in options_dict.items(): | ||
key = _get_single_key(k) | ||
opt = _get_registered_option(key) | ||
if opt and opt.validator: | ||
opt.validator(v) | ||
# walk the nested dict | ||
root, k_root = _get_root(key) | ||
root[k_root] = v | ||
if opt.cb: | ||
opt.cb(key) | ||
return | ||
|
||
# Handle single option-value pair | ||
if len(args) == 2: | ||
key = _get_single_key(args[0]) | ||
v = args[1] | ||
|
||
opt = _get_registered_option(key) | ||
if opt and opt.validator: | ||
opt.validator(v) | ||
|
||
# walk the nested dict | ||
root, k_root = _get_root(key) | ||
root[k_root] = v | ||
|
||
if opt.cb: | ||
opt.cb(key) | ||
return | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this needed? does the next (existing) block not handle a single option-pair correctly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for pointing this out! I overlooked it when adding the dictionary handling. I'll remove it in the next commit. |
||
# Deprecated (# GH 61093): multiple option-value pairs as separate arguments | ||
nargs = len(args) | ||
if not nargs or nargs % 2 != 0: | ||
raise ValueError("Must provide an even number of non-keyword arguments") | ||
|
||
warnings.warn( | ||
"Setting multiple options using multiple arguments is deprecated and will be " | ||
"removed in a future version. Use a dictionary instead.", | ||
FutureWarning, | ||
stacklevel=2, | ||
) | ||
|
||
# Backward compatibility | ||
for k, v in zip(args[::2], args[1::2]): | ||
key = _get_single_key(k) | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.