Skip to content

Commit 2cbd317

Browse files
TYP: added missing __init__ in pandas/core/methods (#51052)
* TYP: added missing __init__ in pandas/core/methods * fix most typing issues * use Sequence[Hashable] more consistenly --------- Co-authored-by: Matthew Roeschke <[email protected]>
1 parent bec92a4 commit 2cbd317

File tree

8 files changed

+20
-13
lines changed

8 files changed

+20
-13
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ repos:
135135
types: [python]
136136
stages: [manual]
137137
additional_dependencies: &pyright_dependencies
138-
138+
139139
- id: pyright_reportGeneralTypeIssues
140140
# note: assumes python env is setup and activated
141141
name: pyright reportGeneralTypeIssues

pandas/_testing/contexts.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
)
1212
import uuid
1313

14+
from pandas._typing import (
15+
BaseBuffer,
16+
CompressionOptions,
17+
FilePath,
18+
)
1419
from pandas.compat import PYPY
1520
from pandas.errors import ChainedAssignmentError
1621

@@ -20,7 +25,9 @@
2025

2126

2227
@contextmanager
23-
def decompress_file(path, compression) -> Generator[IO[bytes], None, None]:
28+
def decompress_file(
29+
path: FilePath | BaseBuffer, compression: CompressionOptions
30+
) -> Generator[IO[bytes], None, None]:
2431
"""
2532
Open a compressed file and return a file object.
2633

pandas/core/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9542,7 +9542,7 @@ def _append(
95429542

95439543
def join(
95449544
self,
9545-
other: DataFrame | Series | list[DataFrame | Series],
9545+
other: DataFrame | Series | Iterable[DataFrame | Series],
95469546
on: IndexLabel | None = None,
95479547
how: MergeHow = "left",
95489548
lsuffix: str = "",

pandas/core/methods/__init__.py

Whitespace-only changes.

pandas/core/window/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def flex_binary_moment(arg1, arg2, f, pairwise: bool = False):
2323
elif isinstance(arg1, ABCDataFrame):
2424
from pandas import DataFrame
2525

26-
def dataframe_from_int_dict(data, frame_template):
26+
def dataframe_from_int_dict(data, frame_template) -> DataFrame:
2727
result = DataFrame(data, index=frame_template.index)
2828
if len(result.columns) > 0:
2929
result.columns = frame_template.columns[result.columns]

pandas/io/parsers/base_parser.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ class BadLineHandleMethod(Enum):
106106
def __init__(self, kwds) -> None:
107107

108108
self.names = kwds.get("names")
109-
self.orig_names: list | None = None
109+
self.orig_names: Sequence[Hashable] | None = None
110110

111111
self.index_col = kwds.get("index_col", None)
112112
self.unnamed_cols: set = set()
113113
self.index_names: Sequence[Hashable] | None = None
114-
self.col_names = None
114+
self.col_names: Sequence[Hashable] | None = None
115115

116116
self.parse_dates = _validate_parse_dates_arg(kwds.pop("parse_dates", False))
117117
self._parse_date_cols: Iterable = []
@@ -269,9 +269,11 @@ def _should_parse_dates(self, i: int) -> bool:
269269
def _extract_multi_indexer_columns(
270270
self,
271271
header,
272-
index_names: list | None,
272+
index_names: Sequence[Hashable] | None,
273273
passed_names: bool = False,
274-
):
274+
) -> tuple[
275+
Sequence[Hashable], Sequence[Hashable] | None, Sequence[Hashable] | None, bool
276+
]:
275277
"""
276278
Extract and return the names, index_names, col_names if the column
277279
names are a MultiIndex.
@@ -1004,7 +1006,7 @@ def _validate_usecols_arg(self, usecols):
10041006
return usecols, usecols_dtype
10051007
return usecols, None
10061008

1007-
def _clean_index_names(self, columns, index_col):
1009+
def _clean_index_names(self, columns, index_col) -> tuple[list | None, list, list]:
10081010
if not is_index_col(index_col):
10091011
return None, columns, index_col
10101012

pandas/io/parsers/c_parser_wrapper.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ def __init__(self, src: ReadCsvBuffer[str], **kwds) -> None:
104104

105105
# error: Cannot determine type of 'names'
106106
if self.names is None: # type: ignore[has-type]
107-
# error: Cannot determine type of 'names'
108-
self.names = list(range(self._reader.table_width)) # type: ignore[has-type]
107+
self.names = list(range(self._reader.table_width))
109108

110109
# gh-9755
111110
#

pandas/io/parsers/python_parser.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ def __init__(self, f: ReadCsvBuffer[str] | list, **kwds) -> None:
126126
# Now self.columns has the set of columns that we will process.
127127
# The original set is stored in self.original_columns.
128128
# error: Cannot determine type of 'index_names'
129-
self.columns: list[Hashable]
130129
(
131130
self.columns,
132131
self.index_names,
@@ -915,7 +914,7 @@ def _clear_buffer(self) -> None:
915914
_implicit_index = False
916915

917916
def _get_index_name(
918-
self, columns: list[Hashable]
917+
self, columns: Sequence[Hashable]
919918
) -> tuple[Sequence[Hashable] | None, list[Hashable], list[Hashable]]:
920919
"""
921920
Try several cases to get lines:

0 commit comments

Comments
 (0)