0x26res opened a new issue, #46138: URL: https://github.com/apache/arrow/issues/46138
### Describe the enhancement requested According to the documentation it should be possible to pass an `option` argument of type `payrrow.compute.CastOption` to `pyarrow.Table.cast`. But as far as I can tell: - I can't figure out how to get it to work - there's no example in the documentation - there's no test for it (in `python/pyarrow/tests/test_table.py`) ```python import pandas as pd import pyarrow as pa import pyarrow.compute as pc import pytest original_schema = pa.schema([pa.field("timestamp", pa.timestamp("ns", "UTC"))]) table = pa.table( [[pd.to_datetime("2023-03-15T15:15:00.123456789Z")]], schema=original_schema ) new_schema = pa.schema([pa.field("timestamp", pa.timestamp("us", "UTC"))]) with pytest.raises( pa.ArrowInvalid, match=r"Casting from timestamp\[ns, tz=UTC\] to timestamp\[us, tz=UTC\] would lose data: 1678893300123456789", ): table.cast(new_schema) with pytest.raises( ValueError, match=r"Must either pass values for 'target_type' and 'safe' or pass a value for 'options'", ): table.cast(new_schema, options=pc.CastOptions(allow_time_truncate=True)) with pytest.raises( TypeError, match=r"Argument 'target_type' has incorrect type \(expected pyarrow.lib.DataType, got pyarrow.lib.Schema\)", ): table.cast( new_schema, options=pc.CastOptions(target_type=new_schema, allow_time_truncate=True), ) with pytest.raises( ValueError, match=r"Must either pass values for 'target_type' and 'safe' or pass a value for 'options'", ): table.cast( new_schema, safe=False, options=pc.CastOptions(target_type=pa.struct(new_schema), allow_time_truncate=True), ) ``` I'm happy to send an PR, but not sure where the problem is exactly. PS: as a side note, CastOptions can be converted to bool and be interpreted by mistake as the `safe` argument: ``` assert bool(pc.CastOptions(allow_time_truncate=True)) == True ``` ### Component(s) Python -- 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: issues-unsubscr...@arrow.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org