From 3244a0802ea87e37f207592a4c5a69ab0587f0ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Sun, 17 Jul 2022 10:13:42 -0400 Subject: [PATCH 1/3] TYP: a few mismatches found by stubtest --- pandas/_libs/algos.pyi | 2 +- pandas/_libs/groupby.pyi | 16 +++++++++++++--- pandas/_libs/internals.pyi | 2 +- pandas/_libs/join.pyi | 21 +++------------------ pandas/_libs/missing.pyi | 3 ++- pandas/_libs/parsers.pyi | 1 - 6 files changed, 20 insertions(+), 25 deletions(-) diff --git a/pandas/_libs/algos.pyi b/pandas/_libs/algos.pyi index 0cc9209fbdfc5..24942fc8ad5af 100644 --- a/pandas/_libs/algos.pyi +++ b/pandas/_libs/algos.pyi @@ -42,7 +42,7 @@ def groupsort_indexer( np.ndarray, # ndarray[int64_t, ndim=1] ]: ... def kth_smallest( - a: np.ndarray, # numeric[:] + arr: np.ndarray, # numeric[:] k: int, ) -> Any: ... # numeric diff --git a/pandas/_libs/groupby.pyi b/pandas/_libs/groupby.pyi index 2f0c3980c0c02..c7cb9705d7cb9 100644 --- a/pandas/_libs/groupby.pyi +++ b/pandas/_libs/groupby.pyi @@ -105,8 +105,9 @@ def group_last( values: np.ndarray, # ndarray[rank_t, ndim=2] labels: np.ndarray, # const int64_t[:] mask: npt.NDArray[np.bool_] | None, - result_mask: npt.NDArray[np.bool_] | None, + result_mask: npt.NDArray[np.bool_] | None = ..., min_count: int = ..., # Py_ssize_t + is_datetimelike: bool = ..., ) -> None: ... def group_nth( out: np.ndarray, # rank_t[:, ::1] @@ -114,9 +115,10 @@ def group_nth( values: np.ndarray, # ndarray[rank_t, ndim=2] labels: np.ndarray, # const int64_t[:] mask: npt.NDArray[np.bool_] | None, - result_mask: npt.NDArray[np.bool_] | None, + result_mask: npt.NDArray[np.bool_] | None = ..., min_count: int = ..., # int64_t rank: int = ..., # int64_t + is_datetimelike: bool = ..., ) -> None: ... def group_rank( out: np.ndarray, # float64_t[:, ::1] @@ -124,7 +126,7 @@ def group_rank( labels: np.ndarray, # const int64_t[:] ngroups: int, is_datetimelike: bool, - ties_method: Literal["aveage", "min", "max", "first", "dense"] = ..., + ties_method: Literal["average", "min", "max", "first", "dense"] = ..., ascending: bool = ..., pct: bool = ..., na_option: Literal["keep", "top", "bottom"] = ..., @@ -136,6 +138,7 @@ def group_max( values: np.ndarray, # ndarray[groupby_t, ndim=2] labels: np.ndarray, # const int64_t[:] min_count: int = ..., + is_datetimelike: bool = ..., mask: np.ndarray | None = ..., result_mask: np.ndarray | None = ..., ) -> None: ... @@ -145,6 +148,7 @@ def group_min( values: np.ndarray, # ndarray[groupby_t, ndim=2] labels: np.ndarray, # const int64_t[:] min_count: int = ..., + is_datetimelike: bool = ..., mask: np.ndarray | None = ..., result_mask: np.ndarray | None = ..., ) -> None: ... @@ -154,6 +158,9 @@ def group_cummin( labels: np.ndarray, # const int64_t[:] ngroups: int, is_datetimelike: bool, + mask: np.ndarray | None = ..., + result_mask: np.ndarray | None = ..., + skipna: bool = ..., ) -> None: ... def group_cummax( out: np.ndarray, # groupby_t[:, ::1] @@ -161,4 +168,7 @@ def group_cummax( labels: np.ndarray, # const int64_t[:] ngroups: int, is_datetimelike: bool, + mask: np.ndarray | None = ..., + result_mask: np.ndarray | None = ..., + skipna: bool = ..., ) -> None: ... diff --git a/pandas/_libs/internals.pyi b/pandas/_libs/internals.pyi index 6a90fbc729580..201c7b7b565cc 100644 --- a/pandas/_libs/internals.pyi +++ b/pandas/_libs/internals.pyi @@ -32,7 +32,7 @@ def update_blklocs_and_blknos( loc: int, nblocks: int, ) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ... - +@final class BlockPlacement: def __init__(self, val: int | slice | np.ndarray): ... @property diff --git a/pandas/_libs/join.pyi b/pandas/_libs/join.pyi index a5e91e2ce83eb..8d02f8f57dee1 100644 --- a/pandas/_libs/join.pyi +++ b/pandas/_libs/join.pyi @@ -56,6 +56,7 @@ def asof_join_backward_on_X_by_Y( right_by_values: np.ndarray, # by_t[:] allow_exact_matches: bool = ..., tolerance: np.number | int | float | None = ..., + use_hashtable: bool = ..., ) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ... def asof_join_forward_on_X_by_Y( left_values: np.ndarray, # asof_t[:] @@ -64,6 +65,7 @@ def asof_join_forward_on_X_by_Y( right_by_values: np.ndarray, # by_t[:] allow_exact_matches: bool = ..., tolerance: np.number | int | float | None = ..., + use_hashtable: bool = ..., ) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ... def asof_join_nearest_on_X_by_Y( left_values: np.ndarray, # asof_t[:] @@ -72,22 +74,5 @@ def asof_join_nearest_on_X_by_Y( right_by_values: np.ndarray, # by_t[:] allow_exact_matches: bool = ..., tolerance: np.number | int | float | None = ..., -) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ... -def asof_join_backward( - left_values: np.ndarray, # asof_t[:] - right_values: np.ndarray, # asof_t[:] - allow_exact_matches: bool = ..., - tolerance: np.number | int | float | None = ..., -) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ... -def asof_join_forward( - left_values: np.ndarray, # asof_t[:] - right_values: np.ndarray, # asof_t[:] - allow_exact_matches: bool = ..., - tolerance: np.number | int | float | None = ..., -) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ... -def asof_join_nearest( - left_values: np.ndarray, # asof_t[:] - right_values: np.ndarray, # asof_t[:] - allow_exact_matches: bool = ..., - tolerance: np.number | int | float | None = ..., + use_hashtable: bool = ..., ) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ... diff --git a/pandas/_libs/missing.pyi b/pandas/_libs/missing.pyi index 3a4cc9def07bd..27f227558dee5 100644 --- a/pandas/_libs/missing.pyi +++ b/pandas/_libs/missing.pyi @@ -1,7 +1,8 @@ import numpy as np from numpy import typing as npt -class NAType: ... +class NAType: + def __new__(cls, *args, **kwargs): ... NA: NAType diff --git a/pandas/_libs/parsers.pyi b/pandas/_libs/parsers.pyi index 01f5d5802ccd5..6b0bbf183f07e 100644 --- a/pandas/_libs/parsers.pyi +++ b/pandas/_libs/parsers.pyi @@ -63,7 +63,6 @@ class TextReader: skip_blank_lines: bool = ..., encoding_errors: bytes | str = ..., ): ... - def set_error_bad_lines(self, status: int) -> None: ... def set_noconvert(self, i: int) -> None: ... def remove_noconvert(self, i: int) -> None: ... def close(self) -> None: ... From 8097226bbe626a4b0a7afb4ed0d2a028d3d2ca9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Sun, 17 Jul 2022 13:09:07 -0400 Subject: [PATCH 2/3] a few more --- pandas/_libs/tslibs/ccalendar.pyi | 2 -- pandas/_libs/tslibs/dtypes.pyi | 2 ++ pandas/_libs/tslibs/nattype.pyi | 3 +-- pandas/_libs/tslibs/offsets.pyi | 1 + pandas/_libs/tslibs/timezones.pyi | 3 --- 5 files changed, 4 insertions(+), 7 deletions(-) diff --git a/pandas/_libs/tslibs/ccalendar.pyi b/pandas/_libs/tslibs/ccalendar.pyi index 5d5b935ffa54b..993f18a61d74a 100644 --- a/pandas/_libs/tslibs/ccalendar.pyi +++ b/pandas/_libs/tslibs/ccalendar.pyi @@ -8,7 +8,5 @@ def get_firstbday(year: int, month: int) -> int: ... def get_lastbday(year: int, month: int) -> int: ... def get_day_of_year(year: int, month: int, day: int) -> int: ... def get_iso_calendar(year: int, month: int, day: int) -> tuple[int, int, int]: ... -def is_leapyear(year: int) -> bool: ... def get_week_of_year(year: int, month: int, day: int) -> int: ... def get_days_in_month(year: int, month: int) -> int: ... -def dayofweek(y: int, m: int, d: int) -> int: ... diff --git a/pandas/_libs/tslibs/dtypes.pyi b/pandas/_libs/tslibs/dtypes.pyi index dd439ebfc4798..041c51533d8da 100644 --- a/pandas/_libs/tslibs/dtypes.pyi +++ b/pandas/_libs/tslibs/dtypes.pyi @@ -14,10 +14,12 @@ class PeriodDtypeBase: # actually __cinit__ def __new__(cls, code: int): ... + @property def _freq_group_code(self) -> int: ... @property def _resolution_obj(self) -> Resolution: ... def _get_to_timestamp_base(self) -> int: ... + @property def _freqstr(self) -> str: ... class FreqGroup(Enum): diff --git a/pandas/_libs/tslibs/nattype.pyi b/pandas/_libs/tslibs/nattype.pyi index e5a7e0223e534..0aa80330b15bc 100644 --- a/pandas/_libs/tslibs/nattype.pyi +++ b/pandas/_libs/tslibs/nattype.pyi @@ -12,8 +12,6 @@ NaT: NaTType iNaT: int nat_strings: set[str] -def is_null_datetimelike(val: object, inat_is_null: bool = ...) -> bool: ... - _NaTComparisonTypes = datetime | timedelta | Period | np.datetime64 | np.timedelta64 class _NatComparison: @@ -21,6 +19,7 @@ class _NatComparison: class NaTType: value: np.int64 + @property def asm8(self) -> np.datetime64: ... def to_datetime64(self) -> np.datetime64: ... def to_numpy( diff --git a/pandas/_libs/tslibs/offsets.pyi b/pandas/_libs/tslibs/offsets.pyi index 12b113f0b73b1..1fe92e2870400 100644 --- a/pandas/_libs/tslibs/offsets.pyi +++ b/pandas/_libs/tslibs/offsets.pyi @@ -80,6 +80,7 @@ class BaseOffset: def name(self) -> str: ... @property def rule_code(self) -> str: ... + @property def freqstr(self) -> str: ... def apply_index(self, dtindex: DatetimeIndex) -> DatetimeIndex: ... def _apply_array(self, dtarr) -> None: ... diff --git a/pandas/_libs/tslibs/timezones.pyi b/pandas/_libs/tslibs/timezones.pyi index 20c403e93b149..a2a8ef86f2d8d 100644 --- a/pandas/_libs/tslibs/timezones.pyi +++ b/pandas/_libs/tslibs/timezones.pyi @@ -17,9 +17,6 @@ def infer_tzinfo( start: datetime | None, end: datetime | None, ) -> tzinfo | None: ... -def get_dst_info( - tz: tzinfo, -) -> tuple[npt.NDArray[np.int64], npt.NDArray[np.int64], str]: ... def maybe_get_tz(tz: str | int | np.int64 | tzinfo | None) -> tzinfo | None: ... def get_timezone(tz: tzinfo) -> tzinfo | str: ... def is_utc(tz: tzinfo | None) -> bool: ... From d736a799065d675f9a94741749a3dda5e5cb995e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Sun, 17 Jul 2022 13:21:41 -0400 Subject: [PATCH 3/3] flake8 --- pandas/_libs/tslibs/timezones.pyi | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas/_libs/tslibs/timezones.pyi b/pandas/_libs/tslibs/timezones.pyi index a2a8ef86f2d8d..d241a35f21cca 100644 --- a/pandas/_libs/tslibs/timezones.pyi +++ b/pandas/_libs/tslibs/timezones.pyi @@ -6,8 +6,6 @@ from typing import Callable import numpy as np -from pandas._typing import npt - # imported from dateutil.tz dateutil_gettz: Callable[[str], tzinfo]