Skip to content

Commit

Permalink
Merge pull request #16639 from anirudh2290/fix_timedelta_promotion_uint
Browse files Browse the repository at this point in the history
BUG: Fix uint->timedelta promotion to raise TypeError
  • Loading branch information
seberg committed Jun 20, 2020
2 parents 2f156d8 + 27edfbb commit 69555f5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
10 changes: 8 additions & 2 deletions doc/release/upcoming_changes/16592.compatibility.rst
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion numpy/core/src/multiarray/convert_datatype.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions numpy/core/tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,8 @@ def test_dtype_promotion(self):
# 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,
Expand Down

0 comments on commit 69555f5

Please sign in to comment.