-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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: Unclear FutureWarning regarding inplace iloc setitem #48673
Comments
Actually even looking at the release notes, I don't think I understand exactly what is deprecated here. The relevant section starts with
But then it says
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? |
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. |
I'm seeing this same behaviour in another package (bug report linked above). Can confirm it's also when a change in dtype is happening, and with |
Could change "iloc" to "loc/iloc"? |
I'm not sure that's a sufficient change @jbrockmendel because |
What's the difference between inplace and setting a new array? Neither the warning, nor the release notes makes this very clear to me. I have a script that runs I also don't see how either |
Definitely open to suggestions for better wording. Let me try to explain using the OP example:
At this point the DataFrame There are types of setting (e.g. Unfortunately, because of [reasons], the existing behavior is not super-consistent in when we do inplace vs not-inplace. That's why this particular case is deprecated, so in 2.0 we can make the behavior more consistent. In particular, in your case:
In the current behavior, Is that helpful? If you have suggestions to make the warning or docs clearer, please let us know. |
Is there a way to disable this warning? For example, I have gotten the warning, and I acknowledge that this behavior will change and am OK with it, can I disable the warning? Why? I have warnings turned into errors in my test suite so that I can catch potential pandas-misuse, but this new warning causes my tests to fail with (as far as I can tell) no way to disable the warning. |
|
@jbrockmendel Yes, that is what I ended up doing, but that's not what I was hoping. To the best of my knowledge, other warnings from In this case, it seems more informative than a true warning, at least in the case where I am OK with the setting being in-place in the future (which I am). I am OK with using the warnings filter, but I was hoping for some way to suppress it at the |
I'm getting this warning indirectly when I call |
this issue is quite annoying... |
Me too,
The warning message essentially says that |
I'm getting this with both:
and the equivalent (in my case):
Additionally, neither line's syntax matches the warning, which just adds to the confusion. It is clear from this bug report that the warning itself should not be showing regardless. This StackOverflow entry directly references the |
Seeing as this warning shows up in places where users can't do anything about it, perhaps we should consider removing the warning? I think most users don't care too much about whether the operation is truly in-place or not, so just making the breaking change in 2.0.0 seems unlikely to do much harm, especially if:
Furthermore, I don't think we should encourage |
I'd second this idea. If this is only a breaking change in the next major release, in my opinion, this would be an acceptable and preferred approach for me. |
Works for me. |
awesome - if anyone here wants to make a PR, that'd be welcome https://pandas.pydata.org/docs/development/contributing.html |
take |
Should the fix also include a test in tests subdirectory to confirm that a warning is not raised? |
yeah, you could use |
Hi @MarcoGorelli ,
Please let me know if my understanding is correct My question is should the warning call inside this function be removed entirely? or since the warning is related to |
Do we still want to consider removing the warning? If so, then ideally we should do that for 1.5.3? |
I'd highly welcome that. But the PR around that seems stalled. Also, as I read the discussion here and in the PR, there doesn't really seem to be a consensus about what to do with this warning. (Remove it, change it, ...) |
They must undo this warning because it creates highly undesirable consequences. Next, they should book and complete an Ayahuasca therapy session because they obviously cannot resolve this issue at their current level of conciousness and understanding. |
@max0x7ba please refrain from such comments (the second paragraph), that's not helpful at all |
In the PR, it was suggested we could also turn the FutureWarning into a DeprecationWarning (#50044 (comment)) That would at least make it less noisy for end users (i.e. if they use a method from a package that triggers this, they by default won't see see it). So I think there are basically three options:
|
1 is not really an option, since we can not correctly guess all cases where the behavior would change (I think) I'd be in favour of a DeprecationWarning, removing is a bit weird imo, since this reflects to users that we don't want to do this change, but it's already enforced on main |
It is an option by expanding the message to make it correct for all those different cases ...
For users that already bumped into the warning, and then don't see it anymore at some point, they might indeed think it is solved and they don't need to do anything. But 1) we can clearly communicate in the whatsnew that this is not the reason the warning is removed (I know, not everyone reads this), and 2) for many users that still have to update to 1.5 that's not an issue. |
Making it a deprecation warning is fine, imo. Then, as package developer, I can supress it from my logs once I have verified it's not a problem and users won't be bothered. |
The message would get awfully long and probably wouldn't be complete anyway. Initially, I'd have prefered option 3, but since we added it in 1.5 I would prefer 2 now for 1.5.3 Edit: I misread your option 1 initially, I thought the fix was referring the warning not the message |
This comment was marked as off-topic.
This comment was marked as off-topic.
@max0x7ba just out of curiosity, how much are you paying for this massively complex, 3.5k-issue, OSS that you are totally entitled to SLAs and world-class service on? It's a warning. Relax or find a different tool. |
Closed by #50044 As an aside, I'd suggest enforcing the code of conduct more and banning toxic users, there's nothing to be gained by having them around and they disincentivise people from contributing |
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
This is confusing because I did not do
df.iloc
, I diddf.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
The text was updated successfully, but these errors were encountered: