@@ -818,6 +818,12 @@ PyUFunc_AdditionTypeResolver(PyUFuncObject *ufunc,
818818 /* m8[<A>] + int => m8[<A>] + m8[<A>] */
819819 else if (PyTypeNum_ISINTEGER (type_num2 ) ||
820820 PyTypeNum_ISBOOL (type_num2 )) {
821+ if (DEPRECATE (
822+ "The 'generic' unit for NumPy timedelta is deprecated, "
823+ "and will raise an error in the future. "
824+ "Please convert the integer with an explicit unit." ) < 0 ) {
825+ return -1 ;
826+ }
821827 out_dtypes [0 ] = NPY_DT_CALL_ensure_canonical (
822828 PyArray_DESCR (operands [0 ]));
823829 if (out_dtypes [0 ] == NULL ) {
@@ -855,6 +861,12 @@ PyUFunc_AdditionTypeResolver(PyUFuncObject *ufunc,
855861 /* M8[<A>] + int => M8[<A>] + m8[<A>] */
856862 else if (PyTypeNum_ISINTEGER (type_num2 ) ||
857863 PyTypeNum_ISBOOL (type_num2 )) {
864+ if (DEPRECATE (
865+ "The 'generic' unit for NumPy timedelta is deprecated, "
866+ "and will raise an error in the future. "
867+ "Please convert the integer with an explicit unit." ) < 0 ) {
868+ return -1 ;
869+ }
858870 out_dtypes [0 ] = NPY_DT_CALL_ensure_canonical (
859871 PyArray_DESCR (operands [0 ]));
860872 if (out_dtypes [0 ] == NULL ) {
@@ -880,6 +892,12 @@ PyUFunc_AdditionTypeResolver(PyUFuncObject *ufunc,
880892 else if (PyTypeNum_ISINTEGER (type_num1 ) || PyTypeNum_ISBOOL (type_num1 )) {
881893 /* int + m8[<A>] => m8[<A>] + m8[<A>] */
882894 if (type_num2 == NPY_TIMEDELTA ) {
895+ if (DEPRECATE (
896+ "The 'generic' unit for NumPy timedelta is deprecated, "
897+ "and will raise an error in the future. "
898+ "Please convert the integer with an explicit unit." ) < 0 ) {
899+ return -1 ;
900+ }
883901 out_dtypes [0 ] = NPY_DT_CALL_ensure_canonical (
884902 PyArray_DESCR (operands [1 ]));
885903 if (out_dtypes [0 ] == NULL ) {
@@ -893,6 +911,12 @@ PyUFunc_AdditionTypeResolver(PyUFuncObject *ufunc,
893911 type_num1 = NPY_TIMEDELTA ;
894912 }
895913 else if (type_num2 == NPY_DATETIME ) {
914+ if (DEPRECATE (
915+ "The 'generic' unit for NumPy timedelta is deprecated, "
916+ "and will raise an error in the future. "
917+ "Please convert the integer with an explicit unit." ) < 0 ) {
918+ return -1 ;
919+ }
896920 /* Make a new NPY_TIMEDELTA, and copy type2's metadata */
897921 out_dtypes [0 ] = timedelta_dtype_with_copied_meta (
898922 PyArray_DESCR (operands [1 ]));
@@ -991,6 +1015,12 @@ PyUFunc_SubtractionTypeResolver(PyUFuncObject *ufunc,
9911015 /* m8[<A>] - int => m8[<A>] - m8[<A>] */
9921016 else if (PyTypeNum_ISINTEGER (type_num2 ) ||
9931017 PyTypeNum_ISBOOL (type_num2 )) {
1018+ if (DEPRECATE (
1019+ "The 'generic' unit for NumPy timedelta is deprecated, "
1020+ "and will raise an error in the future. "
1021+ "Please convert the integer with an explicit unit." ) < 0 ) {
1022+ return -1 ;
1023+ }
9941024 out_dtypes [0 ] = NPY_DT_CALL_ensure_canonical (
9951025 PyArray_DESCR (operands [0 ]));
9961026 if (out_dtypes [0 ] == NULL ) {
@@ -1028,6 +1058,12 @@ PyUFunc_SubtractionTypeResolver(PyUFuncObject *ufunc,
10281058 /* M8[<A>] - int => M8[<A>] - m8[<A>] */
10291059 else if (PyTypeNum_ISINTEGER (type_num2 ) ||
10301060 PyTypeNum_ISBOOL (type_num2 )) {
1061+ if (DEPRECATE (
1062+ "The 'generic' unit for NumPy timedelta is deprecated, "
1063+ "and will raise an error in the future. "
1064+ "Please convert the integer with an explicit unit." ) < 0 ) {
1065+ return -1 ;
1066+ }
10311067 out_dtypes [0 ] = NPY_DT_CALL_ensure_canonical (
10321068 PyArray_DESCR (operands [0 ]));
10331069 if (out_dtypes [0 ] == NULL ) {
@@ -1069,6 +1105,12 @@ PyUFunc_SubtractionTypeResolver(PyUFuncObject *ufunc,
10691105 else if (PyTypeNum_ISINTEGER (type_num1 ) || PyTypeNum_ISBOOL (type_num1 )) {
10701106 /* int - m8[<A>] => m8[<A>] - m8[<A>] */
10711107 if (type_num2 == NPY_TIMEDELTA ) {
1108+ if (DEPRECATE (
1109+ "The 'generic' unit for NumPy timedelta is deprecated, "
1110+ "and will raise an error in the future. "
1111+ "Please convert the integer with an explicit unit." ) < 0 ) {
1112+ return -1 ;
1113+ }
10721114 out_dtypes [0 ] = NPY_DT_CALL_ensure_canonical (
10731115 PyArray_DESCR (operands [1 ]));
10741116 if (out_dtypes [0 ] == NULL ) {
0 commit comments