Skip to content
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

BUG: inconsistency in dtype of replace() #44864

Closed
2 of 3 tasks
ShafinKhadem opened this issue Dec 13, 2021 · 1 comment · Fixed by #44897
Closed
2 of 3 tasks

BUG: inconsistency in dtype of replace() #44864

ShafinKhadem opened this issue Dec 13, 2021 · 1 comment · Fixed by #44897
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@ShafinKhadem
Copy link

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

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

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

Reproducible Example

import pandas as pd
s = pd.Series(['0'])
print(s.replace(to_replace='0', value=1, regex=False).dtype)  # shows int64
print(s.replace(to_replace='0', value=1, regex=True).dtype)  # shows object

Issue Description

dtype of replace() is different based on regex. When regex=False, dtype is int64. But when regex=True, dtype is object.

Expected Behavior

dtype in both cases should be the same, int64, as value=1

Installed Versions

INSTALLED VERSIONS

commit : 66e3805
python : 3.9.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.11.0-41-generic
Version : #45-Ubuntu SMP Fri Nov 5 11:37:01 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : en_US.utf8
LANG : en_US.utf8
LOCALE : en_US.UTF-8

pandas : 1.3.5
numpy : 1.21.4
pytz : 2021.3
dateutil : 2.8.1
pip : 20.3.4
setuptools : 52.0.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 7.30.1
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.4.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.7.3
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
None

@ShafinKhadem ShafinKhadem added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 13, 2021
vsydoriak99 added a commit to vsydoriak99/pandas that referenced this issue Dec 13, 2021
vsydoriak99 added a commit to vsydoriak99/pandas that referenced this issue Dec 13, 2021
vsydoriak99 added a commit to vsydoriak99/pandas that referenced this issue Dec 13, 2021
simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this issue Dec 14, 2021
@simonjayhawkins
Copy link
Member

Expected Behavior

dtype in both cases should be the same, int64, as value=1

This is a regression from 1.2.5

first bad commit: [f066cda] REF: avoid object-dtype casting in Block.replace (#40082)

cc @jbrockmendel

@simonjayhawkins simonjayhawkins added Regression Functionality that used to work in a prior pandas version Dtype Conversions Unexpected or buggy dtype conversions and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 14, 2021
@jreback jreback added this to the 1.4 milestone Dec 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants