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: dask expr is_unique & is_duplicated #803

Merged
merged 1 commit into from
Aug 16, 2024
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
26 changes: 22 additions & 4 deletions narwhals/_dask/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,12 +546,30 @@ def func(_input: Any) -> Any:
)

def is_duplicated(self: Self) -> Self:
msg = "`Expr.is_duplicated` is not support since Dask currently has no native duplicated check"
raise NotImplementedError(msg)
def func(_input: Any) -> Any:
_name = _input.name
return (
_input.to_frame().groupby(_name).transform("size", meta=(_name, int)) > 1
)

return self._from_call(
func,
"is_duplicated",
returns_scalar=False,
)

def is_unique(self: Self) -> Self:
msg = "`Expr.is_duplicated` is not support since Dask currently has no native duplicated check"
raise NotImplementedError(msg)
def func(_input: Any) -> Any:
_name = _input.name
return (
_input.to_frame().groupby(_name).transform("size", meta=(_name, int)) == 1
)

return self._from_call(
func,
"is_unique",
returns_scalar=False,
)

def is_in(self: Self, other: Any) -> Self:
return self._from_call(
Expand Down
2 changes: 0 additions & 2 deletions tests/expr_and_series/is_duplicated_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@


def test_is_duplicated_expr(constructor: Any, request: Any) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
if "modin" in str(constructor):
# TODO(unassigned): why is Modin failing here?
request.applymarker(pytest.mark.xfail)
Expand Down
2 changes: 0 additions & 2 deletions tests/expr_and_series/is_unique_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@


def test_is_unique_expr(constructor: Any, request: Any) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
if "modin" in str(constructor):
# TODO(unassigned): why is Modin failing here?
request.applymarker(pytest.mark.xfail)
Expand Down
Loading