entertainingrover01 opened a new pull request, #4471:
URL: https://github.com/apache/iceberg-python/pull/4471

   Closes #1169
   
   # Rationale for this change
   
   PyArrow `pa.time64("ns")` was unsupported on write and raised `Unsupported 
type: time64[ns]`, even though Iceberg's `time` type is microsecond precision 
by spec. Users had to manually downcast a `time64[ns]` column before writing, 
while the analogous `timestamp[ns]` case has been handled by an opt-in downcast 
since #848.
   
   This change mirrors that existing `ns -> us` timestamp behavior for `time`, 
gated on the same `downcast-ns-timestamp-to-us-on-write` configuration property:
   
   - `pyiceberg/io/pyarrow.py`, `_ConvertToIceberg.primitive`: a `time64[ns]` 
PyArrow type now maps to Iceberg `TimeType()` (with a warning) when 
`downcast-ns-timestamp-to-us-on-write` is set, and otherwise raises a 
`TypeError` pointing the user at that property. `time64[us]` keeps working 
unchanged.
   - `pyiceberg/io/pyarrow.py`, `ArrowProjectionVisitor._cast_if_needed`: a new 
`TimeType` branch casts a `time64[ns]` array to `time64[us]` (`safe=False`) on 
write when the flag is set, so the data, not just the schema mapping, is 
actually downcast.
   - Tests: updated `test_pyarrow_time64_ns_to_iceberg` and added 
`test_pyarrow_time64_ns_to_iceberg_downcast`, 
`test__to_requested_schema_time_ns_downcast`, and 
`test__to_requested_schema_time_ns_without_downcast_raises_exception`.
   
   # Are these changes tested?
   
   Yes — `pytest tests/io/test_pyarrow_visitor.py tests/io/test_pyarrow.py` 
passes (296 passed, 3 skipped), including the 3 new tests and the updated one. 
`ruff check` and `ruff format --check` pass on all changed files.
   


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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to