Skip to content

Commit f38d79b

Browse files
committed
add unit test for projecting timestamp to timestamptz
1 parent 640c592 commit f38d79b

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/io/test_pyarrow.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2521,6 +2521,45 @@ def test_initial_value() -> None:
25212521
assert val.as_py() == 22
25222522

25232523

2524+
def test__to_requested_schema_timestamp_to_timestamptz_projection() -> None:
2525+
from datetime import datetime, timezone
2526+
2527+
# file is written with timestamp without timezone
2528+
file_schema = Schema(NestedField(1, "ts_field", TimestampType(), required=False))
2529+
batch = pa.record_batch(
2530+
[
2531+
pa.array(
2532+
[
2533+
datetime(2025, 8, 14, 12, 0, 0),
2534+
datetime(2025, 8, 14, 13, 0, 0),
2535+
],
2536+
type=pa.timestamp("us"),
2537+
)
2538+
],
2539+
names=["ts_field"],
2540+
)
2541+
2542+
# table is written with timestamp with timezone
2543+
table_schema = Schema(NestedField(1, "ts_field", TimestamptzType(), required=False))
2544+
2545+
actual_result = _to_requested_schema(table_schema, file_schema, batch, downcast_ns_timestamp_to_us=True)
2546+
expected = pa.record_batch(
2547+
[
2548+
pa.array(
2549+
[
2550+
datetime(2025, 8, 14, 12, 0, 0),
2551+
datetime(2025, 8, 14, 13, 0, 0),
2552+
],
2553+
type=pa.timestamp("us", tz=timezone.utc),
2554+
)
2555+
],
2556+
names=["ts_field"],
2557+
)
2558+
2559+
# expect actual_result to have timezone
2560+
assert expected.equals(actual_result)
2561+
2562+
25242563
def test__to_requested_schema_timestamps(
25252564
arrow_table_schema_with_all_timestamp_precisions: pa.Schema,
25262565
arrow_table_with_all_timestamp_precisions: pa.Table,

0 commit comments

Comments
 (0)