Skip to content

Commit bd1263f

Browse files
authored
TYP: annotation of __init__ return type (PEP 484) (pandas/io) (#46284)
1 parent c0d746f commit bd1263f

32 files changed

+92
-86
lines changed

pandas/io/clipboard/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class PyperclipException(RuntimeError):
9393

9494

9595
class PyperclipWindowsException(PyperclipException):
96-
def __init__(self, message):
96+
def __init__(self, message) -> None:
9797
message += f" ({ctypes.WinError()})"
9898
super().__init__(message)
9999

@@ -305,7 +305,7 @@ def __bool__(self) -> bool:
305305

306306
# Windows-related clipboard functions:
307307
class CheckedCall:
308-
def __init__(self, f):
308+
def __init__(self, f) -> None:
309309
super().__setattr__("f", f)
310310

311311
def __call__(self, *args):

pandas/io/common.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ def __init__(
872872
mode: str,
873873
archive_name: str | None = None,
874874
**kwargs,
875-
):
875+
) -> None:
876876
mode = mode.replace("b", "")
877877
self.archive_name = archive_name
878878
self.multiple_write_buffer: StringIO | BytesIO | None = None
@@ -944,7 +944,7 @@ def __init__(
944944
encoding: str = "utf-8",
945945
errors: str = "strict",
946946
decode: bool = True,
947-
):
947+
) -> None:
948948
self.encoding = encoding
949949
self.errors = errors
950950
self.decoder = codecs.getincrementaldecoder(encoding)(errors=errors)
@@ -999,7 +999,7 @@ class _IOWrapper:
999999
# methods, e.g., tempfile.SpooledTemporaryFile.
10001000
# If a buffer does not have the above "-able" methods, we simple assume they are
10011001
# seek/read/writ-able.
1002-
def __init__(self, buffer: BaseBuffer):
1002+
def __init__(self, buffer: BaseBuffer) -> None:
10031003
self.buffer = buffer
10041004

10051005
def __getattr__(self, name: str):
@@ -1026,7 +1026,7 @@ def writable(self) -> bool:
10261026
class _BytesIOWrapper:
10271027
# Wrapper that wraps a StringIO buffer and reads bytes from it
10281028
# Created for compat with pyarrow read_csv
1029-
def __init__(self, buffer: StringIO | TextIOBase, encoding: str = "utf-8"):
1029+
def __init__(self, buffer: StringIO | TextIOBase, encoding: str = "utf-8") -> None:
10301030
self.buffer = buffer
10311031
self.encoding = encoding
10321032
# Because a character can be represented by more than 1 byte,

pandas/io/excel/_base.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,9 @@ def read_excel(
497497

498498

499499
class BaseExcelReader(metaclass=abc.ABCMeta):
500-
def __init__(self, filepath_or_buffer, storage_options: StorageOptions = None):
500+
def __init__(
501+
self, filepath_or_buffer, storage_options: StorageOptions = None
502+
) -> None:
501503
# First argument can also be bytes, so create a buffer
502504
if isinstance(filepath_or_buffer, bytes):
503505
filepath_or_buffer = BytesIO(filepath_or_buffer)
@@ -1131,7 +1133,7 @@ def __init__(
11311133
if_sheet_exists: str | None = None,
11321134
engine_kwargs: dict[str, Any] | None = None,
11331135
**kwargs,
1134-
):
1136+
) -> None:
11351137
# validate that this engine can handle the extension
11361138
if isinstance(path, str):
11371139
ext = os.path.splitext(path)[-1]
@@ -1454,7 +1456,7 @@ def __init__(
14541456
path_or_buffer,
14551457
engine: str | None = None,
14561458
storage_options: StorageOptions = None,
1457-
):
1459+
) -> None:
14581460
if engine is not None and engine not in self._engines:
14591461
raise ValueError(f"Unknown engine: {engine}")
14601462

pandas/io/excel/_odfreader.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(
4141
self,
4242
filepath_or_buffer: FilePath | ReadBuffer[bytes],
4343
storage_options: StorageOptions = None,
44-
):
44+
) -> None:
4545
import_optional_dependency("odf")
4646
super().__init__(filepath_or_buffer, storage_options=storage_options)
4747

pandas/io/excel/_odswriter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def __init__(
3939
if_sheet_exists: str | None = None,
4040
engine_kwargs: dict[str, Any] | None = None,
4141
**kwargs,
42-
):
42+
) -> None:
4343
from odf.opendocument import OpenDocumentSpreadsheet
4444

4545
if mode == "a":

pandas/io/excel/_openpyxl.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __init__(
5050
if_sheet_exists: str | None = None,
5151
engine_kwargs: dict[str, Any] | None = None,
5252
**kwargs,
53-
):
53+
) -> None:
5454
# Use the openpyxl module as the Excel writer.
5555
from openpyxl.workbook import Workbook
5656

