HyukjinKwon opened a new pull request, #48626:
URL: https://github.com/apache/arrow/pull/48626

   ### Rationale for this change
   
   This is to address a todo: 
   
   
https://github.com/apache/arrow/blob/de6eb89dbdcf210802c3aad5d3f1a3d4c64c3582/python/pyarrow/src/arrow/python/inference.cc#L258
   
   When users mix `numpy.datetime64` values with different units (e.g., 
`datetime64[s]` and `datetime64[ms]`) in a single array, PyArrow previously 
produced a confusing error message
   
   
   ### What changes are included in this PR?
   
   - Added datetime64 unit validation in `NumPyDtypeUnifier::Observe_DATETIME()`
   - Added `InvalidDatetimeUnitMix()` method:
   - Updated `NumPyDtypeUnifier::Observe()` to check units for same-type 
comparisons
   - Updated existing test 
`test_array_from_different_numpy_datetime_units_raises`
   - Removed the TODO comment (now implemented)
   
   ### Are these changes tested?
   
   Manually tested, and unittests were added.
   
   ### Are there any user-facing changes?
   
   Yes. It produces a better error message. For example,
   
   ```python
   import pyarrow as pa
   import numpy as np
   pa.array([np.datetime64('2020-01-01', 's'), np.datetime64('2020-01-02', 
'ms')])
   ```
   
   Before: 
   
   ```
   pyarrow.lib.ArrowNotImplementedError: Expected np.datetime64 but got: 
timestamp[ms]
   ```
   
   After:
   
   ```
   pyarrow.lib.ArrowInvalid: Cannot mix NumPy datetime64 units s and ms
   ```


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