mbutrovich opened a new issue, #11600:
URL: https://github.com/apache/arrow-rs/issues/11600
### Describe the bug
`sub` of a `Date32` or `Date64` array and a `YearMonth` or `MonthDayNano`
interval whose months are `i32::MIN` panics with "attempt to negate with
overflow" in debug builds, instead of returning the "Date arithmetic overflow"
error.
### To Reproduce
```rust
use arrow_arith::numeric::sub;
use arrow_array::{Date32Array, IntervalYearMonthArray};
fn main() {
let dates = Date32Array::from(vec![0]);
let months = IntervalYearMonthArray::from(vec![i32::MIN]);
println!("{:?}", sub(&dates, &months));
// debug build: panics with "attempt to negate with overflow"
}
```
### Expected behavior
`Err(ComputeError("Date arithmetic overflow: ..."))`, as for other intervals
that move the date out of range.
### Additional context
`subtract_year_months_opt` and `subtract_month_day_nano_opt` on `Date32Type`
and `Date64Type` negate the months with `-` before adding them
([types.rs](https://github.com/apache/arrow-rs/blob/72887ed91c80002bb7ec755ce1e964bab07bebea/arrow-array/src/types.rs#L1143),
[types.rs](https://github.com/apache/arrow-rs/blob/72887ed91c80002bb7ec755ce1e964bab07bebea/arrow-array/src/types.rs#L1229),
[types.rs](https://github.com/apache/arrow-rs/blob/72887ed91c80002bb7ec755ce1e964bab07bebea/arrow-array/src/types.rs#L1333),
[types.rs](https://github.com/apache/arrow-rs/blob/72887ed91c80002bb7ec755ce1e964bab07bebea/arrow-array/src/types.rs#L1371)).
Their docs say they return `None` when the result does not fit. The timestamp
path subtracts with `sub_months_datetime`, which handles `i32::MIN` through
`unsigned_abs`
([delta.rs](https://github.com/apache/arrow-rs/blob/72887ed91c80002bb7ec755ce1e964bab07bebea/arrow-array/src/delta.rs#L68-L77)).
Using `checked_neg`, or `sub_months_date` written the s
ame way, would return `None` here.
Found with property-based tests that build arrays in every physical layout
the Arrow format allows.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]