Skip to content

Commit 9f637fb

Browse files
committed
add testcase
1 parent 89c6588 commit 9f637fb

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/io/test_pyarrow.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2725,6 +2725,43 @@ def test__to_requested_schema_timestamp_to_timestamptz_projection() -> None:
27252725
assert expected.equals(actual_result)
27262726

27272727

2728+
def test__to_requested_schema_timestamptz_to_timestamp_projection() -> None:
2729+
# file is written with timestamp with timezone
2730+
file_schema = Schema(NestedField(1, "ts_field", TimestamptzType(), required=False))
2731+
batch = pa.record_batch(
2732+
[
2733+
pa.array(
2734+
[
2735+
datetime(2025, 8, 14, 12, 0, 0, tzinfo=timezone.utc),
2736+
datetime(2025, 8, 14, 13, 0, 0, tzinfo=timezone.utc),
2737+
],
2738+
type=pa.timestamp("us", tz="UTC"),
2739+
)
2740+
],
2741+
names=["ts_field"],
2742+
)
2743+
2744+
# table schema expects timestamp without timezone
2745+
table_schema = Schema(NestedField(1, "ts_field", TimestampType(), required=False))
2746+
2747+
actual_result = _to_requested_schema(table_schema, file_schema, batch, downcast_ns_timestamp_to_us=True)
2748+
expected = pa.record_batch(
2749+
[
2750+
pa.array(
2751+
[
2752+
datetime(2025, 8, 14, 12, 0, 0),
2753+
datetime(2025, 8, 14, 13, 0, 0),
2754+
],
2755+
type=pa.timestamp("us"),
2756+
)
2757+
],
2758+
names=["ts_field"],
2759+
)
2760+
2761+
# expect actual_result to have no timezone
2762+
assert expected.equals(actual_result)
2763+
2764+
27282765
def test__to_requested_schema_timestamps(
27292766
arrow_table_schema_with_all_timestamp_precisions: pa.Schema,
27302767
arrow_table_with_all_timestamp_precisions: pa.Table,

0 commit comments

Comments
 (0)