2
2
Utilities for conversion to writer-agnostic Excel representation.
3
3
"""
4
4
5
- from _future_ import annotations
5
+ from __future__ import annotations
6
6
7
7
from collections .abc import (
8
8
Callable ,
11
11
Mapping ,
12
12
Sequence ,
13
13
)
14
- import pandas as pd
15
14
import functools
16
15
import itertools
17
16
import re
64
63
65
64
66
65
class ExcelCell :
67
- _fields_ = ("row" , "col" , "val" , "style" , "mergestart" , "mergeend" )
68
- _slots_ = _fields_
66
+ __fields__ = ("row" , "col" , "val" , "style" , "mergestart" , "mergeend" )
67
+ __slots__ = __fields__
69
68
70
- def _init_ (
69
+ def __init__ (
71
70
self ,
72
71
row : int ,
73
72
col : int ,
@@ -85,7 +84,7 @@ def _init_(
85
84
86
85
87
86
class CssExcelCell (ExcelCell ):
88
- def _init_ (
87
+ def __init__ (
89
88
self ,
90
89
row : int ,
91
90
col : int ,
@@ -106,7 +105,7 @@ def _init_(
106
105
unique_declarations = frozenset (declaration_dict .items ())
107
106
style = css_converter (unique_declarations )
108
107
109
- super ()._init_ (row = row , col = col , val = val , style = style , ** kwargs )
108
+ super ().__init__ (row = row , col = col , val = val , style = style , ** kwargs )
110
109
111
110
112
111
class CSSToExcelConverter :
@@ -117,14 +116,14 @@ class CSSToExcelConverter:
117
116
focusing on font styling, backgrounds, borders and alignment.
118
117
119
118
Operates by first computing CSS styles in a fairly generic
120
- way (see :meth: compute_css ) then determining Excel style
121
- properties from CSS properties (see :meth: build_xlstyle ).
119
+ way (see :meth: ` compute_css` ) then determining Excel style
120
+ properties from CSS properties (see :meth: ` build_xlstyle` ).
122
121
123
122
Parameters
124
123
----------
125
124
inherited : str, optional
126
125
CSS declarations understood to be the containing scope for the
127
- CSS processed by :meth: __call__ .
126
+ CSS processed by :meth:` __call__` .
128
127
"""
129
128
130
129
NAMED_COLORS = CSS4_COLORS
@@ -184,25 +183,25 @@ class CSSToExcelConverter:
184
183
]
185
184
}
186
185
187
- # NB: Most of the methods here could be classmethods, as only _init_
188
- # and _call_ make use of instance attributes. We leave them as
186
+ # NB: Most of the methods here could be classmethods, as only __init__
187
+ # and __call__ make use of instance attributes. We leave them as
189
188
# instancemethods so that users can easily experiment with extensions
190
189
# without monkey-patching.
191
190
inherited : dict [str , str ] | None
192
191
193
- def _init_ (self , inherited : str | None = None ) -> None :
192
+ def __init__ (self , inherited : str | None = None ) -> None :
194
193
if inherited is not None :
195
194
self .inherited = self .compute_css (inherited )
196
195
else :
197
196
self .inherited = None
198
- # We should avoid cache on the _call_ method.
199
- # Otherwise once the method _call_ has been called
197
+ # We should avoid cache on the __call__ method.
198
+ # Otherwise once the method __call__ has been called
200
199
# garbage collection no longer deletes the instance.
201
200
self ._call_cached = functools .cache (self ._call_uncached )
202
201
203
202
compute_css = CSSResolver ()
204
203
205
- def _call_ (
204
+ def __call__ (
206
205
self , declarations : str | frozenset [tuple [str , str ]]
207
206
) -> dict [str , dict [str , str ]]:
208
207
"""
@@ -518,27 +517,27 @@ class ExcelFormatter:
518
517
output row names (index)
519
518
index_label : str or sequence, default None
520
519
Column label for index column(s) if desired. If None is given, and
521
- header and index are True, then the index names are used. A
520
+ ` header` and ` index` are True, then the index names are used. A
522
521
sequence should be given if the DataFrame uses MultiIndex.
523
522
merge_cells : bool or 'columns', default False
524
523
Format MultiIndex column headers and Hierarchical Rows as merged cells
525
524
if True. Merge MultiIndex column headers only if 'columns'.
526
525
.. versionchanged:: 3.0.0
527
526
Added the 'columns' option.
528
- inf_rep : str, default 'inf'
527
+ inf_rep : str, default ` 'inf'`
529
528
representation for np.inf values (which aren't representable in Excel)
530
- A '-' sign will be added in front of -inf.
529
+ A ` '-'` sign will be added in front of -inf.
531
530
style_converter : callable, optional
532
531
This translates Styler styles (CSS) into ExcelWriter styles.
533
- Defaults to ` CSSToExcelConverter() `.
532
+ Defaults to `` CSSToExcelConverter()` `.
534
533
It should have signature css_declarations string -> excel style.
535
534
This is only called for body cells.
536
535
"""
537
536
538
537
max_rows = 2 ** 20
539
538
max_cols = 2 ** 14
540
539
541
- def _init_ (
540
+ def __init__ (
542
541
self ,
543
542
df ,
544
543
na_rep : str = "" ,
@@ -928,8 +927,8 @@ def write(
928
927
is to be frozen
929
928
engine : string, default None
930
929
write engine to use if writer is a path - you can also set this
931
- via the options ` io.excel.xlsx.writer `,
932
- or ` io.excel.xlsm.writer `.
930
+ via the options `` io.excel.xlsx.writer` `,
931
+ or `` io.excel.xlsm.writer` `.
933
932
934
933
{storage_options}
935
934
@@ -971,4 +970,4 @@ def write(
971
970
finally :
972
971
# make sure to close opened file handles
973
972
if need_save :
974
- writer .close ()
973
+ writer .close ()
0 commit comments