Skip to content

TYP: annotation of __init__ return type (PEP 484) (pandas/io) #46284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pandas/io/clipboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class PyperclipException(RuntimeError):


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

Expand Down Expand Up @@ -305,7 +305,7 @@ def __bool__(self) -> bool:

# Windows-related clipboard functions:
class CheckedCall:
def __init__(self, f):
def __init__(self, f) -> None:
super().__setattr__("f", f)

def __call__(self, *args):
Expand Down
8 changes: 4 additions & 4 deletions pandas/io/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ def __init__(
mode: str,
archive_name: str | None = None,
**kwargs,
):
) -> None:
mode = mode.replace("b", "")
self.archive_name = archive_name
self.multiple_write_buffer: StringIO | BytesIO | None = None
Expand Down Expand Up @@ -944,7 +944,7 @@ def __init__(
encoding: str = "utf-8",
errors: str = "strict",
decode: bool = True,
):
) -> None:
self.encoding = encoding
self.errors = errors
self.decoder = codecs.getincrementaldecoder(encoding)(errors=errors)
Expand Down Expand Up @@ -999,7 +999,7 @@ class _IOWrapper:
# methods, e.g., tempfile.SpooledTemporaryFile.
# If a buffer does not have the above "-able" methods, we simple assume they are
# seek/read/writ-able.
def __init__(self, buffer: BaseBuffer):
def __init__(self, buffer: BaseBuffer) -> None:
self.buffer = buffer

def __getattr__(self, name: str):
Expand All @@ -1026,7 +1026,7 @@ def writable(self) -> bool:
class _BytesIOWrapper:
# Wrapper that wraps a StringIO buffer and reads bytes from it
# Created for compat with pyarrow read_csv
def __init__(self, buffer: StringIO | TextIOBase, encoding: str = "utf-8"):
def __init__(self, buffer: StringIO | TextIOBase, encoding: str = "utf-8") -> None:
self.buffer = buffer
self.encoding = encoding
# Because a character can be represented by more than 1 byte,
Expand Down
8 changes: 5 additions & 3 deletions pandas/io/excel/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,9 @@ def read_excel(


class BaseExcelReader(metaclass=abc.ABCMeta):
def __init__(self, filepath_or_buffer, storage_options: StorageOptions = None):
def __init__(
self, filepath_or_buffer, storage_options: StorageOptions = None
) -> None:
# First argument can also be bytes, so create a buffer
if isinstance(filepath_or_buffer, bytes):
filepath_or_buffer = BytesIO(filepath_or_buffer)
Expand Down Expand Up @@ -1131,7 +1133,7 @@ def __init__(
if_sheet_exists: str | None = None,
engine_kwargs: dict[str, Any] | None = None,
**kwargs,
):
) -> None:
# validate that this engine can handle the extension
if isinstance(path, str):
ext = os.path.splitext(path)[-1]
Expand Down Expand Up @@ -1454,7 +1456,7 @@ def __init__(
path_or_buffer,
engine: str | None = None,
storage_options: StorageOptions = None,
):
) -> None:
if engine is not None and engine not in self._engines:
raise ValueError(f"Unknown engine: {engine}")

Expand Down
2 changes: 1 addition & 1 deletion pandas/io/excel/_odfreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(
self,
filepath_or_buffer: FilePath | ReadBuffer[bytes],
storage_options: StorageOptions = None,
):
) -> None:
import_optional_dependency("odf")
super().__init__(filepath_or_buffer, storage_options=storage_options)

Expand Down
2 changes: 1 addition & 1 deletion pandas/io/excel/_odswriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(
if_sheet_exists: str | None = None,
engine_kwargs: dict[str, Any] | None = None,
**kwargs,
):
) -> None:
from odf.opendocument import OpenDocumentSpreadsheet

if mode == "a":
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/excel/_openpyxl.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(
if_sheet_exists: str | None = None,
engine_kwargs: dict[str, Any] | None = None,
**kwargs,
):
) -> None:
# Use the openpyxl module as the Excel writer.
from openpyxl.workbook import Workbook

