From 53686443c86ba91a1d76fde0c8b3f29813da7a4d Mon Sep 17 00:00:00 2001 From: Shashank Yadav <65058495+shashank11yadav@users.noreply.github.com> Date: Fri, 4 Dec 2026 00:06:32 -0700 Subject: [PATCH 1/2] Raise for an explicit snapshot_id=0 in inspect.files() on a table without snapshots 0 was treated as "no snapshot id", so the empty-table shortcut hid an unknown id. Use `is None`, as `_get_snapshot` does. --- pyiceberg/table/inspect.py | 2 +- tests/table/test_inspect.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pyiceberg/table/inspect.py b/pyiceberg/table/inspect.py index 2cc8b210b2..e134b2c0fc 100644 --- a/pyiceberg/table/inspect.py +++ b/pyiceberg/table/inspect.py @@ -893,7 +893,7 @@ def _files(self, snapshot_id: int | None = None, data_file_filter: set[DataFileC """ import pyarrow as pa - if not snapshot_id and not self.tbl.metadata.current_snapshot(): + if snapshot_id is None and not self.tbl.metadata.current_snapshot(): return self._get_files_schema().empty_table() snapshot = self._get_snapshot(snapshot_id) diff --git a/tests/table/test_inspect.py b/tests/table/test_inspect.py index 20a2235cd6..fede0cfd79 100644 --- a/tests/table/test_inspect.py +++ b/tests/table/test_inspect.py @@ -308,3 +308,12 @@ def test_inspect_after_promoting_then_dropping_partition_column(catalog: InMemor assert tbl.inspect.manifests().to_pydict()["partition_summaries"][0] == [ {"contains_null": False, "contains_nan": False, "lower_bound": "10", "upper_bound": "20"} ] + + +def test_inspect_files_with_snapshot_id_zero_on_table_without_snapshots(catalog: InMemoryCatalog) -> None: + tbl = catalog.create_table("default.no_snapshots", Schema(NestedField(1, "x", LongType(), required=False))) + + for inspect_files in [tbl.inspect.files, tbl.inspect.data_files, tbl.inspect.delete_files]: + assert inspect_files().num_rows == 0 + with pytest.raises(ValueError, match="Cannot find snapshot with ID 0"): + inspect_files(snapshot_id=0) From 342f45bf60cb7ff87816a2bf6c70a3bdd55c262e Mon Sep 17 00:00:00 2001 From: Shashank Yadav <65058495+shashank11yadav@users.noreply.github.com> Date: Fri, 4 Dec 2026 14:41:29 -0700 Subject: [PATCH 2/2] Parametrize the snapshot_id=0 inspect test and document the ValueError in _files Split the test over files, data_files and delete_files with pytest.mark.parametrize, as test_inspect_files_of_snapshot_without_manifests does, and add a Raises section to the _files docstring. --- pyiceberg/table/inspect.py | 3 +++ tests/table/test_inspect.py | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pyiceberg/table/inspect.py b/pyiceberg/table/inspect.py index e134b2c0fc..fe2ff4ca78 100644 --- a/pyiceberg/table/inspect.py +++ b/pyiceberg/table/inspect.py @@ -890,6 +890,9 @@ def _files(self, snapshot_id: int | None = None, data_file_filter: set[DataFileC Returns: pa.Table: Concatenated file metadata from all manifests in the snapshot. + + Raises: + ValueError: If the specified snapshot does not exist. """ import pyarrow as pa diff --git a/tests/table/test_inspect.py b/tests/table/test_inspect.py index fede0cfd79..bd879c35db 100644 --- a/tests/table/test_inspect.py +++ b/tests/table/test_inspect.py @@ -310,10 +310,10 @@ def test_inspect_after_promoting_then_dropping_partition_column(catalog: InMemor ] -def test_inspect_files_with_snapshot_id_zero_on_table_without_snapshots(catalog: InMemoryCatalog) -> None: +@pytest.mark.parametrize("method", ["files", "data_files", "delete_files"]) +def test_inspect_files_with_snapshot_id_zero_on_table_without_snapshots(catalog: InMemoryCatalog, method: str) -> None: tbl = catalog.create_table("default.no_snapshots", Schema(NestedField(1, "x", LongType(), required=False))) - for inspect_files in [tbl.inspect.files, tbl.inspect.data_files, tbl.inspect.delete_files]: - assert inspect_files().num_rows == 0 - with pytest.raises(ValueError, match="Cannot find snapshot with ID 0"): - inspect_files(snapshot_id=0) + assert getattr(tbl.inspect, method)().num_rows == 0 + with pytest.raises(ValueError, match="Cannot find snapshot with ID 0"): + getattr(tbl.inspect, method)(snapshot_id=0)