-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: Allow inplace arithmetic operations #5104
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
with dtype conversion....seems ok?
|
It works but it's not actually in place (with
|
oh...i c....prob don't have tests for that I thought was ok (did it work before?) |
as I said, hasn't worked that way since at least v0.12, not sure if earlier. |
I'll take a look |
Looked back, hasn't (truly) supported inplace ops since at least 0.9 (at least not for DataFrame, and Series appears to have overridden inplace ops) |
ok....should be straightforward in any event |
Would also be nice to have in-place versions of |
@BrenBarn even if you had inplace ops, pandas isn't actually going to do it inplace (i.e., it'll still allocate new memory for the final arrays). It would be relatively easy to add an My problem is that it's a total lie to the end user: you think that you're doing an operation inplace and that this will mean you are saving on memory, but all you would be doing is a convenience function that just updates the wrapper. |
I see. So you mean it's simply not possible to update Pandas structures in-place at all? That is unfortunate. |
@BrenBarn the structures CAN be updated in some cases in-place (a lot depends on what kind of operation it is), but for example, the operation would have to be 2 structures that are alignable w/o copy, and the operation itself would then be done in-place. e.g. arithmetic is straightforward. Any type of reshape or dtype change would invalidate this. Would welcome some tests for this; that is the main issue. I don't think making is work all that hard. |
But this whole issue is about arithmetic operations, right? I'm not saying every possible manipulation should be available in-place, just basic ones that can already be done in-place on numpy arrays (e.g., |
@BrenBarn this could be done when the op doesn't change dtype, however, I think this might actually be more confusing, because their would be a subset of ops that are actually in-place, while most would not actually modify the underlying data, but replace it (as happens now in all cases). This would be deterministic, but IMHO confusing to the user. A simple case of when its not possible is changes, e.g.
Numpy keeps the same object, but just does a wrong thing IMHO
|
just to echo @jreback - I did not mean it's impossible to update inplace, |
In-place operations have unfortunate complications when coupled with automatic index-based alignment, as I discovered when I tried to implement this for xray: The problem is that you can end up with (int, int) operations giving you complete garbage if the second argument needs to be realigned and hence ends up with a bunch of NaN values. Numpy does not catch in-place integer operations with non-scalar
|
In current master (and before the initial arithmetic refactor),
__iadd__
doesn't do anything, it's just a synonym for__add__
(or not defined). (just for reference,v0.12.0
had__iadd__ = __add__
onSeries
and no__add__
defined onDataFrame
). It would be great to support in place ops on+=
and friends. Is this possible to do?The text was updated successfully, but these errors were encountered: