Skip to content

Fix for ns timestamp non utc#3142

Merged
kevinjqliu merged 1 commit intoapache:mainfrom
nssalian:fix-ns-timestamp-non-utc-tz-silently-dropped
Mar 12, 2026
Merged

Fix for ns timestamp non utc#3142
kevinjqliu merged 1 commit intoapache:mainfrom
nssalian:fix-ns-timestamp-non-utc-tz-silently-dropped

Conversation

@nssalian
Copy link
Contributor

Closes #3127

Rationale for this change

pa.timestamp("ns", tz="US/Pacific") converts to TimestampNanoType() (tz-naive) instead of raising TypeError. The us path correctly rejects non-UTC timezones.

raises TypeError
visit_pyarrow(pa.timestamp("us", tz="US/Pacific"), _ConvertToIceberg())

silently drops timezone
visit_pyarrow(pa.timestamp("ns", tz="US/Pacific"), _ConvertToIceberg(format_version=3))

Fixes this by adding the correct elif clause

Are these changes tested?

Yes - added a couple of tests in the pyarrow visitor

Are there any user-facing changes?

It fixes the behavior that was a bug, so I think it would be.

@nssalian nssalian marked this pull request as ready for review March 11, 2026 16:16
Copy link
Contributor

@kevinjqliu kevinjqliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thank you for the fix!

Comment on lines +236 to +239
def test_pyarrow_timestamp_ns_no_tz_accepted() -> None:
pyarrow_type = pa.timestamp(unit="ns")
converted = visit_pyarrow(pyarrow_type, _ConvertToIceberg(format_version=3))
assert converted == TimestampNanoType()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pa.timestamp defaults tz to None
https://arrow.apache.org/docs/python/generated/pyarrow.timestamp.html

makes sense that it maps to TimestampNanoType

@kevinjqliu kevinjqliu merged commit 098174c into apache:main Mar 12, 2026
14 checks passed
kris-gaudel pushed a commit to kris-gaudel/iceberg-python that referenced this pull request Mar 13, 2026
Closes apache#3127  

# Rationale for this change
`pa.timestamp("ns", tz="US/Pacific") converts to TimestampNanoType()`
(tz-naive) instead of raising `TypeError`. The `us` path correctly
rejects non-UTC timezones.

raises TypeError
`visit_pyarrow(pa.timestamp("us", tz="US/Pacific"),
_ConvertToIceberg())`

silently drops timezone
`visit_pyarrow(pa.timestamp("ns", tz="US/Pacific"),
_ConvertToIceberg(format_version=3))`

Fixes this by adding the correct elif clause
## Are these changes tested?
Yes - added a couple of tests in the pyarrow visitor

## Are there any user-facing changes?
It fixes the behavior that was a bug, so I think it would be.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: ns-precision timestamp with non-UTC timezone silently drops timezone

2 participants