From 96eb213842a6fa3b2d2ae13d96388811fd267e66 Mon Sep 17 00:00:00 2001 From: Neelesh Salian Date: Tue, 10 Mar 2026 14:24:22 -0700 Subject: [PATCH] Fix for ns timestamp non utc --- pyiceberg/io/pyarrow.py | 2 +- tests/io/test_pyarrow_visitor.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pyiceberg/io/pyarrow.py b/pyiceberg/io/pyarrow.py index 0dfc5eb55a..8f22261f5d 100644 --- a/pyiceberg/io/pyarrow.py +++ b/pyiceberg/io/pyarrow.py @@ -1451,7 +1451,7 @@ def primitive(self, primitive: pa.DataType) -> PrimitiveType: elif self._format_version >= 3: if primitive.tz in UTC_ALIASES: return TimestamptzNanoType() - else: + elif primitive.tz is None: return TimestampNanoType() else: raise TypeError( diff --git a/tests/io/test_pyarrow_visitor.py b/tests/io/test_pyarrow_visitor.py index 433350c225..6727b8c768 100644 --- a/tests/io/test_pyarrow_visitor.py +++ b/tests/io/test_pyarrow_visitor.py @@ -63,6 +63,7 @@ NestedField, StringType, StructType, + TimestampNanoType, TimestampType, TimestamptzType, TimeType, @@ -226,6 +227,18 @@ def test_pyarrow_timestamp_tz_invalid_tz() -> None: visit_pyarrow(pyarrow_type, _ConvertToIceberg()) +def test_pyarrow_timestamp_ns_tz_invalid_tz() -> None: + pyarrow_type = pa.timestamp(unit="ns", tz="US/Pacific") + with pytest.raises(TypeError, match=re.escape("Unsupported type: timestamp[ns, tz=US/Pacific]")): + visit_pyarrow(pyarrow_type, _ConvertToIceberg(format_version=3)) + + +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() + + @pytest.mark.parametrize("pyarrow_type", [pa.string(), pa.large_string(), pa.string_view()]) def test_pyarrow_string_to_iceberg(pyarrow_type: pa.DataType) -> None: converted_iceberg_type = visit_pyarrow(pyarrow_type, _ConvertToIceberg())