diff options
author | Anirudh Subramanian <anirudh2290@ufl.edu> | 2020-06-19 22:19:15 +0000 |
---|---|---|
committer | Anirudh Subramanian <anirudh2290@ufl.edu> | 2020-06-19 23:05:40 +0000 |
commit | 2990d6e9102e4d7c3ff6cb1b69702c42bddaa738 (patch) | |
tree | aa05aaea1877b1d7e9fe9252e52d731e350f46ce | |
parent | 2f156d8e3eb4f57067209fa4499eaeed8551c4ae (diff) | |
download | numpy-2990d6e9102e4d7c3ff6cb1b69702c42bddaa738.tar.gz |
BUG: Fix promote_types uint<->m8 behavior
-rw-r--r-- | doc/release/upcoming_changes/16592.compatibility.rst | 10 | ||||
-rw-r--r-- | numpy/core/src/multiarray/convert_datatype.c | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_datetime.py | 2 |
3 files changed, 11 insertions, 3 deletions
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, |