Skip to content

Commit e132d85

Browse files
authored
BUG: Validate drop_duplicates ignore_index argument for bool (#38277)
1 parent 492806e commit e132d85

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

doc/source/whatsnew/v1.2.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,7 @@ Reshaping
796796
- Bug in :func:`merge_ordered` couldn't handle list-like ``left_by`` or ``right_by`` (:issue:`35269`)
797797
- Bug in :func:`merge_ordered` returned wrong join result when length of ``left_by`` or ``right_by`` equals to the rows of ``left`` or ``right`` (:issue:`38166`)
798798
- Bug in :func:`merge_ordered` didn't raise when elements in ``left_by`` or ``right_by`` not exist in ``left`` columns or ``right`` columns (:issue:`38167`)
799+
- Bug in :func:`DataFrame.drop_duplicates` not validating bool dtype for ``ignore_index`` keyword (:issue:`38274`)
799800

800801
Sparse
801802
^^^^^^

pandas/core/frame.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5273,6 +5273,7 @@ def drop_duplicates(
52735273
return self.copy()
52745274

52755275
inplace = validate_bool_kwarg(inplace, "inplace")
5276+
ignore_index = validate_bool_kwarg(ignore_index, "ignore_index")
52765277
duplicated = self.duplicated(subset, keep=keep)
52775278

52785279
result = self[-duplicated]

pandas/tests/frame/methods/test_drop_duplicates.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,3 +459,12 @@ def test_drop_duplicates_series_vs_dataframe(keep):
459459
dropped_frame = df[[column]].drop_duplicates(keep=keep)
460460
dropped_series = df[column].drop_duplicates(keep=keep)
461461
tm.assert_frame_equal(dropped_frame, dropped_series.to_frame())
462+
463+
464+
@pytest.mark.parametrize("arg", [[1], 1, "True", [], 0])
465+
def test_drop_duplicates_non_boolean_ignore_index(arg):
466+
# GH#38274
467+
df = DataFrame({"a": [1, 2, 1, 3]})
468+
msg = '^For argument "ignore_index" expected type bool, received type .*.$'
469+
with pytest.raises(ValueError, match=msg):
470+
df.drop_duplicates(ignore_index=arg)

0 commit comments

Comments
 (0)