Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixing some failing tests that turned up in #55732. This PR specifically fixes
pandas/tests/window/test_online.py::TestEWM::test_online_vs_non_online_mean
for Copy-on-Write enabled.The numba function takes the underlying frame's array of values, and then writes into those values:
pandas/pandas/core/window/online.py
Line 80 in c36e302
(this
weighted_avg
is a view in the passed values, fromweighted_avg = values[0]
)That currently doesn't cause a bug, because before getting the values from the frame and passing it to the numba func, we cast to float64:
pandas/pandas/core/window/ewm.py
Line 1071 in c36e302
This
astype()
call currently always returns a copy by default (even if you already have all float64 columns), but with CoW enabled, this avoids making a copy. Currently, with CoW enabled, the numba func fails because of the numpy array being marked as read-only. But if we wouldn't manually copy the data and just ignore this read-only flag, we would be mutating the calling dataframe (so marking as read-only prevented a new bug here!).