Skip to content

Commit 3cb14af

Browse files
bashtageKevin Sheppard
and
Kevin Sheppard
authored
BUG: Generalize options (#306)
* BUG: Generalize options Generalize using specific classes for each level * TST: Correct backend Co-authored-by: Kevin Sheppard <[email protected]>
1 parent bb66356 commit 3cb14af

File tree

2 files changed

+169
-7
lines changed

2 files changed

+169
-7
lines changed

pandas-stubs/_config/config.pyi

Lines changed: 151 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,157 @@ class DictWrapper:
2222
def __getattr__(self, key: str) -> str | bool | int | DictWrapper | None: ...
2323
def __dir__(self) -> Iterable[str]: ...
2424

25-
options: DictWrapper = ...
25+
class Compute(DictWrapper):
26+
use_bottleneck: bool
27+
use_numba: bool
28+
use_numexpr: bool
29+
30+
class DisplayHTML(DictWrapper):
31+
border: int
32+
table_schema: bool
33+
use_mathjax: bool
34+
35+
class DisplayLaTeX(DictWrapper):
36+
escape: bool
37+
longtable: bool
38+
multicolumn: bool
39+
multicolumn_format: str
40+
multirow: bool
41+
repr: bool
42+
43+
class DisplayUnicode(DictWrapper):
44+
ambiguous_as_wide: bool
45+
east_asian_width: bool
46+
47+
class Display(DictWrapper):
48+
chop_threshold: int | None
49+
colheader_justify: str
50+
column_space: int
51+
date_dayfirst: bool
52+
date_yearfirst: bool
53+
encoding: str
54+
expand_frame_repr: bool
55+
float_format: str | None
56+
html: DisplayHTML
57+
large_repr: str
58+
latex: DisplayLaTeX
59+
max_categories: int
60+
max_columns: int
61+
max_colwidth: int
62+
max_dir_items: int
63+
max_info_columns: int
64+
max_info_rows: int
65+
max_rows: int
66+
max_seq_items: int
67+
memory_usage: bool
68+
min_rows: int
69+
multi_sparse: bool
70+
notebook_repr_html: bool
71+
pprint_nest_depth: int
72+
precision: int
73+
show_dimensions: str
74+
unicode: DisplayUnicode
75+
width: int
76+
77+
class IOExcelODS(DictWrapper):
78+
reader: str
79+
writer: str
80+
81+
class IOExcelXLS(DictWrapper):
82+
writer: str
83+
84+
class IOExcelXLSB(DictWrapper):
85+
reader: str
86+
87+
class IOExcelXLSM(DictWrapper):
88+
reader: str
89+
writer: str
90+
91+
class IOExcelXLSX(DictWrapper):
92+
reader: str
93+
writer: str
94+
95+
class IOExcel(DictWrapper):
96+
ods: IOExcelODS
97+
xls: DictWrapper
98+
xlsb: DictWrapper
99+
xlsm: DictWrapper
100+
xlsx: DictWrapper
101+
102+
class IOHDF(DictWrapper):
103+
default_format: Literal["table", "fixed"] | None
104+
dropna_table: bool
105+
106+
class IOParquet(DictWrapper):
107+
engine: str
108+
109+
class IOSQL(DictWrapper):
110+
engine: str
111+
112+
class IO(DictWrapper):
113+
excel: IOExcel
114+
hdf: IOHDF
115+
parquet: IOParquet
116+
sql: IOSQL
117+
118+
class Mode(DictWrapper):
119+
chained_assignment: str
120+
data_manager: str
121+
sim_interactive: bool
122+
string_storage: str
123+
use_inf_as_na: bool
124+
125+
class PlottingMatplotlib(DictWrapper):
126+
register_converters: str
127+
128+
class Plotting(DictWrapper):
129+
backend: str
130+
matplotlib: PlottingMatplotlib
131+
132+
class StylerFormat:
133+
decimal: str
134+
escape: str | None
135+
formatter: str | None
136+
na_rep: str | None
137+
precision: int
138+
thousands: str | None
139+
140+
class StylerHTML:
141+
mathjax: bool
142+
143+
class StylerLatex:
144+
environment: str | None
145+
hrules: bool
146+
multicol_align: str
147+
multirow_align: str
148+
149+
class StylerRender:
150+
encoding: str
151+
max_columns: int | None
152+
max_elements: int
153+
max_rows: int | None
154+
repr: str
155+
156+
class StylerSparse:
157+
columns: bool
158+
index: bool
159+
160+
class Styler(DictWrapper):
161+
format: StylerFormat
162+
html: StylerHTML
163+
latex: StylerLatex
164+
render: StylerRender
165+
sparse: StylerSparse
166+
167+
class Options(DictWrapper):
168+
compute: Compute
169+
display: Display
170+
io: IO
171+
mode: Mode
172+
plotting: Plotting
173+
styler: Styler
174+
175+
options: Options
26176

27177
class option_context(ContextDecorator):
28178
def __init__(self, /, pat: str, val: Any, *args: Any) -> None: ...

tests/test_config.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import (
2+
TYPE_CHECKING,
23
Any,
3-
Union,
44
)
55

66
import pandas as pd
@@ -10,17 +10,29 @@
1010

1111
from tests import check
1212

13+
if TYPE_CHECKING:
14+
from pandas._config.config import (
15+
Display,
16+
Options,
17+
)
18+
else:
19+
Display = Options = Any
20+
1321

1422
def test_option_tools():
1523
check(assert_type(pd.reset_option("display.width"), None), type(None))
1624
check(assert_type(pd.set_option("display.width", 80), None), type(None))
1725
check(assert_type(pd.describe_option("display.width", False), str), str)
1826
check(assert_type(pd.describe_option("display.width", True), None), type(None))
19-
check(assert_type(pd.options, DictWrapper), DictWrapper)
20-
check(
21-
assert_type(pd.options.display, Union[str, bool, int, None, DictWrapper]),
22-
DictWrapper,
23-
)
27+
check(assert_type(pd.options, Options), DictWrapper)
28+
check(assert_type(pd.options.display, Display), DictWrapper)
2429
check(assert_type(pd.get_option("display.width"), Any), int)
2530
with pd.option_context("display.width", 120):
2631
assert pd.get_option("display.width") == 120
32+
33+
34+
def test_specific_option():
35+
# GH 294
36+
check(assert_type(pd.options.plotting.backend, str), str)
37+
# Just check assignment
38+
pd.options.plotting.backend = "matplotlib"

0 commit comments

Comments
 (0)