pandas/io/excel/_pyxlsb.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(
2121
self,
2222
filepath_or_buffer: FilePath | ReadBuffer[bytes],
2323
storage_options: StorageOptions = None,
24-
):
24+
) -> None:
2525
"""
2626
Reader using pyxlsb engine.
2727

pandas/io/excel/_xlrd.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
class XlrdReader(BaseExcelReader):
1515
@doc(storage_options=_shared_docs["storage_options"])
16-
def __init__(self, filepath_or_buffer, storage_options: StorageOptions = None):
16+
def __init__(
17+
self, filepath_or_buffer, storage_options: StorageOptions = None
18+
) -> None:
1719
"""
1820
Reader using xlrd engine.
1921

pandas/io/excel/_xlsxwriter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def __init__(
183183
if_sheet_exists: str | None = None,
184184
engine_kwargs: dict[str, Any] | None = None,
185185
**kwargs,
186-
):
186+
) -> None:
187187
# Use the xlsxwriter module as the Excel writer.
188188
from xlsxwriter import Workbook
189189

pandas/io/excel/_xlwt.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(
4040
if_sheet_exists: str | None = None,
4141
engine_kwargs: dict[str, Any] | None = None,
4242
**kwargs,
43-
):
43+
) -> None:
4444
# Use the xlwt module as the Excel writer.
4545
import xlwt
4646

pandas/io/formats/csvs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def __init__(
6666
doublequote: bool = True,
6767
escapechar: str | None = None,
6868
storage_options: StorageOptions = None,
69-
):
69+
) -> None:
7070
self.fmt = formatter
7171

7272
self.obj = self.fmt.frame

pandas/io/formats/excel.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def __init__(
6262
style=None,
6363
mergestart: int | None = None,
6464
mergeend: int | None = None,
65-
):
65+
) -> None:
6666
self.row = row
6767
self.col = col
6868
self.val = val
@@ -83,7 +83,7 @@ def __init__(
8383
css_col: int,
8484
css_converter: Callable | None,
8585
**kwargs,
86-
):
86+
) -> None:
8787
if css_styles and css_converter:
8888
css = ";".join(
8989
[a + ":" + str(v) for (a, v) in css_styles[css_row, css_col]]
@@ -158,7 +158,7 @@ class CSSToExcelConverter:
158158
# without monkey-patching.
159159
inherited: dict[str, str] | None
160160

161-
def __init__(self, inherited: str | None = None):
161+
def __init__(self, inherited: str | None = None) -> None:
162162
if inherited is not None:
163163
self.inherited = self.compute_css(inherited)
164164
else:
@@ -493,7 +493,7 @@ def __init__(
493493
merge_cells: bool = False,
494494
inf_rep: str = "inf",
495495
style_converter: Callable | None = None,
496-
):
496+
) -> None:
497497
self.rowcounter = 0
498498
self.na_rep = na_rep
499499
if not isinstance(df, DataFrame):

pandas/io/formats/format.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def __init__(
204204
length: bool = True,
205205
na_rep: str = "NaN",
206206
footer: bool = True,
207-
):
207+
) -> None:
208208
self.categorical = categorical
209209
self.buf = buf if buf is not None else StringIO("")
210210
self.na_rep = na_rep
@@ -274,7 +274,7 @@ def __init__(
274274
dtype: bool = True,
275275
max_rows: int | None = None,
276276
min_rows: int | None = None,
277-
):
277+
) -> None:
278278
self.series = series
279279
self.buf = buf if buf is not None else StringIO()
280280
self.name = name
@@ -421,7 +421,7 @@ def to_string(self) -> str:
421421

422422

423423
class TextAdjustment:
424-
def __init__(self):
424+
def __init__(self) -> None:
425425
self.encoding = get_option("display.encoding")
426426

427427
def len(self, text: str) -> int:
@@ -435,7 +435,7 @@ def adjoin(self, space: int, *lists, **kwargs) -> str:
435435

436436

