-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: .loc
/.iloc
/.at
/iat
setitem coerces a pd.Series to np.ndarray with object dtype
#48933
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
Comments
BTW: The bug/issue was introduced with |
.loc
/.iloc
/.at
/iat
behave unexpected with object dtype
|
I came across this as well, trying to insert at Series in at a specified DataFrame index. Example if useful:
With pandas 1.4.4:
With pandas 1.5.1:
Note that the 'A' column is needed, else it gives |
take |
#49306 may solve this, but folks, trying to put a Series object inside a Series/DataFrame is a recipe for a bad time. |
moving to the 2.1 milestone |
.loc
/.iloc
/.at
/iat
behave unexpected with object dtype .loc
/.iloc
/.at
/iat
setitem coerce a pd.Series to np.ndarray with object dtype
.loc
/.iloc
/.at
/iat
setitem coerce a pd.Series to np.ndarray with object dtype .loc
/.iloc
/.at
/iat
setitem coerces a pd.Series to np.ndarray with object dtype
Pandas version checks
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 main branch of pandas.
Reproducible Example
Issue Description
A series with object dtype and a predefined index, cast items of type
pd.Series
tonp.ndarray
instead of preserving the series(-type). This apply to all accessorsloc
,iloc
,at
,iat
and only works correctly with__setitem__
..Expected Behavior
The elements in a series of dtype object should not be casted in any case.
Installed Versions
INSTALLED VERSIONS
commit : 87cfe4e
python : 3.10.6.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.0-48-generic
Version : #54-Ubuntu SMP Fri Aug 26 13:26:29 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.5.0
numpy : 1.23.3
pytz : 2022.2.1
dateutil : 2.8.2
setuptools : 59.8.0
pip : 22.2.2
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
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.6.0
numba : 0.56.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 9.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.9.1
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None
The text was updated successfully, but these errors were encountered: