8000 TYP,WIP: Try to fix up the typing for datetime/timedelta promotion de… · numpy/numpy@de6293d · GitHub
[go: up one dir, main page]

Skip to content

Commit de6293d

Browse files
committed
TYP,WIP: Try to fix up the typing for datetime/timedelta promotion deprecation
1 parent 7559adc commit de6293d

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

numpy/__init__.pyi

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ from numpy._typing import (
3232
_ArrayLikeComplex_co,
3333
_ArrayLikeNumber_co,
3434
_ArrayLikeTD64_co,
35+
_ArrayLikeTD64_comp_co,
3536
_ArrayLikeDT64_co,
3637
_ArrayLikeObject_co,
3738
_ArrayLikeStr_co,
@@ -1853,7 +1854,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
18531854
@overload
18541855
def __lt__(self: _ArrayNumber_co, other: _ArrayLikeNumber_co) -> NDArray[bool_]: ...
18551856
@overload
1856-
def __lt__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co) -> NDArray[bool_]: ...
1857+
def __lt__(self: _ArrayTD64_co, other: _ArrayLikeTD64_comp_co) -> NDArray[bool_]: ...
18571858
@overload
18581859
def __lt__(self: NDArray[datetime64], other: _ArrayLikeDT64_co) -> NDArray[bool_]: ...
18591860
@overload
@@ -1864,7 +1865,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
18641865
@overload
18651866
def __le__(self: _ArrayNumber_co, other: _ArrayLikeNumber_co) -> NDArray[bool_]: ...
18661867
@overload
1867-
def __le__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co) -> NDArray[bool_]: ...
1868+
def __le__(self: _ArrayTD64_co, other: _ArrayLikeTD64_comp_co) -> NDArray[bool_]: ...
18681869
@overload
18691870
def __le__(self: NDArray[datetime64], other: _ArrayLikeDT64_co) -> NDArray[bool_]: ...
18701871
@overload
@@ -1875,7 +1876,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
18751876
@overload
18761877
def __gt__(self: _ArrayNumber_co, other: _ArrayLikeNumber_co) -> NDArray[bool_]: ...
18771878
@overload
1878-
def __gt__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co) -> NDArray[bool_]: ...
1879+
def __gt__(self: _ArrayTD64_co, other: _ArrayLikeTD64_comp_co) -> NDArray[bool_]: ...
18791880
@overload
18801881
def __gt__(self: NDArray[datetime64], other: _ArrayLikeDT64_co) -> NDArray[bool_]: ...
18811882
@overload
@@ -1886,7 +1887,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
18861887
@overload
18871888
def __ge__(self: _ArrayNumber_co, other: _ArrayLikeNumber_co) -> NDArray[bool_]: ...
18881889
@overload
1889-
def __ge__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co) -> NDArray[bool_]: ...
1890+
def __ge__(self: _ArrayTD64_co, other: _ArrayLikeTD64_comp_co) -> NDArray[bool_]: ...
18901891
@overload
18911892
def __ge__(self: NDArray[datetime64], other: _ArrayLikeDT64_co) -> NDArray[bool_]: ...
18921893
@overload
@@ -2919,10 +2920,10 @@ class timedelta64(generic):
29192920
def __rmod__(self, other: timedelta64) -> timedelta64: ...
29202921
def __divmod__(self, other: timedelta64) -> tuple[int64, timedelta64]: ...
29212922
def __rdivmod__(self, other: timedelta64) -> tuple[int64, timedelta64]: ...
2922-
__lt__: _ComparisonOp[_TD64Like_co, _ArrayLikeTD64_co]
2923-
__le__: _ComparisonOp[_TD64Like_co, _ArrayLikeTD64_co]
2924-
__gt__: _ComparisonOp[_TD64Like_co, _ArrayLikeTD64_co]
2925-
__ge__: _ComparisonOp[_TD64Like_co, _ArrayLikeTD64_co]
2923+
__lt__: _ComparisonOp[_TD64Like_co, _ArrayLikeTD64_comp_co]
2924+
__le__: _ComparisonOp[_TD64Like_co, _ArrayLikeTD64_comp_co]
2925+
__gt__: _ComparisonOp[_TD64Like_co, _ArrayLikeTD64_comp_co]
2926+
__ge__: _ComparisonOp[_TD64Like_co, _ArrayLikeTD64_comp_co]
29262927

29272928
class unsignedinteger(integer[_NBit1]):
29282929
# NOTE: `uint64 + signedinteger -> float64`

numpy/_typing/_array_like.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ def __array_function__(
117117
"dtype[Union[bool_, integer[Any], timedelta64]]",
118118
Union[bool, int],
119119
]
120+
_ArrayLikeTD64_comp_co = Union[
121+
_SupportsArray["dtype[timedelta64]"],
122+
_NestedSequence[_SupportsArray["dtype[timedelta64]"]],
123+
]
124+
120125
_ArrayLikeDT64_co = Union[
121126
_SupportsArray["dtype[datetime64]"],
122127
_NestedSequence[_SupportsArray["dtype[datetime64]"]],

numpy/typing/tests/data/fail/comparisons.pyi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Any
22
import numpy as np
33

4+
AR_b: np.ndarray[Any, np.dtype[np.bool_]]
45
AR_i: np.ndarray[Any, np.dtype[np.int64]]
56
AR_f: np.ndarray[Any, np.dtype[np.float64]]
67
AR_c: np.ndarray[Any, np.dtype[np.complex128]]
@@ -21,6 +22,11 @@ AR_M > AR_i # E: Unsupported operand types
2122
AR_M > AR_f # E: Unsupported operand types
2223
AR_M > AR_m # E: Unsupported operand types
2324

25+
AR_m > AR_b # E: Unsupported operand types
26+
AR_m > AR_i # E: Unsupported operand types
27+
AR_b > AR_m # E: Unsupported operand types
28+
AR_i > AR_m # E: Unsupported operand types
29+
2430
AR_i > str() # E: No overload variant
2531
AR_i > bytes() # E: No overload variant
2632
str() > AR_M # E: Unsupported operand types

numpy/typing/tests/data/pass/comparisons.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,7 @@
6666
AR_c > AR_f
6767
AR_c > AR_c
6868

69-
AR_m > AR_b
70-
AR_m > AR_u
71-
AR_m > AR_i
72-
AR_b > AR_m
73-
AR_u > AR_m
74-
AR_i > AR_m
75-
69+
AR_m > AR_m
7670
AR_M > AR_M
7771

7872
AR_O > AR_O
@@ -82,13 +76,7 @@
8276
# Time structures
8377

8478
dt > dt
85-
8679
td > td
87-
td > i
88-
td > i4
89-
td > i8
90-
td > AR_i
91-
td > SEQ
9280

9381
# boolean
9482

0 commit comments

Comments
 (0)
0