Skip to content

BUG: fix online ewma with CoW #55735

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

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/core/window/ewm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ def mean(self, *args, update=None, update_times=None, **kwargs):
result_kwargs["columns"] = self._selected_obj.columns
else:
result_kwargs["name"] = self._selected_obj.name
np_array = self._selected_obj.astype(np.float64).to_numpy()
np_array = self._selected_obj.astype(np.float64, copy=False).to_numpy()
ewma_func = generate_online_numba_ewma_func(
**get_jit_arguments(self.engine_kwargs)
)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/window/online.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def online_ewma(
exponentially weighted mean accounting minimum periods.
"""
result = np.empty(values.shape)
weighted_avg = values[0]
weighted_avg = values[0].copy()
Copy link
Member Author

@jorisvandenbossche jorisvandenbossche Oct 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the copy here inside the function, instead of copying the full array before passing it to the function, since here we only need to copy the first row of the array.

This copy ensures we don't mutate the passed values, and then this numba func will work fine on read-only input.

nobs = (~np.isnan(weighted_avg)).astype(np.int64)
result[0] = np.where(nobs >= minimum_periods, weighted_avg, np.nan)

Expand Down