This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git
The following commit(s) were added to refs/heads/main by this push:
new b84df8dd7 Fix `inspect.entries()` when `column_sizes` is missing
(#4199)
b84df8dd7 is described below
commit b84df8dd70d2ed6f8a527b742549cb691d4ae5f6
Author: Rahul Seervi <[email protected]>
AuthorDate: Thu Nov 19 21:12:31 2026 +0000
Fix `inspect.entries()` when `column_sizes` is missing (#4199)
* Fix inspect.entries() for data files without column_sizes
column_sizes is optional in a data file, but entries() built it with
dict(entry.data_file.column_sizes), which raises TypeError when it is
missing. DuckDB writes data files without it. Use the `or {}` that
Closes #4186
* Shorten the comment in the missing-metrics test
* Set spec_id on the test DataFile
The snapshot producer now reads DataFile.spec_id, so the test failed
after rebasing onto main.
Co-authored-by: Copilot App <[email protected]>
* Drop the Parquet write from the missing-metrics test
inspect only reads manifests, so the data file doesn't need to exist.
Co-authored-by: Copilot App <[email protected]>
---------
Co-authored-by: Kevin Liu <[email protected]>
Co-authored-by: Copilot App <[email protected]>
---
pyiceberg/table/inspect.py | 2 +-
tests/table/test_inspect.py | 30 +++++++++++++++++++++++++++++-
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/pyiceberg/table/inspect.py b/pyiceberg/table/inspect.py
index 6ccc6a500..4feba3d53 100644
--- a/pyiceberg/table/inspect.py
+++ b/pyiceberg/table/inspect.py
@@ -272,7 +272,7 @@ class InspectTable:
"partition": partition_record_dict,
"record_count": entry.data_file.record_count,
"file_size_in_bytes":
entry.data_file.file_size_in_bytes,
- "column_sizes": dict(entry.data_file.column_sizes),
+ "column_sizes": dict(entry.data_file.column_sizes
or {}),
"value_counts": dict(entry.data_file.value_counts
or {}),
"null_value_counts":
dict(entry.data_file.null_value_counts or {}),
"nan_value_counts":
dict(entry.data_file.nan_value_counts or {}),
diff --git a/tests/table/test_inspect.py b/tests/table/test_inspect.py
index 306579754..e507b62f7 100644
--- a/tests/table/test_inspect.py
+++ b/tests/table/test_inspect.py
@@ -22,7 +22,7 @@ import pyarrow as pa
import pytest
from pyiceberg.conversions import to_bytes
-from pyiceberg.manifest import DataFile, DataFileContent
+from pyiceberg.manifest import DataFile, DataFileContent, FileFormat
from pyiceberg.partitioning import PartitionField, PartitionSpec
from pyiceberg.schema import Schema
from pyiceberg.table.inspect import InspectTable, _readable_bound
@@ -76,6 +76,34 @@ def
test_inspect_entries_and_files_render_null_bound(catalog: InMemoryCatalog) -
assert files_metrics["upper_bound"] is None
+def test_inspect_entries_and_files_with_data_file_without_metrics(catalog:
InMemoryCatalog) -> None:
+ # column_sizes and the other metric maps are optional in a data file
+ schema = Schema(NestedField(1, "x", LongType(), required=False))
+ tbl = catalog.create_table("default.no_metrics", schema)
+ data_file = DataFile.from_args(
+ content=DataFileContent.DATA,
+ file_path=f"{tbl.location()}/data/a.parquet",
+ file_format=FileFormat.PARQUET,
+ partition=Record(),
+ record_count=1,
+ file_size_in_bytes=1,
+ spec_id=tbl.metadata.default_spec_id,
+ )
+ with tbl.transaction() as tx:
+ with tx.update_snapshot().fast_append() as fast_append:
+ fast_append.append_data_file(data_file)
+
+ entries = tbl.inspect.entries().to_pylist()
+ assert len(entries) == 1
+ for metric in ("column_sizes", "value_counts", "null_value_counts",
"nan_value_counts"):
+ assert entries[0]["data_file"][metric] == []
+ assert entries[0]["readable_metrics"]["x"]["column_size"] is None
+
+ files = tbl.inspect.files().to_pylist()
+ assert len(files) == 1
+ assert files[0]["column_sizes"] is 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