summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2020-06-19 20:34:13 -0500
committerGitHub <noreply@github.com>2020-06-19 20:34:13 -0500
commit69555f52b2e2c5032cf70d40d9f9b8ec9a048500 (patch)
treecf500bb4f765e45a988442a0732ab38035213ad4
parent2f156d8e3eb4f57067209fa4499eaeed8551c4ae (diff)
parent27edfbbc1b06008caee1966590ff2765007d6fcc (diff)
downloadnumpy-69555f52b2e2c5032cf70d40d9f9b8ec9a048500.tar.gz
Merge pull request #16639 from anirudh2290/fix_timedelta_promotion_uint
BUG: Fix uint->timedelta promotion to raise TypeError
-rw-r--r--.gitignore3
-rw-r--r--doc/release/upcoming_changes/16592.compatibility.rst10
-rw-r--r--numpy/core/src/multiarray/convert_datatype.c2
-rw-r--r--numpy/core/tests/test_datetime.py2
4 files changed, 14 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore
index 2a77f4f83..6d0cdff50 100644
--- a/.gitignore
+++ b/.gitignore
@@ -166,6 +166,9 @@ numpy/core/src/umath/simd.inc
numpy/core/src/umath/struct_ufunc_test.c
numpy/core/src/umath/test_rational.c
numpy/core/src/umath/umath_tests.c
+numpy/core/src/umath/_umath_tests.dispatch.avx2.c
+numpy/core/src/umath/_umath_tests.dispatch.h
+numpy/core/src/umath/_umath_tests.dispatch.sse41.c
numpy/distutils/__config__.py
numpy/linalg/umath_linalg.c
doc/source/**/generated/
diff --git a/doc/release/upcoming_changes/16592.compatibility.rst b/doc/release/upcoming_changes/16592.compatibility.rst
index 0e2a79262..289e768fc 100644
--- a/doc/release/upcoming_changes/16592.compatibility.rst
+++ b/doc/release/upcoming_changes/16592.compatibility.rst
@@ -1,7 +1,13 @@
-float->timedelta promotion will raise a TypeError
--------------------------------------------------
+float->timedelta and uint64->timedelta promotion will raise a TypeError
+-----------------------------------------------------------------------
Float and timedelta promotion consistently raises a TypeError.
``np.promote_types("float32", "m8")`` aligns with
``np.promote_types("m8", "float32")`` now and both raise a TypeError.
Previously, ``np.promote_types("float32", "m8")`` returned ``"m8"`` which
was considered a bug.
+
+Uint64 and timedelta promotion consistently raises a TypeError.
+``np.promote_types("uint64", "m8")`` aligns with
+``np.promote_types("m8", "uint64")`` now and both raise a TypeError.
+Previously, ``np.promote_types("uint64", "m8")`` returned ``"m8"`` which
+was considered a bug.
diff --git a/numpy/core/src/multiarray/convert_datatype.c b/numpy/core/src/multiarray/convert_datatype.c
index 6c1958e72..7bd088677 100644
--- a/numpy/core/src/multiarray/convert_datatype.c
+++ b/numpy/core/src/multiarray/convert_datatype.c
@@ -1419,7 +1419,7 @@ PyArray_PromoteTypes(PyArray_Descr *type1, PyArray_Descr *type2)
}
break;
case NPY_TIMEDELTA:
- if (PyTypeNum_ISINTEGER(type_num1)) {
+ if (PyTypeNum_ISSIGNED(type_num1)) {
return ensure_dtype_nbo(type2);
}
break;
diff --git a/numpy/core/tests/test_datetime.py b/numpy/core/tests/test_datetime.py
index 84dfc2949..fef1e24d8 100644
--- a/numpy/core/tests/test_datetime.py
+++ b/numpy/core/tests/test_datetime.py
@@ -778,6 +778,8 @@ class TestDateTime:
# timedelta and float cannot be safely cast with each other
assert_raises(TypeError, np.promote_types, "float32", "m8")
assert_raises(TypeError, np.promote_types, "m8", "float32")
+ assert_raises(TypeError, np.promote_types, "uint64", "m8")
+ assert_raises(TypeError, np.promote_types, "m8", "uint64")
# timedelta <op> timedelta may overflow with big unit ranges
assert_raises(OverflowError, np.promote_types,