8000 MAINT: Fixed an issue where certain `array > arraylike` operations wh… · numpy/numpy@6e84855 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6e84855

Browse files
author
Bas van Beek
committed
MAINT: Fixed an issue where certain array > arraylike operations where neglected
More specifically operations between array-likes of `timedelta64` and `ndarray`s that can be cast into `timedelta64`. For example: ar_i = np.array([1]) seq_m = [np.timedelta64()] ar_i > seq_m
1 parent 3aa0bf6 commit 6e84855

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

numpy/__init__.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,7 +1486,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
14861486
@overload
14871487
def __lt__(self: _ArrayND[Union[number[Any], bool_]], other: _ArrayLikeNumber_co) -> _ArrayOrScalar[bool_]: ...
14881488
@overload
1489-
def __lt__(self: _ArrayND[timedelta64], other: _ArrayLikeTD64_co) -> _ArrayOrScalar[bool_]: ...
1489+
def __lt__(self: _ArrayND[Union[bool_, integer[Any], timedelta64]], other: _ArrayLikeTD64_co) -> _ArrayOrScalar[bool_]: ...
14901490
@overload
14911491
def __lt__(self: _ArrayND[datetime64], other: _ArrayLikeDT64_co) -> _ArrayOrScalar[bool_]: ...
14921492
@overload
@@ -1502,7 +1502,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
15021502
@overload
15031503
def __le__(self: _ArrayND[Union[number[Any], bool_]], other: _ArrayLikeNumber_co) -> _ArrayOrScalar[bool_]: ...
15041504
@overload
1505-
def __le__(self: _ArrayND[timedelta64], other: _ArrayLikeTD64_co) -> _ArrayOrScalar[bool_]: ...
1505+
def __le__(self: _ArrayND[Union[bool_, integer[Any], timedelta64]], other: _ArrayLikeTD64_co) -> _ArrayOrScalar[bool_]: ...
15061506
@overload
15071507
def __le__(self: _ArrayND[datetime64], other: _ArrayLikeDT64_co) -> _ArrayOrScalar[bool_]: ...
15081508
@overload
@@ -1518,7 +1518,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
15181518
@overload
15191519
def __gt__(self: _ArrayND[Union[number[Any], bool_]], other: _ArrayLikeNumber_co) -> _ArrayOrScalar[bool_]: ...
15201520
@overload
1521-
def __gt__(self: _ArrayND[timedelta64], other: _ArrayLikeTD64_co) -> _ArrayOrScalar[bool_]: ...
1521+
def __gt__(self: _ArrayND[Union[bool_, integer[Any], timedelta64]], other: _ArrayLikeTD64_co) -> _ArrayOrScalar[bool_]: ...
15221522
@overload
15231523
def __gt__(self: _ArrayND[datetime64], other: _ArrayLikeDT64_co) -> _ArrayOrScalar[bool_]: ...
15241524
@overload
@@ -1534,7 +1534,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
15341534
@overload
15351535
def __ge__(self: _ArrayND[Union[number[Any], bool_]], other: _ArrayLikeNumber_co) -> _ArrayOrScalar[bool_]: ...
15361536
@overload
1537-
def __ge__(self: _ArrayND[timedelta64], other: _ArrayLikeTD64_co) -> _ArrayOrScalar[bool_]: ...
1537+
def __ge__(self: _ArrayND[Union[bool_, integer[Any], timedelta64]], other: _ArrayLikeTD64_co) -> _ArrayOrScalar[bool_]: ...
15381538
@overload
15391539
def __ge__(self: _ArrayND[datetime64], other: _ArrayLikeDT64_co) -> _ArrayOrScalar[bool_]: ...
15401540
@overload

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@
3333
reveal_type(td > i) # E: numpy.bool_
3434
reveal_type(td > i4) # E: numpy.bool_
3535
reveal_type(td > i8) # E: numpy.bool_
36+
3637
reveal_type(td > AR) # E: Union[numpy.bool_, numpy.ndarray[Any, numpy.dtype[numpy.bool_]]]
3738
reveal_type(td > SEQ) # E: Union[numpy.bool_, numpy.ndarray[Any, numpy.dtype[numpy.bool_]]]
39+
reveal_type(AR > SEQ) # E: Union[numpy.bool_, numpy.ndarray[Any, numpy.dtype[numpy.bool_]]]
40+
reveal_type(AR > td) # E: Union[numpy.bool_, numpy.ndarray[Any, numpy.dtype[numpy.bool_]]]
41+
reveal_type(SEQ > td) # E: Union[numpy.bool_, numpy.ndarray[Any, numpy.dtype[numpy.bool_]]]
42+
reveal_type(SEQ > AR) # E: Union[numpy.bool_, numpy.ndarray[Any, numpy.dtype[numpy.bool_]]]
3843

3944
# boolean
4045

0 commit comments

Comments
 (0)
0