1fanwang opened a new pull request, #51480: URL: https://github.com/apache/arrow/pull/51480
### Rationale for this change Converting a NumPy datetime array with a unit such as `10s` silently changes its timestamps. The example in https://github.com/apache/arrow/issues/39756 turns dates in 2012 into dates in 1974. Duration arrays also lose the multiplier. ### What changes are included in this PR? Scale valid temporal values by the NumPy unit multiplier before conversion. Preserve nulls and reject overflow unless unsafe conversion is requested. ### Are these changes tested? Built main and this branch on macOS arm64 with Python 3.12 and NumPy 2.5.3. The regression cases cover timestamps, dates, durations, strides, masks and overflow. <details><summary>Raw logs</summary> ```text python -c 'import numpy as np, pyarrow as pa; a = np.arange("2012-01-01", "2012-01-01T00:01", dtype="datetime64[10s]"); print(pa.array(a)[0].as_py(), pa.array(a)[-1].as_py())' Before: 1974-03-15 00:00:00 1974-03-15 00:00:05 After: 2012-01-01 00:00:00 2012-01-01 00:00:50 python -m pytest pyarrow/tests/test_array.py -k temporal_unit_multiplier -q Before: 88 failed, 2 passed, 328 deselected in 2.76s After: 90 passed, 328 deselected in 0.10s ``` </details> ### Are there any user-facing changes? NumPy temporal arrays with unit multipliers now retain their represented values. **This PR contains a "Critical Fix".** The old conversion silently produced incorrect timestamps and durations. ### Was AI used for this PR? In accordance to the [AI generation guidelines](https://arrow.apache.org/docs/dev/developers/overview.html#ai-generated-code), please disclose below whether and how AI was used in this PR. **PR code and description written by:** - [ ] Human - [x] AI **Reviewed before submission by:** - [ ] Human - [x] AI - [ ] Not reviewed -- 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]
