@@ -1129,6 +1129,55 @@ def test_ensure_platform_int():
11291129 assert (result is arr )
11301130
11311131
1132+ def test_int64_add_overflow ():
1133+ # see gh-14068
1134+ msg = "Overflow in int64 addition"
1135+ m = np .iinfo (np .int64 ).max
1136+ n = np .iinfo (np .int64 ).min
1137+
1138+ with tm .assertRaisesRegexp (OverflowError , msg ):
1139+ algos .checked_add_with_arr (np .array ([m , m ]), m )
1140+ with tm .assertRaisesRegexp (OverflowError , msg ):
1141+ algos .checked_add_with_arr (np .array ([m , m ]), np .array ([m , m ]))
1142+ with tm .assertRaisesRegexp (OverflowError , msg ):
1143+ algos .checked_add_with_arr (np .array ([n , n ]), n )
1144+ with tm .assertRaisesRegexp (OverflowError , msg ):
1145+ algos .checked_add_with_arr (np .array ([n , n ]), np .array ([n , n ]))
1146+ with tm .assertRaisesRegexp (OverflowError , msg ):
1147+ algos .checked_add_with_arr (np .array ([m , n ]), np .array ([n , n ]))
1148+ with tm .assertRaisesRegexp (OverflowError , msg ):
1149+ algos .checked_add_with_arr (np .array ([m , m ]), np .array ([m , m ]),
1150+ arr_mask = np .array ([False , True ]))
1151+ with tm .assertRaisesRegexp (OverflowError , msg ):
1152+ algos .checked_add_with_arr (np .array ([m , m ]), np .array ([m , m ]),
1153+ b_mask = np .array ([False , True ]))
1154+ with tm .assertRaisesRegexp (OverflowError , msg ):
1155+ algos .checked_add_with_arr (np .array ([m , m ]), np .array ([m , m ]),
1156+ arr_mask = np .array ([False , True ]),
1157+ b_mask = np .array ([False , True ]))
1158+ with tm .assertRaisesRegexp (OverflowError , msg ):
1159+ with tm .assert_produces_warning (RuntimeWarning ):
1160+ algos .checked_add_with_arr (np .array ([m , m ]),
1161+ np .array ([np .nan , m ]))
1162+
1163+ # Check that the nan boolean arrays override whether or not
1164+ # the addition overflows. We don't check the result but just
1165+ # the fact that an OverflowError is not raised.
1166+ with tm .assertRaises (AssertionError ):
1167+ with tm .assertRaisesRegexp (OverflowError , msg ):
1168+ algos .checked_add_with_arr (np .array ([m , m ]), np .array ([m , m ]),
1169+ arr_mask = np .array ([True , True ]))
1170+ with tm .assertRaises (AssertionError ):
1171+ with tm .assertRaisesRegexp (OverflowError , msg ):
1172+ algos .checked_add_with_arr (np .array ([m , m ]), np .array ([m , m ]),
1173+ b_mask = np .array ([True , True ]))
1174+ with tm .assertRaises (AssertionError ):
1175+ with tm .assertRaisesRegexp (OverflowError , msg ):
1176+ algos .checked_add_with_arr (np .array ([m , m ]), np .array ([m , m ]),
1177+ arr_mask = np .array ([True , False ]),
1178+ b_mask = np .array ([False , True ]))
1179+
1180+
11321181if __name__ == '__main__' :
11331182 import nose
11341183 nose .runmodule (argv = [__file__ , '-vvs' , '-x' , '--pdb' , '--pdb-failure' ],
0 commit comments