Skip to content

Commit 85ce03c

Browse files
TYP: GH1680 Allow set_option for multiple arguments (#1681)
* GH1680 Allow set_option for multiple arguments * GH1680 Allow set_option for multiple arguments * GH1680 PR Feedback
1 parent 1c2927a commit 85ce03c

2 files changed

Lines changed: 164 additions & 2 deletions

File tree

pandas-stubs/_config/config.pyi

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,56 @@ from typing import (
1212

1313
def get_option(pat: str) -> Any: ...
1414
@overload
15-
def set_option(pat: str, val: object) -> None: ...
16-
@overload
1715
def set_option(*args: dict[str, Any]) -> None: ...
16+
@overload
17+
def set_option(pat0: str, val0: object) -> None: ...
18+
@overload
19+
def set_option(pat0: str, val0: object, pat1: str, val1: object) -> None: ...
20+
@overload
21+
def set_option(
22+
pat0: str, val0: object, pat1: str, val1: object, pat2: str, val2: object
23+
) -> None: ...
24+
@overload
25+
def set_option(
26+
pat0: str,
27+
val0: object,
28+
pat1: str,
29+
val1: object,
30+
pat2: str,
31+
val2: object,
32+
pat3: str,
33+
val3: object,
34+
) -> None: ...
35+
@overload
36+
def set_option(
37+
pat0: str,
38+
val0: object,
39+
pat1: str,
40+
val1: object,
41+
pat2: str,
42+
val2: object,
43+
pat3: str,
44+
val3: object,
45+
pat4: str,
46+
val4: object,
47+
) -> None: ...
48+
@overload
49+
def set_option(
50+
pat0: str,
51+
val0: object,
52+
pat1: str,
53+
val1: object,
54+
pat2: str,
55+
val2: object,
56+
pat3: str,
57+
val3: object,
58+
pat4: str,
59+
val4: object,
60+
pat5: str,
61+
val5: object,
62+
) -> None: ...
63+
@overload
64+
def set_option(*args: Any) -> None: ...
1865
def reset_option(pat: str) -> None: ...
1966
@overload
2067
def describe_option(pat: str, _print_desc: Literal[False]) -> str: ...

tests/test_config.py

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ def test_option_tools() -> None:
2525
check(assert_type(pd.reset_option("display.width"), None), type(None))
2626
check(assert_type(pd.set_option("display.width", 80), None), type(None))
2727
check(assert_type(pd.set_option({"display.width": 80}), None), type(None))
28+
check(
29+
assert_type(
30+
pd.set_option("display.max_columns", 4, "display.precision", 1), None
31+
),
32+
type(None),
33+
)
2834
check(assert_type(pd.describe_option("display.width", False), str), str)
2935
check(assert_type(pd.describe_option("display.width", True), None), type(None))
3036
check(assert_type(pd.options, Options), DictWrapper)
@@ -34,6 +40,115 @@ def test_option_tools() -> None:
3440
assert pd.get_option("display.width") == 120
3541

3642

43+
def test_set_option_overload() -> None:
44+
"""Test the different overloads of `pd.set_option`."""
45+
# dict
46+
check(assert_type(pd.set_option({"display.width": 80}), None), type(None))
47+
check(
48+
assert_type(pd.set_option({"display.width": 80, "display.precision": 6}), None),
49+
type(None),
50+
)
51+
52+
# one pair of arguments
53+
check(assert_type(pd.set_option("display.width", 80), None), type(None))
54+
check(assert_type(pd.set_option("display.precision", 6), None), type(None))
55+
check(assert_type(pd.set_option("display.max_rows", 60), None), type(None))
56+
check(assert_type(pd.set_option("display.max_rows", None), None), type(None))
57+
check(
58+
assert_type(pd.set_option("display.expand_frame_repr", True), None), type(None)
59+
)
60+
61+
# two pairs of arguments
62+
check(
63+
assert_type(pd.set_option("display.width", 80, "display.precision", 6), None),
64+
type(None),
65+
)
66+
check(
67+
assert_type(
68+
pd.set_option("display.max_rows", 60, "display.max_columns", 20), None
69+
),
70+
type(None),
71+
)
72+
73+
# three pairs of arguments
74+
check(
75+
assert_type(
76+
pd.set_option(
77+
"display.width",
78+
80,
79+
"display.precision",
80+
6,
81+
"display.max_rows",
82+
60,
83+
),
84+
None,
85+
),
86+
type(None),
87+
)
88+
89+
# four pairs of arguments
90+
check(
91+
assert_type(
92+
pd.set_option(
93+
"display.width",
94+
80,
95+
"display.precision",
96+
6,
97+
"display.max_rows",
98+
60,
99+
"display.max_columns",
100+
20,
101+
),
102+
None,
103+
),
104+
type(None),
105+
)
106+
107+
# five pairs of arguments
108+
check(
109+
assert_type(
110+
pd.set_option(
111+
"display.width",
112+
80,
113+
"display.precision",
114+
6,
115+
"display.max_rows",
116+
60,
117+
"display.max_columns",
118+
20,
119+
"display.max_colwidth",
120+
50,
121+
),
122+
None,
123+
),
124+
type(None),
125+
)
126+
127+
128+
def test_set_option_six_pairs() -> None:
129+
# GH 1680: set_option(pat0..pat5, val0..val5)
130+
check(
131+
assert_type(
132+
pd.set_option(
133+
"display.width",
134+
80,
135+
"display.precision",
136+
6,
137+
"display.max_rows",
138+
60,
139+
"display.max_columns",
140+
20,
141+
"display.max_colwidth",
142+
50,
143+
"display.min_rows",
144+
10,
145+
),
146+
None,
147+
),
148+
type(None),
149+
)
150+
151+
37152
def test_specific_option() -> None:
38153
# GH 294
39154
check(assert_type(pd.options.plotting.backend, str), str)

0 commit comments

Comments
 (0)