Expand Down
2 changes: 1 addition & 1 deletion pandas/io/excel/_pyxlsb.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(
self,
filepath_or_buffer: FilePath | ReadBuffer[bytes],
storage_options: StorageOptions = None,
):
) -> None:
"""
Reader using pyxlsb engine.

Expand Down
4 changes: 3 additions & 1 deletion pandas/io/excel/_xlrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

class XlrdReader(BaseExcelReader):
@doc(storage_options=_shared_docs["storage_options"])
def __init__(self, filepath_or_buffer, storage_options: StorageOptions = None):
def __init__(
self, filepath_or_buffer, storage_options: StorageOptions = None
) -> None:
"""
Reader using xlrd engine.

Expand Down
2 changes: 1 addition & 1 deletion pandas/io/excel/_xlsxwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def __init__(
if_sheet_exists: str | None = None,
engine_kwargs: dict[str, Any] | None = None,
**kwargs,
):
) -> None:
# Use the xlsxwriter module as the Excel writer.
from xlsxwriter import Workbook

Expand Down
2 changes: 1 addition & 1 deletion pandas/io/excel/_xlwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(
if_sheet_exists: str | None = None,
engine_kwargs: dict[str, Any] | None = None,
**kwargs,
):
) -> None:
# Use the xlwt module as the Excel writer.
import xlwt

Expand Down
2 changes: 1 addition & 1 deletion pandas/io/formats/csvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(
doublequote: bool = True,
escapechar: str | None = None,
storage_options: StorageOptions = None,
):
) -> None:
self.fmt = formatter

self.obj = self.fmt.frame
Expand Down
8 changes: 4 additions & 4 deletions pandas/io/formats/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(
style=None,
mergestart: int | None = None,
mergeend: int | None = None,
):
) -> None:
self.row = row
self.col = col
self.val = val
Expand All @@ -83,7 +83,7 @@ def __init__(
css_col: int,
css_converter: Callable | None,
**kwargs,
):
) -> None:
if css_styles and css_converter:
css = ";".join(
[a + ":" + str(v) for (a, v) in css_styles[css_row, css_col]]
Expand Down Expand Up @@ -158,7 +158,7 @@ class CSSToExcelConverter:
# without monkey-patching.
inherited: dict[str, str] | None

def __init__(self, inherited: str | None = None):
def __init__(self, inherited: str | None = None) -> None:
if inherited is not None:
self.inherited = self.compute_css(inherited)
else:
Expand Down Expand Up @@ -493,7 +493,7 @@ def __init__(
merge_cells: bool = False,
inf_rep: str = "inf",
style_converter: Callable | None = None,
):
) -> None:
self.rowcounter = 0
self.na_rep = na_rep
if not isinstance(df, DataFrame):
Expand Down
24 changes: 13 additions & 11 deletions pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def __init__(
length: bool = True,
na_rep: str = "NaN",
footer: bool = True,
):
) -> None:
self.categorical = categorical
self.buf = buf if buf is not None else StringIO("")
self.na_rep = na_rep
Expand Down Expand Up @@ -274,7 +274,7 @@ def __init__(
dtype: bool = True,
max_rows: int | None = None,
min_rows: int | None = None,
):
) -> None:
self.series = series
self.buf = buf if buf is not None else StringIO()
self.name = name
Expand Down Expand Up @@ -421,7 +421,7 @@ def to_string(self) -> str:


class TextAdjustment:
def __init__(self):
def __init__(self) -> None:
self.encoding = get_option("display.encoding")

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


