Skip to content

Commit 6c62e3e

Browse files
Add doc-strings and type annotations
1 parent 8437b30 commit 6c62e3e

File tree

1 file changed

+57
-10
lines changed

1 file changed

+57
-10
lines changed

pandas/io/excel/_odswriter.py

+57-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from collections import defaultdict
22
import datetime
3-
from typing import DefaultDict, Dict
3+
from typing import Any, DefaultDict, Dict, List, Tuple
44

55
import pandas._libs.json as json
66

@@ -12,7 +12,8 @@ class _ODSWriter(ExcelWriter):
1212
engine = "odf"
1313
supported_extensions = (".ods",)
1414

15-
def __init__(self, path, engine=None, encoding=None, mode="w", **engine_kwargs):
15+
def __init__(self, path: str, engine: Dict = None, mode: str = "w",
16+
**engine_kwargs):
1617
from odf.opendocument import OpenDocumentSpreadsheet
1718

1819
engine_kwargs["engine"] = engine
@@ -25,17 +26,18 @@ def __init__(self, path, engine=None, encoding=None, mode="w", **engine_kwargs):
2526
self.book = OpenDocumentSpreadsheet()
2627
self._style_dict: Dict[str, str] = {}
2728

28-
def save(self):
29+
def save(self) -> None:
2930
"""
3031
Save workbook to disk.
3132
"""
3233
for sheet in self.sheets.values():
3334
self.book.spreadsheet.addElement(sheet)
34-
return self.book.save(self.path)
35+
self.book.save(self.path)
3536

3637
def write_cells(
37-
self, cells, sheet_name=None, startrow=0, startcol=0, freeze_panes=None
38-
):
38+
self, cells, sheet_name: str = None, startrow: int = 0, startcol: int = 0,
39+
freeze_panes: List = None
40+
) -> None:
3941
"""
4042
Write the frame cells using odf
4143
"""
@@ -80,7 +82,19 @@ def write_cells(
8082
for row_nr in range(max(rows.keys()) + 1):
8183
wks.addElement(rows[row_nr])
8284

83-
def _make_table_cell_attributes(self, cell):
85+
def _make_table_cell_attributes(self, cell) -> Dict[str, object]:
86+
"""Convert cell attributes to OpenDocument attributes
87+
88+
Parameters
89+
----------
90+
cell : ExcelCell
91+
Spreadsheet cell data
92+
93+
Returns
94+
-------
95+
attributes : Dict[str, object]
96+
Dictionary with attributes and attribute values
97+
"""
8498
attributes = {}
8599
style_name = self._process_style(cell.style)
86100
if style_name is not None:
@@ -90,7 +104,19 @@ def _make_table_cell_attributes(self, cell):
90104
attributes["numbercolumnsspanned"] = cell.mergeend
91105
return attributes
92106

93-
def _make_table_cell(self, cell):
107+
def _make_table_cell(self, cell) -> Tuple[str, object]:
108+
"""Convert cell data to an OpenDocument spreadsheet cell
109+
110+
Parameters
111+
----------
112+
cell : ExcelCell
113+
Spreadsheet cell data
114+
115+
Returns
116+
-------
117+
pvalue, cell : Tuple[str, object]
118+
Display value, Cell value
119+
"""
94120
from odf.table import TableCell
95121

96122
attributes = self._make_table_cell_attributes(cell)
@@ -129,7 +155,19 @@ def _make_table_cell(self, cell):
129155
),
130156
)
131157

132-
def _process_style(self, style):
158+
def _process_style(self, style: Dict[str, Any]) -> str:
159+
"""Convert a style dictionary to a OpenDocument style sheet
160+
161+
Parameters
162+
----------
163+
style : Dict
164+
Style dictionary
165+
166+
Returns
167+
-------
168+
style_key : str
169+
Unique style key for for later reference in sheet
170+
"""
133171
from odf.style import (
134172
ParagraphProperties,
135173
Style,
@@ -169,7 +207,16 @@ def _process_style(self, style):
169207
self.book.styles.addElement(odf_style)
170208
return name
171209

172-
def _create_freeze_panes(self, sheet_name, freeze_panes):
210+
def _create_freeze_panes(self, sheet_name: str, freeze_panes: List[int]) -> None:
211+
"""Create freeze panes in the sheet
212+
213+
Parameters
214+
----------
215+
sheet_name : str
216+
Name of the spreadsheet
217+
freeze_panes : list
218+
Freeze pane location x and y
219+
"""
173220
from odf.config import (
174221
ConfigItem,
175222
ConfigItemMapEntry,

0 commit comments

Comments
 (0)