From 782d3d964b65d3d4b668ecd70f82b6466578d725 Mon Sep 17 00:00:00 2001 From: rahulsmahadev Date: Sun, 22 Nov 2026 17:31:34 +0000 Subject: [PATCH 1/2] Return null operation for snapshots without a summary A format v1 snapshot can have no summary, so it has no operation. inspect.snapshots() stored str(operation), which put the text "None" in the nullable operation column. Store the operation as is, so the cell is null, as Java's SnapshotsTable does. Co-authored-by: Isaac --- pyiceberg/table/inspect.py | 2 +- tests/table/test_inspect.py | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/pyiceberg/table/inspect.py b/pyiceberg/table/inspect.py index 4feba3d532..167240dcf8 100644 --- a/pyiceberg/table/inspect.py +++ b/pyiceberg/table/inspect.py @@ -138,7 +138,7 @@ def snapshots(self) -> pa.Table: "committed_at": datetime.fromtimestamp(snapshot.timestamp_ms / 1000.0, tz=UTC), "snapshot_id": snapshot.snapshot_id, "parent_id": snapshot.parent_snapshot_id, - "operation": str(operation), + "operation": operation, "manifest_list": snapshot.manifest_list, "summary": additional_properties, } diff --git a/tests/table/test_inspect.py b/tests/table/test_inspect.py index e507b62f71..09cd956d19 100644 --- a/tests/table/test_inspect.py +++ b/tests/table/test_inspect.py @@ -104,6 +104,32 @@ def test_inspect_entries_and_files_with_data_file_without_metrics(catalog: InMem assert files[0]["column_sizes"] is None +def test_inspect_snapshots_operation_is_null_without_summary(catalog: InMemoryCatalog) -> None: + import json + + # The summary is optional in format v1 and holds the operation, so a snapshot without one has no + # operation: the nullable column must hold null, not the text "None" + schema = Schema(NestedField(1, "x", LongType(), required=False)) + arrow_table = pa.table({"x": [1, 2]}, schema=pa.schema([pa.field("x", pa.int64(), nullable=True)])) + + v2 = catalog.create_table("default.v2_snapshot_operation", schema, properties={"format-version": "2"}) + v2.append(arrow_table) + assert v2.inspect.snapshots().column("operation").to_pylist() == ["append"] + + v1 = catalog.create_table("default.v1_snapshot_without_summary", schema, properties={"format-version": "1"}) + v1.append(arrow_table) + metadata_path = PosixPath(v1.metadata_location.removeprefix("file://")) + metadata = json.loads(metadata_path.read_text()) + for snapshot in metadata["snapshots"]: + del snapshot["summary"] + metadata_path.write_text(json.dumps(metadata)) + + v1 = catalog.load_table("default.v1_snapshot_without_summary") + snapshots = v1.inspect.snapshots().to_pylist() + assert [row["operation"] for row in snapshots] == [None] + assert [row["summary"] for row in snapshots] == [None] + + @pytest.mark.parametrize("newest_first", [False, True]) def test_partitions_last_updated_uses_latest_snapshot_regardless_of_order(newest_first: bool) -> None: # Manifest entries are visited in manifest order, which is not chronological, so the From 966ff629dea26f95e55aa018a0048a78fef9223d Mon Sep 17 00:00:00 2001 From: rahulsmahadev Date: Tue, 24 Nov 2026 03:20:30 +0000 Subject: [PATCH 2/2] Use Path in the inspect snapshots test so it runs on Windows Co-authored-by: Isaac --- tests/table/test_inspect.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/table/test_inspect.py b/tests/table/test_inspect.py index 09cd956d19..789ec70b67 100644 --- a/tests/table/test_inspect.py +++ b/tests/table/test_inspect.py @@ -15,7 +15,7 @@ # specific language governing permissions and limitations # under the License. -from pathlib import PosixPath +from pathlib import Path, PosixPath from typing import Any import pyarrow as pa @@ -118,7 +118,7 @@ def test_inspect_snapshots_operation_is_null_without_summary(catalog: InMemoryCa v1 = catalog.create_table("default.v1_snapshot_without_summary", schema, properties={"format-version": "1"}) v1.append(arrow_table) - metadata_path = PosixPath(v1.metadata_location.removeprefix("file://")) + metadata_path = Path(v1.metadata_location.removeprefix("file://")) metadata = json.loads(metadata_path.read_text()) for snapshot in metadata["snapshots"]: del snapshot["summary"]