|
1 |
| -import abc |
| 1 | +from types import TracebackType |
2 | 2 | from typing import (
|
3 | 3 | Any,
|
4 | 4 | Callable,
|
| 5 | + Generator, |
| 6 | + Hashable, |
| 7 | + Iterable, |
| 8 | + Literal, |
5 | 9 | Sequence,
|
6 | 10 | overload,
|
7 | 11 | )
|
8 | 12 |
|
| 13 | +from odf.opendocument import OpenDocument |
| 14 | +from openpyxl.workbook.workbook import Workbook |
9 | 15 | from pandas.core.frame import DataFrame
|
| 16 | +import pyxlsb.workbook |
| 17 | +from xlrd.book import Book |
10 | 18 |
|
11 | 19 | from pandas._typing import (
|
12 | 20 | Dtype,
|
13 | 21 | FilePath,
|
14 | 22 | ReadBuffer,
|
15 |
| - Scalar, |
| 23 | + StorageOptions, |
| 24 | + WriteExcelBuffer, |
16 | 25 | )
|
17 | 26 |
|
| 27 | +from pandas.io.common import IOHandles |
| 28 | + |
18 | 29 | @overload
|
19 | 30 | def read_excel(
|
20 |
| - filepath: FilePath | ReadBuffer[bytes] | bytes, |
| 31 | + io: FilePath |
| 32 | + | ReadBuffer[bytes] |
| 33 | + | bytes |
| 34 | + | ExcelFile |
| 35 | + | Workbook |
| 36 | + | Book |
| 37 | + | OpenDocument |
| 38 | + | pyxlsb.workbook.Workbook, |
21 | 39 | sheet_name: list[int | str] | None,
|
| 40 | + *, |
22 | 41 | header: int | Sequence[int] | None = ...,
|
23 | 42 | names: list[str] | None = ...,
|
24 | 43 | index_col: int | Sequence[int] | None = ...,
|
25 |
| - usecols: int | str | Sequence[int | str | Callable] | None = ..., |
26 |
| - squeeze: bool = ..., |
27 |
| - dtype: str | dict[str, Any] | Dtype = ..., |
28 |
| - engine: str | None = ..., |
29 |
| - converters: dict[int | str, Callable] | None = ..., |
30 |
| - true_values: Sequence[Scalar] | None = ..., |
31 |
| - false_values: Sequence[Scalar] | None = ..., |
32 |
| - skiprows: Sequence[int] | int | Callable | None = ..., |
| 44 | + usecols: Sequence[int] | Sequence[str] | Callable[[str], bool] | None = ..., |
| 45 | + dtype: str | Dtype | dict[str, str | Dtype] | None = ..., |
| 46 | + engine: Literal["xlrd", "openpyxl", "odf", "pyxlsb"] | None = ..., |
| 47 | + converters: dict[int | str, Callable[[object], object]] | None = ..., |
| 48 | + true_values: Iterable[Hashable] | None = ..., |
| 49 | + false_values: Iterable[Hashable] | None = ..., |
| 50 | + skiprows: int | Sequence[int] | Callable[[object], bool] | None = ..., |
33 | 51 | nrows: int | None = ...,
|
34 |
| - na_values=..., |
| 52 | + na_values: Sequence[str] | dict[str | int, Sequence[str]] = ..., |
35 | 53 | keep_default_na: bool = ...,
|
| 54 | + na_filter: bool = ..., |
36 | 55 | verbose: bool = ...,
|
37 |
| - parse_dates: bool | Sequence | dict[str, Sequence] = ..., |
| 56 | + parse_dates: bool |
| 57 | + | Sequence[int] |
| 58 | + | Sequence[Sequence[str] | Sequence[int]] |
| 59 | + | dict[str, Sequence[int] | list[str]] = ..., |
38 | 60 | date_parser: Callable | None = ...,
|
39 | 61 | thousands: str | None = ...,
|
| 62 | + decimal: str = ..., |
40 | 63 | comment: str | None = ...,
|
41 | 64 | skipfooter: int = ...,
|
42 |
| - convert_float: bool = ..., |
43 |
| - mangle_dupe_cols: bool = ..., |
| 65 | + storage_options: StorageOptions = ..., |
44 | 66 | ) -> dict[int | str, DataFrame]: ...
|
45 | 67 | @overload
|
46 | 68 | def read_excel(
|
47 |
| - filepath: FilePath | ReadBuffer[bytes] | bytes, |
| 69 | + io: FilePath |
| 70 | + | ReadBuffer[bytes] |
| 71 | + | bytes |
| 72 | + | ExcelFile |
| 73 | + | Workbook |
| 74 | + | Book |
| 75 | + | OpenDocument |
| 76 | + | pyxlsb.workbook.Workbook, |
48 | 77 | sheet_name: int | str = ...,
|
| 78 | + *, |
49 | 79 | header: int | Sequence[int] | None = ...,
|
50 | 80 | names: list[str] | None = ...,
|
51 | 81 | index_col: int | Sequence[int] | None = ...,
|
52 |
| - usecols: int | str | Sequence[int | str | Callable] | None = ..., |
53 |
| - squeeze: bool = ..., |
54 |
| - dtype: str | dict[str, Any] | Dtype = ..., |
55 |
| - engine: str | None = ..., |
56 |
| - converters: dict[int | str, Callable] | None = ..., |
57 |
| - true_values: Sequence[Scalar] | None = ..., |
58 |
| - false_values: Sequence[Scalar] | None = ..., |
59 |
| - skiprows: Sequence[int] | int | Callable | None = ..., |
| 82 | + usecols: Sequence[int] | Sequence[str] | Callable[[str], bool] | None = ..., |
| 83 | + dtype: str | Dtype | dict[str, str | Dtype] | None = ..., |
| 84 | + engine: Literal["xlrd", "openpyxl", "odf", "pyxlsb"] | None = ..., |
| 85 | + converters: dict[int | str, Callable[[object], object]] | None = ..., |
| 86 | + true_values: Iterable[Hashable] | None = ..., |
| 87 | + false_values: Iterable[Hashable] | None = ..., |
| 88 | + skiprows: int | Sequence[int] | Callable[[object], bool] | None = ..., |
60 | 89 | nrows: int | None = ...,
|
61 |
| - na_values=..., |
| 90 | + na_values: Sequence[str] | dict[str | int, Sequence[str]] = ..., |
62 | 91 | keep_default_na: bool = ...,
|
| 92 | + na_filter: bool = ..., |
63 | 93 | verbose: bool = ...,
|
64 |
| - parse_dates: bool | Sequence | dict[str, Sequence] = ..., |
| 94 | + parse_dates: bool |
| 95 | + | Sequence[int] |
| 96 | + | Sequence[Sequence[str] | Sequence[int]] |
| 97 | + | dict[str, Sequence[int] | list[str]] = ..., |
65 | 98 | date_parser: Callable | None = ...,
|
66 | 99 | thousands: str | None = ...,
|
| 100 | + decimal: str = ..., |
67 | 101 | comment: str | None = ...,
|
68 | 102 | skipfooter: int = ...,
|
69 |
| - convert_float: bool = ..., |
70 |
| - mangle_dupe_cols: bool = ..., |
71 |
| - **kwargs, |
| 103 | + storage_options: StorageOptions = ..., |
72 | 104 | ) -> DataFrame: ...
|
73 | 105 |
|
74 |
| -class BaseExcelReader(metaclass=abc.ABCMeta): |
75 |
| - book = ... |
76 |
| - def __init__(self, filepath_or_buffer) -> None: ... |
77 |
| - @abc.abstractmethod |
78 |
| - def load_workbook(self, filepath_or_buffer): ... |
79 |
| - def close(self) -> None: ... |
80 |
| - @property |
81 |
| - @abc.abstractmethod |
82 |
| - def sheet_names(self): ... |
83 |
| - @abc.abstractmethod |
84 |
| - def get_sheet_by_name(self, name): ... |
85 |
| - @abc.abstractmethod |
86 |
| - def get_sheet_by_index(self, index): ... |
87 |
| - @abc.abstractmethod |
88 |
| - def get_sheet_data(self, sheet, convert_float): ... |
89 |
| - def parse( |
| 106 | +class ExcelWriter: |
| 107 | + def __init__( |
90 | 108 | self,
|
91 |
| - sheet_name: int = ..., |
92 |
| - header: int = ..., |
93 |
| - names=..., |
94 |
| - index_col=..., |
95 |
| - usecols=..., |
96 |
| - squeeze: bool = ..., |
97 |
| - dtype=..., |
98 |
| - true_values=..., |
99 |
| - false_values=..., |
100 |
| - skiprows=..., |
101 |
| - nrows=..., |
102 |
| - na_values=..., |
103 |
| - verbose: bool = ..., |
104 |
| - parse_dates: bool = ..., |
105 |
| - date_parser=..., |
106 |
| - thousands=..., |
107 |
| - comment=..., |
108 |
| - skipfooter: int = ..., |
109 |
| - convert_float: bool = ..., |
110 |
| - mangle_dupe_cols: bool = ..., |
111 |
| - **kwds, |
112 |
| - ): ... |
113 |
| - |
114 |
| -class ExcelWriter(metaclass=abc.ABCMeta): |
115 |
| - def __new__(cls, path, engine=..., **kwargs): ... |
116 |
| - book = ... |
117 |
| - curr_sheet = ... |
118 |
| - path = ... |
| 109 | + path: FilePath | WriteExcelBuffer | ExcelWriter, |
| 110 | + engine: Literal["auto", "openpyxl", "pyxlsb", "odf"] | None = ..., |
| 111 | + date_format: str | None = ..., |
| 112 | + datetime_format: str | None = ..., |
| 113 | + mode: Literal["w", "writer"] = ..., |
| 114 | + storage_options: StorageOptions = ..., |
| 115 | + if_sheet_exists: Literal["error", "new", "replace", "overlay"] | None = ..., |
| 116 | + engine_kwargs: dict[str, Any] | None = ..., |
| 117 | + ) -> None: ... |
| 118 | + @property |
| 119 | + def supported_extensions(self) -> tuple[str, ...]: ... |
119 | 120 | @property
|
120 |
| - def supported_extensions(self): ... |
| 121 | + def engine(self) -> Literal["openpyxl", "pyxlsb", "odf"]: ... |
121 | 122 | @property
|
122 |
| - def engine(self): ... |
| 123 | + def sheets(self) -> dict[str, Any]: ... |
| 124 | + @property |
| 125 | + def book(self) -> Workbook | OpenDocument | pyxlsb.workbook.Workbook: ... |
123 | 126 | def write_cells(
|
124 | 127 | self,
|
125 |
| - cells, |
126 |
| - sheet_name=..., |
| 128 | + cells: Generator[object, None, None], |
| 129 | + sheet_name: str | None = ..., |
127 | 130 | startrow: int = ...,
|
128 | 131 | startcol: int = ...,
|
129 |
| - freeze_panes=..., |
130 |
| - ): ... |
131 |
| - def save(self): ... |
132 |
| - sheets = ... |
133 |
| - cur_sheet = ... |
134 |
| - date_format: str = ... |
135 |
| - datetime_format: str = ... |
136 |
| - mode = ... |
137 |
| - def __init__( |
| 132 | + freeze_panes: tuple[int, int] | None = ..., |
| 133 | + ) -> None: ... |
| 134 | + def save(self) -> None: ... |
| 135 | + @property |
| 136 | + def date_format(self) -> str: ... |
| 137 | + @property |
| 138 | + def datetime_format(self) -> str: ... |
| 139 | + @property |
| 140 | + def if_sheet_exists(self) -> Literal["error", "new", "replace", "overlay"]: ... |
| 141 | + @property |
| 142 | + def cur_sheet(self) -> Any: ... |
| 143 | + @property |
| 144 | + def handles(self) -> IOHandles[bytes]: ... |
| 145 | + @property |
| 146 | + def path(self) -> str | None: ... |
| 147 | + def __fspath__(self) -> str: ... |
| 148 | + def __enter__(self) -> ExcelWriter: ... |
| 149 | + def __exit__( |
138 | 150 | self,
|
139 |
| - path, |
140 |
| - engine=..., |
141 |
| - date_format=..., |
142 |
| - datetime_format=..., |
143 |
| - mode: str = ..., |
144 |
| - **engine_kwargs, |
| 151 | + exc_type: type[BaseException] | None, |
| 152 | + exc_value: BaseException | None, |
| 153 | + traceback: TracebackType | None, |
145 | 154 | ) -> None: ...
|
146 |
| - def __fspath__(self): ... |
147 |
| - @classmethod |
148 |
| - def check_extension(cls, ext): ... |
149 |
| - def __enter__(self): ... |
150 |
| - def __exit__(self, exc_type, exc_value, traceback) -> None: ... |
151 |
| - def close(self): ... |
| 155 | + def close(self) -> None: ... |
152 | 156 |
|
153 | 157 | class ExcelFile:
|
154 | 158 | engine = ...
|
155 |
| - io = ... |
156 |
| - def __init__(self, io, engine=...) -> None: ... |
| 159 | + io: FilePath | ReadBuffer[bytes] | bytes = ... |
| 160 | + def __init__( |
| 161 | + self, |
| 162 | + io: FilePath | ReadBuffer[bytes] | bytes, |
| 163 | + engine: Literal["xlrd", "openpyxl", "odf", "pyxlsb"] | None = ..., |
| 164 | + storage_options: StorageOptions = ..., |
| 165 | + ) -> None: ... |
157 | 166 | def __fspath__(self): ...
|
| 167 | + @overload |
158 | 168 | def parse(
|
159 | 169 | self,
|
160 |
| - sheet_name: int = ..., |
161 |
| - header: int = ..., |
162 |
| - names=..., |
163 |
| - index_col=..., |
164 |
| - usecols=..., |
165 |
| - squeeze: bool = ..., |
166 |
| - converters=..., |
167 |
| - true_values=..., |
168 |
| - false_values=..., |
169 |
| - skiprows=..., |
170 |
| - nrows=..., |
171 |
| - na_values=..., |
172 |
| - parse_dates: bool = ..., |
173 |
| - date_parser=..., |
174 |
| - thousands=..., |
175 |
| - comment=..., |
| 170 | + sheet_name: list[int | str] | None, |
| 171 | + header: int | Sequence[int] | None = ..., |
| 172 | + names: list[str] | None = ..., |
| 173 | + index_col: int | Sequence[int] | None = ..., |
| 174 | + usecols: str |
| 175 | + | Sequence[int] |
| 176 | + | Sequence[str] |
| 177 | + | Callable[[str], bool] |
| 178 | + | None = ..., |
| 179 | + converters: dict[int | str, Callable[[object], object]] | None = ..., |
| 180 | + true_values: Iterable[Hashable] | None = ..., |
| 181 | + false_values: Iterable[Hashable] | None = ..., |
| 182 | + skiprows: int | Sequence[int] | Callable[[object], bool] | None = ..., |
| 183 | + nrows: int | None = ..., |
| 184 | + na_values: Sequence[str] | dict[str | int, Sequence[str]] = ..., |
| 185 | + parse_dates: bool |
| 186 | + | Sequence[int] |
| 187 | + | Sequence[Sequence[str] | Sequence[int]] |
| 188 | + | dict[str, Sequence[int] | list[str]] = ..., |
| 189 | + date_parser: Callable | None = ..., |
| 190 | + thousands: str | None = ..., |
| 191 | + comment: str | None = ..., |
176 | 192 | skipfooter: int = ...,
|
177 |
| - convert_float: bool = ..., |
178 |
| - mangle_dupe_cols: bool = ..., |
179 |
| - **kwds, |
180 |
| - ): ... |
| 193 | + keep_default_na: bool = ..., |
| 194 | + na_filter: bool = ..., |
| 195 | + **kwds: Any, |
| 196 | + ) -> dict[int | str, DataFrame]: ... |
| 197 | + @overload |
| 198 | + def parse( |
| 199 | + self, |
| 200 | + sheet_name: int | str, |
| 201 | + header: int | Sequence[int] | None = ..., |
| 202 | + names: list[str] | None = ..., |
| 203 | + index_col: int | Sequence[int] | None = ..., |
| 204 | + usecols: str |
| 205 | + | Sequence[int] |
| 206 | + | Sequence[str] |
| 207 | + | Callable[[str], bool] |
| 208 | + | None = ..., |
| 209 | + converters: dict[int | str, Callable[[object], object]] | None = ..., |
| 210 | + true_values: Iterable[Hashable] | None = ..., |
| 211 | + false_values: Iterable[Hashable] | None = ..., |
| 212 | + skiprows: int | Sequence[int] | Callable[[object], bool] | None = ..., |
| 213 | + nrows: int | None = ..., |
| 214 | + na_values: Sequence[str] | dict[str | int, Sequence[str]] = ..., |
| 215 | + parse_dates: bool |
| 216 | + | Sequence[int] |
| 217 | + | Sequence[Sequence[str] | Sequence[int]] |
| 218 | + | dict[str, Sequence[int] | list[str]] = ..., |
| 219 | + date_parser: Callable | None = ..., |
| 220 | + thousands: str | None = ..., |
| 221 | + comment: str | None = ..., |
| 222 | + skipfooter: int = ..., |
| 223 | + keep_default_na: bool = ..., |
| 224 | + na_filter: bool = ..., |
| 225 | + **kwds: Any, |
| 226 | + ) -> DataFrame: ... |
181 | 227 | @property
|
182 |
| - def book(self): ... |
| 228 | + def book(self) -> Workbook | Book | OpenDocument | pyxlsb.workbook.Workbook: ... |
183 | 229 | @property
|
184 |
| - def sheet_names(self): ... |
| 230 | + def sheet_names(self) -> list[int | str]: ... |
185 | 231 | def close(self) -> None: ...
|
186 |
| - def __enter__(self): ... |
187 |
| - def __exit__(self, exc_type, exc_value, traceback) -> None: ... |
| 232 | + def __enter__(self) -> ExcelFile: ... |
| 233 | + def __exit__( |
| 234 | + self, |
| 235 | + exc_type: type[BaseException] | None, |
| 236 | + exc_value: BaseException | None, |
| 237 | + traceback: TracebackType | None, |
| 238 | + ) -> None: ... |
188 | 239 | def __del__(self) -> None: ...
|
0 commit comments