437437
class EastAsianTextAdjustment(TextAdjustment):
438-
def __init__(self):
438+
def __init__(self) -> None:
439439
super().__init__()
440440
if get_option("display.unicode.ambiguous_as_wide"):
441441
self.ambiguous_width = 2
@@ -578,7 +578,7 @@ def __init__(
578578
decimal: str = ".",
579579
bold_rows: bool = False,
580580
escape: bool = True,
581-
):
581+
) -> None:
582582
self.frame = frame
583583
self.columns = self._initialize_columns(columns)
584584
self.col_space = self._initialize_colspace(col_space)
@@ -1017,7 +1017,7 @@ class DataFrameRenderer:
10171017
Formatter with the formatting options.
10181018
"""
10191019

1020-
def __init__(self, fmt: DataFrameFormatter):
1020+
def __init__(self, fmt: DataFrameFormatter) -> None:
10211021
self.fmt = fmt
10221022

10231023
def to_latex(
@@ -1332,7 +1332,7 @@ def __init__(
13321332
quoting: int | None = None,
13331333
fixed_width: bool = True,
13341334
leading_space: bool | None = True,
1335-
):
1335+
) -> None:
13361336
self.values = values
13371337
self.digits = digits
13381338
self.na_rep = na_rep
@@ -1425,7 +1425,7 @@ def _format(x):
14251425

14261426

14271427
class FloatArrayFormatter(GenericArrayFormatter):
1428-
def __init__(self, *args, **kwargs):
1428+
def __init__(self, *args, **kwargs) -> None:
14291429
super().__init__(*args, **kwargs)
14301430

14311431
# float_format is expected to be a string
@@ -1614,7 +1614,7 @@ def __init__(
16141614
nat_rep: str = "NaT",
16151615
date_format: None = None,
16161616
**kwargs,
1617-
):
1617+
) -> None:
16181618
super().__init__(values, **kwargs)
16191619
self.nat_rep = nat_rep
16201620
self.date_format = date_format
@@ -1823,7 +1823,7 @@ def __init__(
18231823
nat_rep: str = "NaT",
18241824
box: bool = False,
18251825
**kwargs,
1826-
):
1826+
) -> None:
18271827
super().__init__(values, **kwargs)
18281828
self.nat_rep = nat_rep
18291829
self.box = box
@@ -2023,7 +2023,9 @@ class EngFormatter:
20232023
24: "Y",
20242024
}
20252025

2026-
def __init__(self, accuracy: int | None = None, use_eng_prefix: bool = False):
2026+
def __init__(
2027+
self, accuracy: int | None = None, use_eng_prefix: bool = False
2028+
) -> None:
20272029
self.accuracy = accuracy
20282030
self.use_eng_prefix = use_eng_prefix
20292031

pandas/io/formats/info.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ def __init__(
459459
self,
460460
data: DataFrame,
461461
memory_usage: bool | str | None = None,
462-
):
462+
) -> None:
463463
self.data: DataFrame = data
464464
self.memory_usage = _initialize_memory_usage(memory_usage)
465465

@@ -535,7 +535,7 @@ def __init__(
535535
self,
536536
data: Series,
537537
memory_usage: bool | str | None = None,
538-
):
538+
) -> None:
539539
self.data: Series = data
540540
self.memory_usage = _initialize_memory_usage(memory_usage)
541541

@@ -629,7 +629,7 @@ def __init__(
629629
max_cols: int | None = None,
630630
verbose: bool | None = None,
631631
show_counts: bool | None = None,
632-
):
632+
) -> None:
633633
self.info = info
634634
self.data = info.data
635635
self.verbose = verbose
@@ -706,7 +706,7 @@ def __init__(
706706
info: SeriesInfo,
707707
verbose: bool | None = None,
708708
show_counts: bool | None = None,
709-
):
709+
) -> None:
710710
self.info = info
711711
self.data = info.data
712712
self.verbose = verbose
@@ -797,7 +797,7 @@ class DataFrameTableBuilder(TableBuilderAbstract):
797797
Instance of DataFrameInfo.
798798
"""
799799

800-
def __init__(self, *, info: DataFrameInfo):
800+
def __init__(self, *, info: DataFrameInfo) -> None:
801801
self.info: DataFrameInfo = info
802802

803803
def get_lines(self) -> list[str]:
@@ -959,7 +959,7 @@ def __init__(
959959
*,
960960
info: DataFrameInfo,
961961
with_counts: bool,
962-
):
962+
) -> None:
963963
self.info = info
964964
self.with_counts = with_counts
965965
self.strrows: Sequence[Sequence[str]] = list(self._gen_rows())
@@ -1025,7 +1025,7 @@ class SeriesTableBuilder(TableBuilderAbstract):
10251025
Instance of SeriesInfo.
10261026
"""
10271027

1028-
def __init__(self, *, info: SeriesInfo):
1028+
def __init__(self, *, info: SeriesInfo) -> None:
10291029
self.info: SeriesInfo = info
10301030

10311031
def get_lines(self) -> list[str]:
@@ -1071,7 +1071,7 @@ def __init__(
10711071
*,
10721072
info: SeriesInfo,
10731073
with_counts: bool,
1074-
):
1074+
) -> None:
10751075
self.info = info
10761076
self.with_counts = with_counts
10771077
self.strrows: Sequence[Sequence[str]] = list(self._gen_rows())

pandas/io/formats/latex.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def __init__(
7474
multicolumn: bool = False,
7575
multicolumn_format: str | None = None,
7676
multirow: bool = False,
77-
):
77+
) -> None:
7878
self.fmt = formatter
7979
self.frame = self.fmt.frame
8080
self.multicolumn = multicolumn
@@ -336,7 +336,7 @@ def __init__(
336336
short_caption: str | None = None,
337337
label: str | None = None,
338338
position: str | None = None,
339-
):
339+
) -> None:
340340
self.fmt = formatter
341341
self.column_format = column_format
342342
self.multicolumn = multicolumn
@@ -697,7 +697,7 @@ def __init__(
697697
caption: str | tuple[str, str] | None = None,
698698
label: str | None = None,
699699
position: str | None = None,
700-
):
700+
) -> None:
701701
self.fmt = formatter
702702
self.frame = self.fmt.frame
703703
self.longtable = longtable

0 commit comments

Comments
 (0)