Skip to content
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

feat: add duckdb dataframe drop_nulls #1811

Merged
merged 5 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 7 additions & 7 deletions narwhals/_dask/dataframe.py
FBruzzesi marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,13 @@ def join_asof(
self,
other: Self,
*,
left_on: str | None = None,
right_on: str | None = None,
on: str | None = None,
by_left: str | list[str] | None = None,
by_right: str | list[str] | None = None,
by: str | list[str] | None = None,
strategy: Literal["backward", "forward", "nearest"] = "backward",
left_on: str | None,
right_on: str | None,
on: str | None,
by_left: str | list[str] | None,
by_right: str | list[str] | None,
by: str | list[str] | None,
strategy: Literal["backward", "forward", "nearest"],
) -> Self:
plx = self.__native_namespace__()
return self._from_native_frame(
Expand Down
9 changes: 9 additions & 0 deletions narwhals/_duckdb/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,12 @@ def sort(
)
)
return self._from_native_frame(result)

def drop_nulls(self: Self, subset: str | list[str] | None) -> Self:
import duckdb

rel = self._native_frame
subset_ = subset if subset is not None else rel.columns
keep_condition = " and ".join(f"{col} is not null" for col in subset_)
query = f"""select * from rel where {keep_condition}""" # noqa: S608
return self._from_native_frame(duckdb.sql(query))
14 changes: 7 additions & 7 deletions narwhals/_pandas_like/dataframe.py
FBruzzesi marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -654,13 +654,13 @@ def join_asof(
self,
other: Self,
*,
left_on: str | None = None,
right_on: str | None = None,
on: str | None = None,
by_left: str | list[str] | None = None,
by_right: str | list[str] | None = None,
by: str | list[str] | None = None,
strategy: Literal["backward", "forward", "nearest"] = "backward",
left_on: str | None,
right_on: str | None,
on: str | None,
by_left: str | list[str] | None,
by_right: str | list[str] | None,
by: str | list[str] | None,
strategy: Literal["backward", "forward", "nearest"],
) -> Self:
plx = self.__native_namespace__()
return self._from_native_frame(
Expand Down
7 changes: 1 addition & 6 deletions tests/frame/drop_nulls_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
}


def test_drop_nulls(constructor: Constructor, request: pytest.FixtureRequest) -> None:
if "duckdb" in str(constructor):
request.applymarker(pytest.mark.xfail)
def test_drop_nulls(constructor: Constructor) -> None:
result = nw.from_native(constructor(data)).drop_nulls()
expected = {
"a": [2.0, 4.0],
Expand All @@ -35,9 +33,6 @@ def test_drop_nulls_subset(
constructor: Constructor,
subset: str | list[str],
expected: dict[str, float],
request: pytest.FixtureRequest,
) -> None:
if "duckdb" in str(constructor):
request.applymarker(pytest.mark.xfail)
result = nw.from_native(constructor(data)).drop_nulls(subset=subset)
assert_equal_data(result, expected)
Loading