Skip to content

Commit 4794cfc

Browse files
committed
Added example to set_option description
1 parent b32c46a commit 4794cfc

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

pandas/_config/config.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ def set_option(*args) -> None:
200200
Parameters
201201
----------
202202
*args : str | object | dict
203-
Arguments provided in pairs, which will be interpreted as (pattern, value)
204-
pairs, or as a single dictionary containing multiple option-value pairs.
203+
Arguments provided in a pair, which will be interpreted as (pattern, value),
204+
or as a single dictionary containing multiple option-value pairs.
205205
pattern: str
206206
Regexp which should match a single option
207207
value: object
@@ -239,6 +239,8 @@ def set_option(*args) -> None:
239239
240240
Examples
241241
--------
242+
Option-Value Pair Input:
243+
242244
>>> pd.set_option("display.max_columns", 4)
243245
>>> df = pd.DataFrame([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
244246
>>> df
@@ -247,6 +249,18 @@ def set_option(*args) -> None:
247249
1 6 7 ... 9 10
248250
[2 rows x 5 columns]
249251
>>> pd.reset_option("display.max_columns")
252+
253+
Dictionary Input:
254+
255+
>>> pd.set_option({"display.max_columns": 4, "display.precision", 1})
256+
>>> df = pd.DataFrame([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
257+
>>> df
258+
0 1 ... 3 4
259+
0 1 2 ... 4 5
260+
1 6 7 ... 9 10
261+
[2 rows x 5 columns]
262+
>>> pd.reset_option("display.max_columns")
263+
>>> pd.reset_option("display.precision")
250264
"""
251265
# Handle dictionary input
252266
if len(args) == 1 and isinstance(args[0], dict):

pandas/tests/config/test_config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ def test_set_option_multiple(self):
189189
assert cf.get_option("b.c") == "hullo"
190190
assert cf.get_option("b.b") is None
191191

192-
# Expect the deprecation warning
193192
with tm.assert_produces_warning(
194193
FutureWarning,
195194
match="Setting multiple options using multiple arguments is deprecated",
@@ -201,6 +200,8 @@ def test_set_option_multiple(self):
201200
assert cf.get_option("b.b") == 10.0
202201

203202
def test_set_option_dict(self):
203+
# GH 61093
204+
204205
cf.register_option("a", 1, "doc")
205206
cf.register_option("b.c", "hullo", "doc2")
206207
cf.register_option("b.b", None, "doc2")

0 commit comments

Comments
 (0)