BUG: dtype changes when row passed to a function via DataFrame.apply() #43503
Labels
Apply
Apply, Aggregate, Transform
Bug
Categorical
Categorical Data Type
Dtype Conversions
Unexpected or buggy dtype conversions
Reproducible Example
Issue Description
When I "iterate" on row level via
DataFrame.apply(foo, axis=1)
thedtype
of the columns are changing.Here in the MWE a
category
becomesobject
and anint8
becomes `int64'.The argument
result_type=
seems to have no effect. The MWE checks each possible option for it.This is the output of the MWE
Expected Behavior
Just keep the
dtype
. Do not convert it without users permission. or minimally throw a warning if there is a good reason for it.Possible related #42001
Installed Versions
INSTALLED VERSIONS
commit : 5f648bf
python : 3.9.4.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.18362
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 12, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : de_DE.cp1252
pandas : 1.3.2
numpy : 1.21.1
pytz : 2021.1
dateutil : 2.8.1
pip : 21.2.4
setuptools : 57.0.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.23.1
pandas_datareader: None
bs4 : 4.9.3
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.4.2
numexpr : None
odfpy : None
openpyxl : 3.0.7
pandas_gbq : None
pyarrow : 4.0.1
pyxlsb : None
s3fs : None
scipy : 1.7.0
sqlalchemy : 1.4.13
tables : None
tabulate : 0.8.9
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: