diff --git a/pyiceberg/table/inspect.py b/pyiceberg/table/inspect.py index 2cc8b210b2..fe2ff4ca78 100644 --- a/pyiceberg/table/inspect.py +++ b/pyiceberg/table/inspect.py @@ -890,10 +890,13 @@ 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 - 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..bd879c35db 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"} ] + + +@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))) + + 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)