Shahzeb-DataEngineer opened a new pull request, #11854:
URL: https://github.com/apache/arrow-rs/pull/11854

   # Which issue does this PR close?
   
   - Closes #11853
   
   # Rationale for this change
   
   Casting `Date64` to `Date32` truncated toward zero instead of flooring, so 
any pre-1970 `Date64` value that is not an exact midnight cast to the *next* 
day: for example -1 ms (1969-12-31 23:59:59.999) became Date32 0 (1970-01-01) 
instead of Date32 -1 (1969-12-31). Every sibling conversion in the crate floors 
instead: `cast_timestamp_to_date` uses `div_euclid`, which is also the 
semantics adopted for Timestamp -> Date64 in #11632. The `(Date64, Date32)` arm 
in `arrow-cast/src/cast/mod.rs` was the only day division still using plain `/`.
   
   # What changes are included in this PR?
   
   - Use `div_euclid(MILLISECONDS_IN_DAY)` instead of `/ MILLISECONDS_IN_DAY` 
in both the safe and unsafe closures of the `(Date64, Date32)` cast arm.
   - Add `test_cast_date64_to_date32_negative`, covering negative values just 
before midnight, just after midnight, at an exact midnight, and just before a 
day boundary, plus a positive control and a null, in both safe and unsafe modes.
   
   # Are these changes tested?
   
   Yes, the new regression test is included in this PR and covers both cast 
modes. The existing Date64 cast tests and the rest of the `arrow-cast` library 
tests still pass, and the change is `rustfmt` and `clippy` clean.
   
   # Are there any significant user-facing changes?
   
   No API changes. The only behavior change is that pre-1970 `Date64` values 
with a time component now cast to the correct day instead of the following day. 
Non-negative values and exact midnights are unaffected.
   
   # AI usage disclosure
   
   Following the project's guidance on AI generated submissions: the initial 
bug analysis and draft test cases for this change were produced with the help 
of an AI coding assistant. I reviewed the full diff line by line, confirmed the 
root cause against the sibling `div_euclid` conversions in the crate, and 
verified the fix by running the new test and the `arrow-cast` test suite 
locally.
   


-- 
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]

Reply via email to