We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas. (v1.2.4)
(optional) I have confirmed this bug exists on the master branch of pandas.
There is a bug when calling Series.replace(List, ...), the Series gets converted to dtype 'object', which is incorrect.
Let's start with a simple example that works as expected.
df = pd.DataFrame({'a': ['abc', 'def']}, dtype="string") s0 = df["a"].replace('abc', 'xyz') print(s0)
The output is as expected, and Series has maintained the type string:
0 xyz 1 def Name: a, dtype: string
But when calling Series.replace(List, ...), Series gets converted to dtype object, which is incorrect.
s1 = df["a"].replace(['abc', 'any other string'], "xyz" ) print(s1)
Output:
0 xyz 1 def Name: a, dtype: object
Datatype of Series should not change when using a different argument to Series.replace().
pd.show_versions()
commit : 2cb9652 python : 3.8.3.final.0 python-bits : 64 OS : Darwin OS-release : 19.6.0 Version : Darwin Kernel Version 19.6.0: Thu Oct 29 22:56:45 PDT 2020; root:xnu-6153.141.2.2~1/RELEASE_X86_64 machine : x86_64 processor : i386 byteorder : little LC_ALL : None LANG : None LOCALE : None.UTF-8
pandas : 1.2.4 numpy : 1.19.4 pytz : 2020.4 dateutil : 2.8.1 pip : 21.0.1 setuptools : 56.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 : None pandas_datareader: None bs4 : None bottleneck : None fsspec : None fastparquet : None gcsfs : None matplotlib : 3.4.1 numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : None pyxlsb : None s3fs : None scipy : 1.6.2 sqlalchemy : None tables : None tabulate : 0.8.7 xarray : None xlrd : None xlwt : None numba : None
The text was updated successfully, but these errors were encountered:
Thanks for the report @EdGaere! Persists on master, probably same underlying issue as #40732
Sorry, something went wrong.
Successfully merging a pull request may close this issue.
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas. (v1.2.4)
(optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample, a copy-pastable example
There is a bug when calling Series.replace(List, ...), the Series gets converted to dtype 'object', which is incorrect.
Let's start with a simple example that works as expected.
The output is as expected, and Series has maintained the type string:
But when calling Series.replace(List, ...), Series gets converted to dtype object, which is incorrect.
Output:
Problem description
Datatype of Series should not change when using a different argument to Series.replace().
Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : 2cb9652
python : 3.8.3.final.0
python-bits : 64
OS : Darwin
OS-release : 19.6.0
Version : Darwin Kernel Version 19.6.0: Thu Oct 29 22:56:45 PDT 2020; root:xnu-6153.141.2.2~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8
pandas : 1.2.4
numpy : 1.19.4
pytz : 2020.4
dateutil : 2.8.1
pip : 21.0.1
setuptools : 56.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 : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.4.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.6.2
sqlalchemy : None
tables : None
tabulate : 0.8.7
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: