Skip to content

Commit f5ff73a

Browse files
committed
add testcase
1 parent ac94b29 commit f5ff73a

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
@@ -2684,6 +2684,43 @@ def test__to_requested_schema_timestamp_to_timestamptz_projection() -> None:
26842684
assert expected.equals(actual_result)
26852685

26862686

2687+
def test__to_requested_schema_timestamptz_to_timestamp_projection() -> None:
2688+
# file is written with timestamp with timezone
2689+
file_schema = Schema(NestedField(1, "ts_field", TimestamptzType(), required=False))
2690+
batch = pa.record_batch(
2691+
[
2692+
pa.array(
2693+
[
2694+
datetime(2025, 8, 14, 12, 0, 0, tzinfo=timezone.utc),
2695+
datetime(2025, 8, 14, 13, 0, 0, tzinfo=timezone.utc),
2696+
],
2697+
type=pa.timestamp("us", tz="UTC"),
2698+
)
2699+
],
2700+
names=["ts_field"],
2701+
)
2702+
2703+
# table schema expects timestamp without timezone
2704+
table_schema = Schema(NestedField(1, "ts_field", TimestampType(), required=False))
2705+
2706+
actual_result = _to_requested_schema(table_schema, file_schema, batch, downcast_ns_timestamp_to_us=True)
2707+
expected = pa.record_batch(
2708+
[
2709+
pa.array(
2710+
[
2711+
datetime(2025, 8, 14, 12, 0, 0),
2712+
datetime(2025, 8, 14, 13, 0, 0),
2713+
],
2714+
type=pa.timestamp("us"),
2715+
)
2716+
],
2717+
names=["ts_field"],
2718+
)
2719+
2720+
# expect actual_result to have no timezone
2721+
assert expected.equals(actual_result)
2722+
2723+
26872724
def test__to_requested_schema_timestamps(
26882725
arrow_table_schema_with_all_timestamp_precisions: pa.Schema,
26892726
arrow_table_with_all_timestamp_precisions: pa.Table,

0 commit comments

Comments
 (0)