Skip to content

[Draft] Fix TableScan updating with arguments method #2199

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
16 changes: 15 additions & 1 deletion pyiceberg/table/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1691,7 +1691,21 @@ 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})
return type(self)(**{**self._arguments, **overrides})

@property
def _arguments(self) -> dict[str, Any]:
"""Return the arguments for TableScan creation. Subclasses with additional constructor arguments should override this to include them."""
return {
"table_metadata": self.table_metadata,
"io": self.io,
"row_filter": self.row_filter,
"selected_fields": self.selected_fields,
"case_sensitive": self.case_sensitive,
"snapshot_id": self.snapshot_id,
"options": self.options,
"limit": self.limit,
}

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 @@ -1024,3 +1024,16 @@ def test_scan_with_datetime(catalog: Catalog) -> None:

df = table.scan(row_filter=LessThan("datetime", yesterday)).to_pandas()
assert len(df) == 0


@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