class EastAsianTextAdjustment(TextAdjustment):
def __init__(self):
def __init__(self) -> None:
super().__init__()
if get_option("display.unicode.ambiguous_as_wide"):
self.ambiguous_width = 2
Expand Down Expand Up @@ -578,7 +578,7 @@ def __init__(
decimal: str = ".",
bold_rows: bool = False,
escape: bool = True,
):
) -> None:
self.frame = frame
self.columns = self._initialize_columns(columns)
self.col_space = self._initialize_colspace(col_space)
Expand Down Expand Up @@ -1017,7 +1017,7 @@ class DataFrameRenderer:
Formatter with the formatting options.
"""

def __init__(self, fmt: DataFrameFormatter):
def __init__(self, fmt: DataFrameFormatter) -> None:
self.fmt = fmt

def to_latex(
Expand Down Expand Up @@ -1332,7 +1332,7 @@ def __init__(
quoting: int | None = None,
fixed_width: bool = True,
leading_space: bool | None = True,
):
) -> None:
self.values = values
self.digits = digits
self.na_rep = na_rep
Expand Down Expand Up @@ -1425,7 +1425,7 @@ def _format(x):


class FloatArrayFormatter(GenericArrayFormatter):
def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)

# float_format is expected to be a string
Expand Down Expand Up @@ -1614,7 +1614,7 @@ def __init__(
nat_rep: str = "NaT",
date_format: None = None,
**kwargs,
):
) -> None:
super().__init__(values, **kwargs)
self.nat_rep = nat_rep
self.date_format = date_format
Expand Down Expand Up @@ -1823,7 +1823,7 @@ def __init__(
nat_rep: str = "NaT",
box: bool = False,
**kwargs,
):
) -> None:
super().__init__(values, **kwargs)
self.nat_rep = nat_rep
self.box = box
Expand Down Expand Up @@ -2023,7 +2023,9 @@ class EngFormatter:
24: "Y",
}

def __init__(self, accuracy: int | None = None, use_eng_prefix: bool = False):
def __init__(
self, accuracy: int | None = None, use_eng_prefix: bool = False
) -> None:
self.accuracy = accuracy
self.use_eng_prefix = use_eng_prefix

Expand Down
16 changes: 8 additions & 8 deletions pandas/io/formats/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def __init__(
self,
data: DataFrame,
memory_usage: bool | str | None = None,
):
) -> None:
self.data: DataFrame = data
self.memory_usage = _initialize_memory_usage(memory_usage)

Expand Down Expand Up @@ -535,7 +535,7 @@ def __init__(
self,
data: Series,
memory_usage: bool | str | None = None,
):
) -> None:
self.data: Series = data
self.memory_usage = _initialize_memory_usage(memory_usage)

Expand Down Expand Up @@ -629,7 +629,7 @@ def __init__(
max_cols: int | None = None,
verbose: bool | None = None,
show_counts: bool | None = None,
):
) -> None:
self.info = info
self.data = info.data
self.verbose = verbose
Expand Down Expand Up @@ -706,7 +706,7 @@ def __init__(
info: SeriesInfo,
verbose: bool | None = None,
show_counts: bool | None = None,
):
) -> None:
self.info = info
self.data = info.data
self.verbose = verbose
Expand Down Expand Up @@ -797,7 +797,7 @@ class DataFrameTableBuilder(TableBuilderAbstract):
Instance of DataFrameInfo.
"""

def __init__(self, *, info: DataFrameInfo):
def __init__(self, *, info: DataFrameInfo) -> None:
self.info: DataFrameInfo = info

def get_lines(self) -> list[str]:
Expand Down Expand Up @@ -959,7 +959,7 @@ def __init__(
*,
info: DataFrameInfo,
with_counts: bool,
):
) -> None:
self.info = info
self.with_counts = with_counts
self.strrows: Sequence[Sequence[str]] = list(self._gen_rows())
Expand Down Expand Up @@ -1025,7 +1025,7 @@ class SeriesTableBuilder(TableBuilderAbstract):
Instance of SeriesInfo.
"""

def __init__(self, *, info: SeriesInfo):
def __init__(self, *, info: SeriesInfo) -> None:
self.info: SeriesInfo = info

def get_lines(self) -> list[str]:
Expand Down Expand Up @@ -1071,7 +1071,7 @@ def __init__(
*,
info: SeriesInfo,
with_counts: bool,
):
) -> None:
self.info = info
self.with_counts = with_counts
self.strrows: Sequence[Sequence[str]] = list(self._gen_rows())
Expand Down
6 changes: 3 additions & 3 deletions pandas/io/formats/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __init__(
multicolumn: bool = False,
multicolumn_format: str | None = None,
multirow: bool = False,
):
) -> None:
self.fmt = formatter
self.frame = self.fmt.frame
self.multicolumn = multicolumn
Expand Down Expand Up @@ -336,7 +336,7 @@ def __init__(
short_caption: str | None = None,
label: str | None = None,
position: str | None = None,
):
) -> None:
self.fmt = formatter
self.column_format = column_format
self.multicolumn = multicolumn
Expand Down Expand Up @@ -697,7 +697,7 @@ def __init__(
caption: str | tuple[str, str] | None = None,
label: str | None = None,
position: str | None = None,
):
) -> None:
self.fmt = formatter
self.frame = self.fmt.frame
self.longtable = longtable
Expand Down
Loading