Skip to content

Fix TableScan.update to exclude cached properties #2178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pyiceberg/table/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1702,7 +1702,14 @@ def to_polars(self) -> pl.DataFrame: ...

def update(self: S, **overrides: Any) -> S:
"""Create a copy of this table scan with updated fields."""
return type(self)(**{**self.__dict__, **overrides})
from inspect import signature

# Extract those attributes that are constructor parameters. We don't use self.__dict__ as the kwargs to the
# constructors because it may contain additional attributes that are not part of the constructor signature.
params = signature(type(self).__init__).parameters.keys() - {"self"} # Skip "self" parameter
kwargs = {param: getattr(self, param) for param in params} # Assume parameters are attributes
Comment on lines +1709 to +1710
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevinjqliu, I wrote things slightly differently to #2178 (comment), LMKWYT of this.

Preferred getattr over self.__dict__ since it feels less low-level.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! this is great. lets add some comments to explain why we're doing this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! 776c433


return type(self)(**{**kwargs, **overrides})

def use_ref(self: S, name: str) -> S:
if self.snapshot_id:
Expand Down
13 changes: 13 additions & 0 deletions tests/integration/test_reads.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,3 +1057,16 @@ def test_initial_default(catalog: Catalog, spark: SparkSession) -> None:
result_table = tbl.scan().filter("so_true == True").to_arrow()

assert len(result_table) == 10


@pytest.mark.integration
@pytest.mark.parametrize("catalog", [pytest.lazy_fixture("session_catalog_hive"), pytest.lazy_fixture("session_catalog")])
def test_filter_after_arrow_scan(catalog: Catalog) -> None:
identifier = "test_partitioned_by_hours"
table = catalog.load_table(f"default.{identifier}")

scan = table.scan()
assert len(scan.to_arrow()) > 0

scan = scan.filter("ts >= '2023-03-05T00:00:00+00:00'")
assert len(scan.to_arrow()) > 0