BUG: Unclear FutureWarning regarding inplace iloc setitem

This issue has been created since 2022-09-21.

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

import numpy as np, pandas as pd
values = np.arange(4).reshape(2, 2)
df = pd.DataFrame(values, columns=["a", "b"])
new = np.array([10, 11]).astype(np.int16)
df.loc[:, "a"] = new

Issue Description

FutureWarning: In a future version, df.iloc[:, i] = newvals will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either df[df.columns[i]] = newvals or, if columns are non-unique, df.isetitem(i, newvals)

This is confusing because I did not do df.iloc, I did df.loc. In the release notes, the subsection header mentions .loc, but the text only talks about .iloc.

Additionally, it was very difficult to put together a reproducible example, until I found a related issue demonstrating that it matters whether the old/new series have different dtypes. This is reasonably clear from the release notes themselves, but not the warning message.

Expected Behavior

I assume that this change does affect both .loc and .iloc so the warning message could be updated to be more clear, but in the event it's a false alarm on .loc, it would be good to suppress it.

The warning message could also be a little bit more clear about why the warning got triggered (even if in a general sense).

Installed Versions

INSTALLED VERSIONS

commit : 87cfe4e
python : 3.10.0.final.0
python-bits : 64
OS : Darwin
OS-release : 21.6.0
Version : Darwin Kernel Version 21.6.0: Mon Aug 22 20:20:07 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T8110
machine : arm64
processor : arm
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 : 63.4.1
pip : 22.1.2
Cython : None
pytest : 7.1.3
hypothesis : None
sphinx : 5.1.1
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.1
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.5.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.6.0
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
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

mwaskom wrote this answer on 2022-09-21

Actually even looking at the release notes, I don't think I understand exactly what is deprecated here. The relevant section starts with

Most of the time setting values with DataFrame.iloc() attempts to set values inplace, only falling back to inserting a new array if necessary.

But then it says

This behavior is deprecated. In a future version, setting an entire column with iloc will attempt to operate inplace.

Isn't this what already happens ("most of the time"?) And if it's about different dtypes, how will that work? Do you mean to say it will coerce the dtype when setting the data?

anthonyaag wrote this answer on 2022-09-21

Seems like this warning was added in #45333 along with a some TODOs to get more info. Maybe @jbrockmendel has some guidance on what to do here.

More Details About Repo
Owner Name pandas-dev
Repo Name pandas
Full Name pandas-dev/pandas
Language Python
Created Date 2010-08-24
Updated Date 2022-09-29
Star Count 35374
Watcher Count 1122
Fork Count 15034
Issue Count 3579

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
更改监听地址防止prometheus无法连接核心组件 2 2022-04-28 2022-09-16
[BUG][FEATURE] Display correct reason for which check couldn't run 0 2022-05-26 2022-09-21
Python3 Compability for latest version of Module Package 2 2022-02-24 2022-08-20
Dragonfly Plate and Surge? 4 2021-02-22 2022-09-02
Plugins vst not working 2 2021-01-02 2022-09-14
[Bug]: PWA icons do not load on iOS/iPadOS 7 2022-03-15 2022-09-28
It shows a line on the taskbar 1 2021-07-29 2022-09-08
--no-osd-bar disappears from mpv.conf 4 2022-07-26 2022-09-02
请教是否可以实现群组文件搜索,谢谢。 2 2021-05-20 2022-01-06
Be able to drag pages to where you want them in the side bar 1 2022-01-17 2022-09-05
Controlled radio button list listens to select even on listitem 0 2020-05-28 2022-07-29
Board rendered as a Linked database is not being rendered. NotionAPI collectionQuery error Cannot set property 'group_by' of undefined 2 2021-08-01 2022-08-10
Exasol L026 - Fails on SELECT INTO TABLE statement 2 2021-11-04 2022-09-20
tibble allows to set a column 'names' attribute while data.frame does not 2 2022-06-30 2022-09-13
Android Support for API < 24 4 2021-05-14 2022-08-26
Postfix await 2 2020-01-08 2021-12-05
Question: how to listen to several events of the same type 3 2021-02-08 2022-09-23
Check if remote store has existing backup when creating a new backup 0 2016-03-24 2022-09-20
prepared statement \"s0\" already exists 12 2022-02-04 2022-07-19
include db files in the deb package, create step to download them in the build.sh 0 2021-01-01 2022-07-29
When i open KeyPassXC it disables my Nvidea GeForce Experience Instant Replay 2 2022-07-18 2022-08-18
bug: Value {messageGroupId} for parameter MessageGroupId is invalid 7 2022-02-10 2022-09-11
Add to cart only accepts 1 item per product 0 2021-11-30 2022-09-28
How do I setup session affinity? 5 2022-05-12 2022-09-28
Confirmation of Action: (ariaNotify) general feedback for consideration 7 2022-02-11 2022-09-17
Load test tile servers 1 2022-06-19 2022-09-11
Tuist dont support using macOS bundle in a mac Catalyst target 2 2021-11-22 2022-08-27
Please upgrade apisauce to fix npm audit on axios version 1 2021-01-20 2022-09-21
Publishing a plugin fails due to missing files in the manifest 1 2021-01-27 2022-09-24
Showing the Properties of a Blob does not display it's ContentMD5 value 4 2022-09-15 2022-09-22
Unable to retrieve child resources. 3 2022-09-17 2022-09-22
Logout from Account? 4 2022-09-16 2022-09-22
Query params are not available within load function with adapter-vercel when prerendering 1 2021-07-30 2022-09-25
Feature: GM command to force rename a pet 1 2022-02-05 2022-09-19
Feature: pool_pool table implementation 1 2022-02-04 2022-09-19
Dev tools - index deploy script needs to skip pre-built guides 0 2022-02-04 2022-09-16
Exception when to disconnect. 14 2020-04-23 2022-07-03
Boolean attribute getters throw if the attribute name is not all lowercase 7 2016-05-29 2022-09-09
Recurring payments 2 2021-08-20 2022-01-15
Implement proof aggregation scheme 0 2021-03-30 2022-07-03
Cannot start any PS game, thank you.Old versions works. Now - nope. 5 2022-09-04 2022-09-27
[3DS] bottom_menu.png not found 10 2022-09-03 2022-09-27
Content scanner writes wrong path in playlist if archived file contains accented character 1 2022-08-29 2022-09-27
Can you move managed instance to another subnet or not? 2 2021-09-10 2022-08-07
Design docs refactor 0 2021-11-05 2022-08-05
org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments: Could not find corresponding inner/nested class FirFakeOverrideGenerator.Maybe.Value in class org.jetbrains.kotlin.fir.scopes.impl.FirFakeOverrideGenerator.Maybe.ValueFile: FirFakeOverrideGenerator.class 0 2022-08-06 2022-09-13
[Security] Workflow breakage-against-ponyc-latest.yml is using vulnerable action actions/checkout 0 2021-12-20 2022-07-30
Autocomplete not working after using whitespace 1 2022-02-10 2022-08-31
Filter out internal users not working 9 2022-02-11 2022-09-08
horovod.common.exceptions.HorovodInternalError: Broadcast is not supported with Join at this time. 2 2021-08-19 2022-09-13