Skip to content

ENH: updating subset types in drop_duplicates/duplicated #986

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 8 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 2 additions & 2 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -901,15 +901,15 @@ class DataFrame(NDFrame, OpsMixin):
) -> DataFrame | None: ...
def drop_duplicates(
self,
subset=...,
subset: Hashable | Iterable[Hashable] | None = ...,
*,
keep: NaPosition | _bool = ...,
inplace: _bool = ...,
ignore_index: _bool = ...,
) -> DataFrame: ...
def duplicated(
self,
subset: Hashable | Sequence[Hashable] | None = ...,
subset: Hashable | Iterable[Hashable] | None = ...,
keep: NaPosition | _bool = ...,
) -> Series: ...
@overload
Expand Down
20 changes: 20 additions & 0 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,26 @@ def test_types_dropna() -> None:
res3: None = df.dropna(axis=0, how="all", subset=["col1"], inplace=True)


def test_types_drop_duplicates() -> None:
# GH#59237
df = pd.DataFrame(
{
"AAA": ["foo", "bar", "foo", "bar", "foo", "bar", "bar", "foo"],
"B": ["one", "one", "two", "two", "two", "two", "one", "two"],
"C": [1, 1, 2, 2, 2, 2, 1, 2],
"D": range(8),
}
)

check(assert_type(df.drop_duplicates(["AAA"]), pd.DataFrame), pd.DataFrame)
check(assert_type(df.drop_duplicates(("AAA",)), pd.DataFrame), pd.DataFrame)
check(assert_type(df.drop_duplicates("AAA"), pd.DataFrame), pd.DataFrame)

if not PD_LTE_22:
check(assert_type(df.drop_duplicates({"AAA"}), pd.DataFrame), pd.DataFrame)
check(assert_type(df.drop_duplicates({"AAA": None}), pd.DataFrame), pd.DataFrame)


def test_types_fillna() -> None:
df = pd.DataFrame(data={"col1": [np.nan, np.nan], "col2": [3, np.nan]})
res: pd.DataFrame = df.fillna(0)
Expand Down
Loading