1
1
from typing import (
2
2
Any ,
3
3
Callable ,
4
- Hashable ,
5
4
Literal ,
6
5
Sequence ,
7
- TypeVar ,
8
6
overload ,
9
7
)
10
8
9
+ from matplotlib .colors import Colormap
11
10
import numpy as np
12
11
from pandas .core .frame import DataFrame
13
12
from pandas .core .series import Series
@@ -20,20 +19,21 @@ from pandas._typing import (
20
19
Level ,
21
20
Scalar ,
22
21
WriteBuffer ,
22
+ WriteExcelBuffer ,
23
23
npt ,
24
24
)
25
25
26
+ from pandas .io .excel import ExcelWriter
26
27
from pandas .io .formats .style_render import (
27
28
CSSProperties ,
28
29
CSSStyles ,
29
30
ExtFormatter ,
31
+ StyleExportDict ,
30
32
StylerRenderer ,
31
33
Subset ,
32
34
)
33
35
34
- _StylerT = TypeVar ("_StylerT" , bound = Styler )
35
-
36
- class Styler (StylerRenderer ):
36
+ class Styler (StylerRenderer [Styler ]):
37
37
def __init__ (
38
38
self ,
39
39
data : DataFrame | Series ,
@@ -59,46 +59,91 @@ class Styler(StylerRenderer):
59
59
) -> Styler : ...
60
60
def to_excel (
61
61
self ,
62
- excel_writer ,
62
+ excel_writer : FilePath | WriteExcelBuffer | ExcelWriter ,
63
63
sheet_name : str = ...,
64
64
na_rep : str = ...,
65
65
float_format : str | None = ...,
66
- columns : Sequence [ Hashable ] | None = ...,
67
- header : Sequence [ Hashable ] | bool = ...,
66
+ columns : list [ HashableT ] | None = ...,
67
+ header : list [ HashableT ] | bool = ...,
68
68
index : bool = ...,
69
69
index_label : IndexLabel | None = ...,
70
70
startrow : int = ...,
71
71
startcol : int = ...,
72
- engine : str | None = ...,
72
+ engine : Literal [ "openpyxl" , "xlsxwriter" ] | None = ...,
73
73
merge_cells : bool = ...,
74
74
encoding : str | None = ...,
75
75
inf_rep : str = ...,
76
76
verbose : bool = ...,
77
77
freeze_panes : tuple [int , int ] | None = ...,
78
+ # TODO: Listed in docs but not in function decl
79
+ # storage_options: StorageOptions = ...,
78
80
) -> None : ...
81
+ @overload
79
82
def to_latex (
80
83
self ,
81
- buf : FilePath | WriteBuffer [str ] | None = ... ,
84
+ buf : FilePath | WriteBuffer [str ],
82
85
* ,
83
86
column_format : str | None = ...,
84
87
position : str | None = ...,
85
- position_float : str | None = ...,
88
+ position_float : Literal [ "centering" , "raggedleft" , "raggedright" ] | None = ...,
86
89
hrules : bool | None = ...,
87
- clines : str | None = ...,
90
+ clines : Literal ["all;data" , "all;index" , "skip-last;data" , "skip-last;index" ]
91
+ | None = ...,
88
92
label : str | None = ...,
89
- caption : str | tuple | None = ...,
93
+ caption : str | tuple [str , str ] | None = ...,
94
+ sparse_index : bool | None = ...,
95
+ sparse_columns : bool | None = ...,
96
+ multirow_align : Literal ["c" , "t" , "b" , "naive" ] | None = ...,
97
+ multicol_align : Literal ["r" , "c" , "l" , "naive-l" , "naive-r" ] | None = ...,
98
+ siunitx : bool = ...,
99
+ environment : str | None = ...,
100
+ encoding : str | None = ...,
101
+ convert_css : bool = ...,
102
+ ) -> None : ...
103
+ @overload
104
+ def to_latex (
105
+ self ,
106
+ buf : None = ...,
107
+ * ,
108
+ column_format : str | None = ...,
109
+ position : str | None = ...,
110
+ position_float : Literal ["centering" , "raggedleft" , "raggedright" ] | None = ...,
111
+ hrules : bool | None = ...,
112
+ clines : Literal ["all;data" , "all;index" , "skip-last;data" , "skip-last;index" ]
113
+ | None = ...,
114
+ label : str | None = ...,
115
+ caption : str | tuple [str , str ] | None = ...,
90
116
sparse_index : bool | None = ...,
91
117
sparse_columns : bool | None = ...,
92
- multirow_align : str | None = ...,
93
- multicol_align : str | None = ...,
118
+ multirow_align : Literal [ "c" , "t" , "b" , "naive" ] | None = ...,
119
+ multicol_align : Literal [ "r" , "c" , "l" , "naive-l" , "naive-r" ] | None = ...,
94
120
siunitx : bool = ...,
95
121
environment : str | None = ...,
96
122
encoding : str | None = ...,
97
123
convert_css : bool = ...,
98
- ): ...
124
+ ) -> str : ...
125
+ @overload
126
+ def to_html (
127
+ self ,
128
+ buf : FilePath | WriteBuffer [str ],
129
+ * ,
130
+ table_uuid : str | None = ...,
131
+ table_attributes : str | None = ...,
132
+ sparse_index : bool | None = ...,
133
+ sparse_columns : bool | None = ...,
134
+ bold_headers : bool = ...,
135
+ caption : str | None = ...,
136
+ max_rows : int | None = ...,
137
+ max_columns : int | None = ...,
138
+ encoding : str | None = ...,
139
+ doctype_html : bool = ...,
140
+ exclude_styles : bool = ...,
141
+ ** kwargs : Any ,
142
+ ) -> None : ...
143
+ @overload
99
144
def to_html (
100
145
self ,
101
- buf : FilePath | WriteBuffer [ str ] | None = ...,
146
+ buf : None = ...,
102
147
* ,
103
148
table_uuid : str | None = ...,
104
149
table_attributes : str | None = ...,
@@ -112,7 +157,7 @@ class Styler(StylerRenderer):
112
157
doctype_html : bool = ...,
113
158
exclude_styles : bool = ...,
114
159
** kwargs : Any ,
115
- ): ...
160
+ ) -> str : ...
116
161
def set_td_classes (self , classes : DataFrame ) -> Styler : ...
117
162
def __copy__ (self ) -> Styler : ...
118
163
def __deepcopy__ (self , memo ) -> Styler : ...
@@ -135,7 +180,7 @@ class Styler(StylerRenderer):
135
180
) -> Styler : ...
136
181
def apply_index (
137
182
self ,
138
- func : Callable [[Series ], npt .NDArray [np .str_ ]],
183
+ func : Callable [[Series ], npt .NDArray [np .str_ ] | list [ str ] | Series [ str ] ],
139
184
axis : int | str = ...,
140
185
level : Level | list [Level ] | None = ...,
141
186
** kwargs : Any ,
@@ -153,8 +198,8 @@ class Styler(StylerRenderer):
153
198
# def where(self, cond: Callable, value: str, other: str | None = ..., subset: Subset | None = ..., **kwargs) -> Styler: ...
154
199
# def set_precision(self, precision: int) -> StylerRenderer: ...
155
200
def set_table_attributes (self , attributes : str ) -> Styler : ...
156
- def export (self ) -> dict [ str , Any ] : ...
157
- def use (self , styles : dict [ str , Any ] ) -> Styler : ...
201
+ def export (self ) -> StyleExportDict : ...
202
+ def use (self , styles : StyleExportDict ) -> Styler : ...
158
203
uuid : Any # Incomplete
159
204
def set_uuid (self , uuid : str ) -> Styler : ...
160
205
caption : Any # Incomplete
@@ -174,6 +219,7 @@ class Styler(StylerRenderer):
174
219
) -> Styler : ...
175
220
# def set_na_rep(self, na_rep: str) -> StylerRenderer: ...
176
221
# def hide_index(self, subset: Subset | None = ..., level: Level | list[Level] | None = ..., names: bool = ...,) -> Styler: ...
222
+ # TODO: Not in docs? Should it be?
177
223
def hide_columns (
178
224
self ,
179
225
subset : Subset | None = ...,
@@ -189,26 +235,38 @@ class Styler(StylerRenderer):
189
235
) -> Styler : ...
190
236
def background_gradient (
191
237
self ,
192
- cmap : str = ...,
238
+ cmap : str | Colormap = ...,
193
239
low : float = ...,
194
240
high : float = ...,
195
241
axis : Axis | None = ...,
196
242
subset : Subset | None = ...,
197
243
text_color_threshold : float = ...,
198
244
vmin : float | None = ...,
199
245
vmax : float | None = ...,
200
- gmap : Sequence | None = ...,
246
+ gmap : Sequence [float ]
247
+ | Sequence [Sequence [float ]]
248
+ | npt .NDArray
249
+ | DataFrame
250
+ | Series
251
+ | None = ...,
201
252
) -> Styler : ...
202
253
def text_gradient (
203
254
self ,
204
- cmap : str = ...,
255
+ cmap : str | Colormap = ...,
205
256
low : float = ...,
206
257
high : float = ...,
207
258
axis : Axis | None = ...,
208
259
subset : Subset | None = ...,
260
+ # In docs but not in function declaration
261
+ # text_color_threshold: float
209
262
vmin : float | None = ...,
210
263
vmax : float | None = ...,
211
- gmap : Sequence | None = ...,
264
+ gmap : Sequence [float ]
265
+ | Sequence [Sequence [float ]]
266
+ | npt .NDArray
267
+ | DataFrame
268
+ | Series
269
+ | None = ...,
212
270
) -> Styler : ...
213
271
def set_properties (
214
272
self , subset : Subset | None = ..., ** kwargs : str | int
@@ -218,11 +276,13 @@ class Styler(StylerRenderer):
218
276
subset : Subset | None = ...,
219
277
axis : Axis | None = ...,
220
278
* ,
221
- color : str | list | tuple | None = ...,
222
- cmap : Any | None = ...,
279
+ color : str | list [ str ] | tuple [ str , str ] | None = ...,
280
+ cmap : str | Colormap = ...,
223
281
width : float = ...,
224
282
height : float = ...,
225
- align : str | float | Callable = ...,
283
+ align : Literal ["left" , "right" , "zero" , "mid" , "mean" ]
284
+ | float
285
+ | Callable [[Series | npt .NDArray | DataFrame ], float ] = ...,
226
286
vmin : float | None = ...,
227
287
vmax : float | None = ...,
228
288
props : str = ...,
@@ -276,10 +336,10 @@ class Styler(StylerRenderer):
276
336
searchpath : str | list [str ],
277
337
html_table : str | None = ...,
278
338
html_style : str | None = ...,
279
- ) -> _StylerT : ...
339
+ ) -> type [ Styler ] : ...
280
340
def pipe (
281
341
self ,
282
- func : Callable [[ Styler ], Styler ] | tuple [Callable [[ Styler ], Styler ] , str ],
342
+ func : Callable | tuple [Callable , str ],
283
343
* args : Any ,
284
344
** kwargs : Any ,
285
345
) -> Styler : ...
0 commit comments