8000 Merge pull request #16639 from anirudh2290/fix_timedelta_promotion_uint · numpy/numpy@69555f5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 69555f5

Browse files
authored
Merge pull request #16639 from anirudh2290/fix_timedelta_promotion_uint
BUG: Fix uint->timedelta promotion to raise TypeError
2 parents 2f156d8 + 27edfbb commit 69555f5

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ numpy/core/src/umath/simd.inc
166166
numpy/core/src/umath/struct_ufunc_test.c
167167
numpy/core/src/umath/test_rational.c
168168
numpy/core/src/umath/umath_tests.c
169+
numpy/core/src/umath/_umath_tests.dispatch.avx2.c
170+
numpy/core/src/umath/_umath_tests.dispatch.h
171+
numpy/core/src/umath/_umath_tests.dispatch.sse41.c
169172
numpy/distutils/__config__.py
170173
numpy/linalg/umath_linalg.c
171174
doc/source/**/generated/
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
float->timedelta promotion will raise a TypeError
2-
-------------------------------------------------
1+
float->timedelta and uint64->timedelta promotion will raise a TypeError
2+
-----------------------------------------------------------------------
33
Float and timedelta promotion consistently raises a TypeError.
44
``np.promote_types("float32", "m8")`` aligns with
55
``np.promote_types("m8", "float32")`` now and both raise a TypeError.
66
Previously, ``np.promote_types("float32", "m8")`` returned ``"m8"`` which
77
was considered a bug.
8+
9+
Uint64 and timedelta promotion consistently raises a TypeError.
10+
``np.promote_types("uint64", "m8")`` aligns with
11+
``np.promote_types("m8", "uint64")`` now and both raise a TypeError.
12+
Previously, ``np.promote_types("uint64", "m8")`` returned ``"m8"`` which
13+
was considered a bug.

numpy/core/src/multiarray/convert_datatype.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,7 @@ PyArray_PromoteTypes(PyArray_Descr *type1, PyArray_Descr *type2)
14191419
}
14201420
break;
14211421
case NPY_TIMEDELTA:
1422-
if (PyTypeNum_ISINTEGER(type_num1)) {
1422+
if (PyTypeNum_ISSIGNED(type_num1)) {
14231423
return ensure_dtype_nbo(type2);
14241424
}
14251425
break;

numpy/core/tests/test_datetime.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,8 @@ def test_dtype_promotion(self):
778778
# timedelta and float cannot be safely cast with each other
779779
assert_raises(TypeError, np.promote_types, "float32", "m8")
780780
assert_raises(TypeError, np.promote_types, "m8", "float32")
781+
assert_raises(TypeError, np.promote_types, "uint64", "m8")
782+
assert_raises(TypeError, np.promote_types, "m8", "uint64")
781783

782784
# timedelta <op> timedelta may overflow with big unit ranges
783785
assert_raises(OverflowError, np.promote_types,

0 commit comments

Comments
 (0)
0