Feature Type
-
[x] Adding new functionality to pandas
-
[ ] Changing existing functionality in pandas
-
[ ] Removing existing functionality in pandas
Problem Description
I wish that I could use dict for pd.set_option
, just like other packages typically accept dict when there are lots of option. Current pandas style follow what old programming language do, such as MATLAB.
Feature Description
import pandas as pd
options = {
'display.precision': 2,
'display.max_columns': 100,
'styler.format.precision': 2,
}
# like this
pd.set_option(**options)
# or like this:
pd.set_option(options)
Alternative Solutions
Current implementations is:
pd.set_option('display.precision', 2)
pd.set_option('display.max_columns', 100)
pd.set_option('styler.format.precision', 2)
# or
options = {
'display.precision': 2,
'display.max_columns': 100,
'styler.format.precision': 2,
}
for key, value in options.items():
pd.set_option(key, value)
Additional Context
Because if I write it like this:
pd.set_option(
'display.precision', 2,
'display.max_columns', 100,
'styler.format.precision', 2,
)
An auto formatter like ruff
will make it into:
pd.set_option(
'display.precision',
2,
'display.max_columns',
100,
'styler.format.precision',
2,
)
Comment From: arthurlw
take
Comment From: himanshumahajan138
working on this
aah i missed it maybe
if i have solution can i propose it @arthurlw
Comment From: arthurlw
Oh sorry @himanshumahajan138 I just saw your message. If you have a solution too we can discuss and compare!
Comment From: yasirroni
Hi @arthurlw and @himanshumahajan138. Thanks for making the PR.
I think https://github.com/pandas-dev/pandas/pull/61152 is cleaner, but has a higher risk of bug (if exist). Also, I don't think we need to support the **
approach as it is not based on args(?).
Comment From: himanshumahajan138
@yasirroni actually i am struggling with the Tight code formatting fixtures 😅
Fixing the failing doc tests and type tests after that we can have discussions on approach suitability
Comment From: rhshadrach
cc @pandas-dev/pandas-core for any thoughts.
Comment From: Dr-Irv
I think it's a good idea to support a dict
as an argument to set_option()
although maybe we should introduce set_options()
to support a dict so there is a difference between setting a single option versus multiple options in a single call?
Comment From: datapythonista
I think it's a good addition, the same time makes things a bit complicated. @Dr-Irv makes the API clearer in my opinion, but I would prefer to not have to add and maintain one more method being almoat identical to the existing.
An idea could be since we are addimg a way to pass multiple options, to allow only one option and remove pd.set_option('s1': 1, 's2': 2)
in favour of pasaing a dictionary instead. Not perfect, but feels like it'll male both the API and the code slightly aimpler.
In any case, I'm ok with any option.
Comment From: himanshumahajan138
Good wishes Members,
Actually my PR consists both approaches first one is only for pd.set_option(options)
and second is for both of the cases pd.set_option(options)
& pd.set_option(**options)
PR : #61152
Comment From: arthurlw
For my PR (#61151), I implemented the first approach only, which is pd.set_options(options)
, where options
is a dictionary.
I think this would be simpler, but I am okay with either option.