diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c5c5cc09a0e7a..dfbd24767a189 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -135,7 +135,7 @@ repos: types: [python] stages: [manual] additional_dependencies: &pyright_dependencies - - pyright@1.1.276 + - pyright@1.1.284 - id: pyright_reportGeneralTypeIssues # note: assumes python env is setup and activated name: pyright reportGeneralTypeIssues diff --git a/pandas/_testing/contexts.py b/pandas/_testing/contexts.py index 1a6f78171bcef..6a1f5f83b6af2 100644 --- a/pandas/_testing/contexts.py +++ b/pandas/_testing/contexts.py @@ -11,6 +11,11 @@ ) import uuid +from pandas._typing import ( + BaseBuffer, + CompressionOptions, + FilePath, +) from pandas.compat import PYPY from pandas.errors import ChainedAssignmentError @@ -20,7 +25,9 @@ @contextmanager -def decompress_file(path, compression) -> Generator[IO[bytes], None, None]: +def decompress_file( + path: FilePath | BaseBuffer, compression: CompressionOptions +) -> Generator[IO[bytes], None, None]: """ Open a compressed file and return a file object. diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 69c2476681021..01f4fcfb56cbc 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -9540,7 +9540,7 @@ def _append( def join( self, - other: DataFrame | Series | list[DataFrame | Series], + other: DataFrame | Series | Iterable[DataFrame | Series], on: IndexLabel | None = None, how: MergeHow = "left", lsuffix: str = "", diff --git a/pandas/core/methods/__init__.py b/pandas/core/methods/__init__.py new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/pandas/core/window/common.py b/pandas/core/window/common.py index ff1c3c1784bd6..51d9f70c1d018 100644 --- a/pandas/core/window/common.py +++ b/pandas/core/window/common.py @@ -23,7 +23,7 @@ def flex_binary_moment(arg1, arg2, f, pairwise: bool = False): elif isinstance(arg1, ABCDataFrame): from pandas import DataFrame - def dataframe_from_int_dict(data, frame_template): + def dataframe_from_int_dict(data, frame_template) -> DataFrame: result = DataFrame(data, index=frame_template.index) if len(result.columns) > 0: result.columns = frame_template.columns[result.columns] diff --git a/pandas/io/parsers/base_parser.py b/pandas/io/parsers/base_parser.py index 6272f213ccef1..6d2f569ddb753 100644 --- a/pandas/io/parsers/base_parser.py +++ b/pandas/io/parsers/base_parser.py @@ -106,12 +106,12 @@ class BadLineHandleMethod(Enum): def __init__(self, kwds) -> None: self.names = kwds.get("names") - self.orig_names: list | None = None + self.orig_names: Sequence[Hashable] | None = None self.index_col = kwds.get("index_col", None) self.unnamed_cols: set = set() self.index_names: Sequence[Hashable] | None = None - self.col_names = None + self.col_names: Sequence[Hashable] | None = None self.parse_dates = _validate_parse_dates_arg(kwds.pop("parse_dates", False)) self._parse_date_cols: Iterable = [] @@ -269,9 +269,11 @@ def _should_parse_dates(self, i: int) -> bool: def _extract_multi_indexer_columns( self, header, - index_names: list | None, + index_names: Sequence[Hashable] | None, passed_names: bool = False, - ): + ) -> tuple[ + Sequence[Hashable], Sequence[Hashable] | None, Sequence[Hashable] | None, bool + ]: """ Extract and return the names, index_names, col_names if the column names are a MultiIndex. @@ -1004,7 +1006,7 @@ def _validate_usecols_arg(self, usecols): return usecols, usecols_dtype return usecols, None - def _clean_index_names(self, columns, index_col): + def _clean_index_names(self, columns, index_col) -> tuple[list | None, list, list]: if not is_index_col(index_col): return None, columns, index_col diff --git a/pandas/io/parsers/c_parser_wrapper.py b/pandas/io/parsers/c_parser_wrapper.py index 551518b623836..dbc7658e11631 100644 --- a/pandas/io/parsers/c_parser_wrapper.py +++ b/pandas/io/parsers/c_parser_wrapper.py @@ -104,8 +104,7 @@ def __init__(self, src: ReadCsvBuffer[str], **kwds) -> None: # error: Cannot determine type of 'names' if self.names is None: # type: ignore[has-type] - # error: Cannot determine type of 'names' - self.names = list(range(self._reader.table_width)) # type: ignore[has-type] + self.names = list(range(self._reader.table_width)) # gh-9755 # diff --git a/pandas/io/parsers/python_parser.py b/pandas/io/parsers/python_parser.py index e97aac82a50ff..62a4e80147780 100644 --- a/pandas/io/parsers/python_parser.py +++ b/pandas/io/parsers/python_parser.py @@ -126,7 +126,6 @@ def __init__(self, f: ReadCsvBuffer[str] | list, **kwds) -> None: # Now self.columns has the set of columns that we will process. # The original set is stored in self.original_columns. # error: Cannot determine type of 'index_names' - self.columns: list[Hashable] ( self.columns, self.index_names, @@ -915,7 +914,7 @@ def _clear_buffer(self) -> None: _implicit_index = False def _get_index_name( - self, columns: list[Hashable] + self, columns: Sequence[Hashable] ) -> tuple[Sequence[Hashable] | None, list[Hashable], list[Hashable]]: """ Try several cases to get lines: