Skip to content

Commit 3299527

Browse files
kirill-bashDr-Irv
andauthored
ENH: updating subset types in drop_duplicates/duplicated (#986)
* updating subset types * adding pytest * updating based on feedback * updating based on feedback * updating based on feedback * correcting conditional Co-authored-by: Irv Lustig <[email protected]> * complying with black formatting --------- Co-authored-by: Irv Lustig <[email protected]>
1 parent 96be866 commit 3299527

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

pandas-stubs/core/frame.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -901,15 +901,15 @@ class DataFrame(NDFrame, OpsMixin):
901901
) -> DataFrame | None: ...
902902
def drop_duplicates(
903903
self,
904-
subset=...,
904+
subset: Hashable | Iterable[Hashable] | None = ...,
905905
*,
906906
keep: NaPosition | _bool = ...,
907907
inplace: _bool = ...,
908908
ignore_index: _bool = ...,
909909
) -> DataFrame: ...
910910
def duplicated(
911911
self,
912-
subset: Hashable | Sequence[Hashable] | None = ...,
912+
subset: Hashable | Iterable[Hashable] | None = ...,
913913
keep: NaPosition | _bool = ...,
914914
) -> Series: ...
915915
@overload

tests/test_frame.py

+22
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,28 @@ def test_types_dropna() -> None:
368368
res3: None = df.dropna(axis=0, how="all", subset=["col1"], inplace=True)
369369

370370

371+
def test_types_drop_duplicates() -> None:
372+
# GH#59237
373+
df = pd.DataFrame(
374+
{
375+
"AAA": ["foo", "bar", "foo", "bar", "foo", "bar", "bar", "foo"],
376+
"B": ["one", "one", "two", "two", "two", "two", "one", "two"],
377+
"C": [1, 1, 2, 2, 2, 2, 1, 2],
378+
"D": range(8),
379+
}
380+
)
381+
382+
check(assert_type(df.drop_duplicates(["AAA"]), pd.DataFrame), pd.DataFrame)
383+
check(assert_type(df.drop_duplicates(("AAA",)), pd.DataFrame), pd.DataFrame)
384+
check(assert_type(df.drop_duplicates("AAA"), pd.DataFrame), pd.DataFrame)
385+
386+
if not PD_LTE_22:
387+
check(assert_type(df.drop_duplicates({"AAA"}), pd.DataFrame), pd.DataFrame)
388+
check(
389+
assert_type(df.drop_duplicates({"AAA": None}), pd.DataFrame), pd.DataFrame
390+
)
391+
392+
371393
def test_types_fillna() -> None:
372394
df = pd.DataFrame(data={"col1": [np.nan, np.nan], "col2": [3, np.nan]})
373395
res: pd.DataFrame = df.fillna(0)

0 commit comments

Comments
 (0)