Skip to content

BUG: pandas.dataframe.drop_duplicates ignore_index parameter #38274

Closed
@dannemarre

Description

@dannemarre
  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

import unittest
import pandas as pd

class Test(unittest.TestCase):
    def testError(self):
        cars = {'Brand': ['Honda Civic','Toyota Corolla','Ford Focus','Audi A4'],
                'Price': [22000,25000,27000,35000]
                }

        df = pd.DataFrame(cars, columns = ['Brand', 'Price'])
        dataError = df.drop_duplicates(ignore_index='error')
        print("Should give ValueError: \n"+
            "   ValueError: For argument ignore_index expected type bool, received type str.")

if __name__ == '__main__' :
    unittest.main()

Problem description

Hi! So I am doing white testing for school and found a tiny bug in drop_duplicates. When using the boolean parameter "ignore_index" it does not check if it is boolean or not. The "inplace" parameter is checked using the function validate_bool_kwarg(--). The "ignore_index" should be checked the same way. I have never reported a bug and I could fix it myself but I am a bit afraid to mess things up. Thank you!

Expected Output

ValueError: For argument "ignore_index" expected type bool, received type str.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 2a7d332
python : 3.8.5.final.0
python-bits : 64
OS : Linux
OS-release : 4.19.104-microsoft-standard
Version : #1 SMP Wed Feb 19 06:37:35 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.1.2
numpy : 1.19.2
pytz : 2020.1
dateutil : 2.8.1
pip : 20.0.2
setuptools : 45.2.0
Cython : None
pytest : None
hypothesis : None
sphinx : 3.2.1
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10.1
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.2
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugduplicatedduplicated, drop_duplicates

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions