-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy path_python_calamine.pyi
More file actions
233 lines (193 loc) · 6.18 KB
/
_python_calamine.pyi
File metadata and controls
233 lines (193 loc) · 6.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
from __future__ import annotations
import contextlib
import datetime
import enum
import os
import types
import typing
@typing.type_check_only
class ReadBuffer(typing.Protocol):
def seek(self, __offset: int, __whence: int = ...) -> int: ...
def read(self, __size: int = ...) -> bytes | None: ...
@typing.final
class SheetTypeEnum(enum.Enum):
WorkSheet = ...
DialogSheet = ...
MacroSheet = ...
ChartSheet = ...
Vba = ...
@typing.final
class SheetVisibleEnum(enum.Enum):
Visible = ...
Hidden = ...
VeryHidden = ...
@typing.final
class SheetMetadata:
name: str
typ: SheetTypeEnum
visible: SheetVisibleEnum
def __init__(
self, name: str, typ: SheetTypeEnum, visible: SheetVisibleEnum
) -> None: ...
@typing.final
class CalamineSheet:
name: str
@property
def height(self) -> int: ...
@property
def width(self) -> int: ...
@property
def total_height(self) -> int: ...
@property
def total_width(self) -> int: ...
@property
def start(self) -> tuple[int, int] | None: ...
@property
def end(self) -> tuple[int, int] | None: ...
def to_python(
self, skip_empty_area: bool = True, nrows: int | None = None
) -> list[
list[
int
| float
| str
| bool
| datetime.time
| datetime.date
| datetime.datetime
| datetime.timedelta
]
]:
"""Retunrning data from sheet as list of lists.
Args:
skip_empty_area (bool):
By default, calamine skips empty rows/cols before data.
For suppress this behaviour, set `skip_empty_area` to `False`.
"""
def iter_rows(self) -> CalamineCellIterator:
"""Return data from sheet as an iterator."""
def iter_formulas(self) -> CalamineFormulaIterator:
"""Return formulas from sheet as an iterator.
Raises:
ValueError: If read_formulas=False when creating the workbook.
"""
@property
def merged_cell_ranges(
self,
) -> list[tuple[tuple[int, int], tuple[int, int]]] | None:
"""Return a copy of merged cell ranges.
Support only for xlsx/xls.
Returns:
list of merged cell ranges (tuple[start coordinate, end coordinate]) or None for unsuported format
"""
@typing.final
class CalamineCellIterator:
"""Iterator for cell data in a CalamineSheet."""
position: int
start: tuple[int, int]
height: int
width: int
def __iter__(self) -> "CalamineCellIterator": ...
def __next__(
self,
) -> list[
int
| float
| str
| bool
| datetime.time
| datetime.date
| datetime.datetime
| datetime.timedelta
]: ...
@typing.final
class CalamineFormulaIterator:
"""Iterator for formula data in a CalamineSheet."""
position: int
start: tuple[int, int]
width: int
height: int
def __iter__(self) -> "CalamineFormulaIterator": ...
def __next__(self) -> list[str]: ...
@typing.final
class CalamineWorkbook(contextlib.AbstractContextManager):
path: str | None
sheet_names: list[str]
sheets_metadata: list[SheetMetadata]
@classmethod
def from_object(
cls,
path_or_filelike: str | os.PathLike | ReadBuffer,
read_formulas: bool = False,
) -> "CalamineWorkbook":
"""Determining type of pyobject and reading from it.
Args:
path_or_filelike (str | os.PathLike | ReadBuffer): path to file or IO (must imlpement read/seek methods).
read_formulas (bool): Enable formula reading support. Default is False.
"""
@classmethod
def from_path(
cls, path: str | os.PathLike, read_formulas: bool = False
) -> "CalamineWorkbook":
"""Reading file from path.
Args:
path (str | os.PathLike): path to file.
read_formulas (bool): Enable formula reading support. Default is False.
"""
@classmethod
def from_filelike(
cls, filelike: ReadBuffer, read_formulas: bool = False
) -> "CalamineWorkbook":
"""Reading file from IO.
Args:
filelike : IO (must imlpement read/seek methods).
read_formulas (bool): Enable formula reading support. Default is False.
"""
def close(self) -> None:
"""Close the workbook.
Drop internal rust structure from workbook (and close the file under the hood).
`get_sheet_by_name`/`get_sheet_by_index` will raise WorkbookClosed after calling that method.
Raises:
WorkbookClosed: If workbook already closed.
"""
def __enter__(self) -> "CalamineWorkbook": ...
def __exit__(
self,
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: types.TracebackType | None,
) -> None: ...
def get_sheet_by_name(self, name: str) -> CalamineSheet:
"""Get worksheet by name.
Args:
name(str): name of worksheet
Returns:
CalamineSheet
Raises:
WorkbookClosed: If workbook already closed.
WorksheetNotFound: If worksheet not found in workbook.
"""
def get_sheet_by_index(self, index: int) -> CalamineSheet:
"""Get worksheet by index.
Args:
index(int): index of worksheet
Returns:
CalamineSheet
Raises:
WorkbookClosed: If workbook already closed.
WorksheetNotFound: If worksheet not found in workbook.
"""
class CalamineError(Exception): ...
class PasswordError(CalamineError): ...
class WorksheetNotFound(CalamineError): ...
class XmlError(CalamineError): ...
class ZipError(CalamineError): ...
class WorkbookClosed(CalamineError): ...
def load_workbook(
path_or_filelike: str | os.PathLike | ReadBuffer, read_formulas: bool = False
) -> CalamineWorkbook:
"""Determining type of pyobject and reading from it.
Args:
path_or_filelike (str | os.PathLike | ReadBuffer): path to file or IO (must imlpement read/seek methods).
read_formulas (bool): Enable formula reading support. Default is False.
"""