Skip to content

Commit 660cd5f

Browse files
committed
warn when checking LazyFrame column membership
1 parent 267ddc3 commit 660cd5f

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

py-polars/src/polars/lazyframe/frame.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,12 @@ def __le__(self, other: Any) -> NoReturn:
740740
self._comparison_error("<=")
741741

742742
def __contains__(self, key: str) -> bool:
743+
issue_warning(
744+
"Determining column membership of a LazyFrame requires resolving its schema,"
745+
" which is a potentially expensive operation. Use `LazyFrame.collect_schema()`"
746+
" to inspect the schema without this warning.",
747+
category=PerformanceWarning,
748+
)
743749
return key in self.collect_schema()
744750

745751
def __copy__(self) -> LazyFrame:

py-polars/tests/unit/lazyframe/test_lazyframe.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,8 @@ def test_lf_properties() -> None:
14471447
assert lf.dtypes == [pl.Int64, pl.Float64, pl.String]
14481448
with pytest.warns(PerformanceWarning):
14491449
assert lf.width == 3
1450+
with pytest.warns(PerformanceWarning):
1451+
assert "foo" in lf
14501452

14511453

14521454
def test_lf_unnest() -> None:

0 commit comments

Comments
 (0)