Skip to content

Commit 482d66f

Browse files
authored
TYP: misc typing in _libs (#44349)
1 parent b8d5e9c commit 482d66f

File tree

6 files changed

+48
-30
lines changed

6 files changed

+48
-30
lines changed

pandas/_libs/join.pyi

+6-6
Original file line numberDiff line numberDiff line change
@@ -55,39 +55,39 @@ def asof_join_backward_on_X_by_Y(
5555
left_by_values: np.ndarray, # by_t[:]
5656
right_by_values: np.ndarray, # by_t[:]
5757
allow_exact_matches: bool = ...,
58-
tolerance=...,
58+
tolerance: np.number | int | float | None = ...,
5959
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
6060
def asof_join_forward_on_X_by_Y(
6161
left_values: np.ndarray, # asof_t[:]
6262
right_values: np.ndarray, # asof_t[:]
6363
left_by_values: np.ndarray, # by_t[:]
6464
right_by_values: np.ndarray, # by_t[:]
6565
allow_exact_matches: bool = ...,
66-
tolerance=...,
66+
tolerance: np.number | int | float | None = ...,
6767
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
6868
def asof_join_nearest_on_X_by_Y(
6969
left_values: np.ndarray, # asof_t[:]
7070
right_values: np.ndarray, # asof_t[:]
7171
left_by_values: np.ndarray, # by_t[:]
7272
right_by_values: np.ndarray, # by_t[:]
7373
allow_exact_matches: bool = ...,
74-
tolerance=...,
74+
tolerance: np.number | int | float | None = ...,
7575
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
7676
def asof_join_backward(
7777
left_values: np.ndarray, # asof_t[:]
7878
right_values: np.ndarray, # asof_t[:]
7979
allow_exact_matches: bool = ...,
80-
tolerance=...,
80+
tolerance: np.number | int | float | None = ...,
8181
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
8282
def asof_join_forward(
8383
left_values: np.ndarray, # asof_t[:]
8484
right_values: np.ndarray, # asof_t[:]
8585
allow_exact_matches: bool = ...,
86-
tolerance=...,
86+
tolerance: np.number | int | float | None = ...,
8787
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
8888
def asof_join_nearest(
8989
left_values: np.ndarray, # asof_t[:]
9090
right_values: np.ndarray, # asof_t[:]
9191
allow_exact_matches: bool = ...,
92-
tolerance=...,
92+
tolerance: np.number | int | float | None = ...,
9393
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...

pandas/_libs/ops.pyi

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import (
22
Any,
33
Callable,
4+
Iterable,
45
Literal,
56
overload,
67
)
@@ -35,15 +36,15 @@ def vec_binop(
3536
@overload
3637
def maybe_convert_bool(
3738
arr: npt.NDArray[np.object_],
38-
true_values=...,
39-
false_values=...,
39+
true_values: Iterable = ...,
40+
false_values: Iterable = ...,
4041
convert_to_masked_nullable: Literal[False] = ...,
4142
) -> tuple[np.ndarray, None]: ...
4243
@overload
4344
def maybe_convert_bool(
4445
arr: npt.NDArray[np.object_],
45-
true_values=...,
46-
false_values=...,
46+
true_values: Iterable = ...,
47+
false_values: Iterable = ...,
4748
*,
4849
convert_to_masked_nullable: Literal[True],
4950
) -> tuple[np.ndarray, np.ndarray]: ...

pandas/_libs/tslibs/fields.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def month_position_check(fields, weekdays) -> str | None: ...
99
def get_date_name_field(
1010
dtindex: npt.NDArray[np.int64], # const int64_t[:]
1111
field: str,
12-
locale=...,
12+
locale: str | None = ...,
1313
) -> npt.NDArray[np.object_]: ...
1414
def get_start_end_field(
1515
dtindex: npt.NDArray[np.int64], # const int64_t[:]
@@ -31,7 +31,7 @@ def isleapyear_arr(
3131
def build_isocalendar_sarray(
3232
dtindex: npt.NDArray[np.int64], # const int64_t[:]
3333
) -> np.ndarray: ...
34-
def get_locale_names(name_type: str, locale: object = ...): ...
34+
def get_locale_names(name_type: str, locale: str | None = ...): ...
3535

3636
class RoundTo:
3737
@property

pandas/_libs/tslibs/nattype.pyi

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from datetime import (
22
datetime,
33
timedelta,
4+
tzinfo as _tzinfo,
45
)
56
from typing import Any
67

@@ -19,7 +20,7 @@ class NaTType(datetime):
1920
def asm8(self) -> np.datetime64: ...
2021
def to_datetime64(self) -> np.datetime64: ...
2122
def to_numpy(
22-
self, dtype=..., copy: bool = ...
23+
self, dtype: np.dtype | str | None = ..., copy: bool = ...
2324
) -> np.datetime64 | np.timedelta64: ...
2425
@property
2526
def is_leap_year(self) -> bool: ...
@@ -71,7 +72,20 @@ class NaTType(datetime):
7172
def ceil(self) -> NaTType: ...
7273
def tz_convert(self) -> NaTType: ...
7374
def tz_localize(self) -> NaTType: ...
74-
def replace(self, *args, **kwargs) -> NaTType: ...
75+
# error: Signature of "replace" incompatible with supertype "datetime"
76+
def replace( # type: ignore[override]
77+
self,
78+
year: int | None = ...,
79+
month: int | None = ...,
80+
day: int | None = ...,
81+
hour: int | None = ...,
82+
minute: int | None = ...,
83+
second: int | None = ...,
84+
microsecond: int | None = ...,
85+
nanosecond: int | None = ...,
86+
tzinfo: _tzinfo | None = ...,
87+
fold: int | None = ...,
88+
) -> NaTType: ...
7589
# error: Return type "float" of "year" incompatible with return
7690
# type "int" in supertype "date"
7791
@property

pandas/_libs/tslibs/period.pyi

+11-11
Original file line numberDiff line numberDiff line change
@@ -59,30 +59,30 @@ class Period:
5959
def __new__( # type: ignore[misc]
6060
cls,
6161
value=...,
62-
freq=...,
63-
ordinal=...,
64-
year=...,
65-
month=...,
66-
quarter=...,
67-
day=...,
68-
hour=...,
69-
minute=...,
70-
second=...,
62+
freq: int | str | None = ...,
63+
ordinal: int | None = ...,
64+
year: int | None = ...,
65+
month: int | None = ...,
66+
quarter: int | None = ...,
67+
day: int | None = ...,
68+
hour: int | None = ...,
69+
minute: int | None = ...,
70+
second: int | None = ...,
7171
) -> Period | NaTType: ...
7272
@classmethod
7373
def _maybe_convert_freq(cls, freq) -> BaseOffset: ...
7474
@classmethod
7575
def _from_ordinal(cls, ordinal: int, freq) -> Period: ...
7676
@classmethod
77-
def now(cls, freq=...) -> Period: ...
77+
def now(cls, freq: BaseOffset = ...) -> Period: ...
7878
def strftime(self, fmt: str) -> str: ...
7979
def to_timestamp(
8080
self,
8181
freq: str | BaseOffset | None = ...,
8282
how: str = ...,
8383
tz: Timezone | None = ...,
8484
) -> Timestamp: ...
85-
def asfreq(self, freq, how=...) -> Period: ...
85+
def asfreq(self, freq: str, how: str = ...) -> Period: ...
8686
@property
8787
def freqstr(self) -> str: ...
8888
@property

pandas/_libs/tslibs/timedeltas.pyi

+8-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ from pandas._libs.tslibs import (
1414
)
1515
from pandas._typing import npt
1616

17-
_S = TypeVar("_S")
17+
_S = TypeVar("_S", bound=timedelta)
1818

1919
def ints_to_pytimedelta(
2020
arr: npt.NDArray[np.int64], # const int64_t[:]
@@ -36,7 +36,10 @@ class Timedelta(timedelta):
3636

3737
# error: "__new__" must return a class instance (got "Union[Timedelta, NaTType]")
3838
def __new__( # type: ignore[misc]
39-
cls: Type[_S], value=..., unit=..., **kwargs
39+
cls: Type[_S],
40+
value=...,
41+
unit: str = ...,
42+
**kwargs: int | float | np.integer | np.floating,
4043
) -> _S | NaTType: ...
4144
@property
4245
def days(self) -> int: ...
@@ -50,9 +53,9 @@ class Timedelta(timedelta):
5053
@property
5154
def asm8(self) -> np.timedelta64: ...
5255
# TODO: round/floor/ceil could return NaT?
53-
def round(self: _S, freq) -> _S: ...
54-
def floor(self: _S, freq) -> _S: ...
55-
def ceil(self: _S, freq) -> _S: ...
56+
def round(self: _S, freq: str) -> _S: ...
57+
def floor(self: _S, freq: str) -> _S: ...
58+
def ceil(self: _S, freq: str) -> _S: ...
5659
@property
5760
def resolution_string(self) -> str: ...
5861
def __add__(self, other: timedelta) -> timedelta: ...

0 commit comments

Comments
 (0)