Skip to content

Pandas replace does not work with booleans #27660

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

Closed
Mark531 opened this issue Jul 30, 2019 · 2 comments · Fixed by #27696
Closed

Pandas replace does not work with booleans #27660

Mark531 opened this issue Jul 30, 2019 · 2 comments · Fixed by #27696
Labels

Comments

@Mark531
Copy link

Mark531 commented Jul 30, 2019

Code Sample, a copy-pastable example if possible

import pandas as pd

df = pd.DataFrame({"col":[False, True]})
df.replace({"col": {False:0, True:1}})

Problem description

The previous code triggers the following error:
ValueError: Replacement not allowed with overlapping keys and values

Though, there is no overlapping and the replacement should be done properly.

Expected Output

 col

0 0
1 1

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.5.4.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 42 Stepping 7, GenuineIntel
byteorder: little
LC_ALL: None
LANG: fr
LOCALE: None.None

pandas: 0.22.0
pytest: 3.3.2
pip: 19.0.2
setuptools: 39.0.1
Cython: 0.27.3
numpy: 1.14.2
scipy: 1.0.0
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: 1.6.6
patsy: 0.5.0
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.4
feather: None
matplotlib: 2.2.2
openpyxl: 2.4.10
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.2
lxml: 4.1.1
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.2.1
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@WillAyd
Copy link
Member

WillAyd commented Jul 31, 2019

Thanks for the report. AFAICT this is only an issue when replacing a bool dtype with a value of 0 or 1. Investigation and PRs would certainly be welcome

@WillAyd WillAyd added the Bug label Jul 31, 2019
@WillAyd WillAyd added this to the Contributions Welcome milestone Jul 31, 2019
@charlesdong1991
Copy link
Member

PR is coming

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants