From 984d75543fce5c68f0dcc4f0b3500256e4a9c0c9 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Fri, 27 Oct 2023 23:49:15 +0200 Subject: [PATCH] BUG: fix online ewma with CoW (#55735) --- pandas/core/window/ewm.py | 2 +- pandas/core/window/online.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/window/ewm.py b/pandas/core/window/ewm.py index 775f3cd428677..82b4746aa57a5 100644 --- a/pandas/core/window/ewm.py +++ b/pandas/core/window/ewm.py @@ -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) ) diff --git a/pandas/core/window/online.py b/pandas/core/window/online.py index f9e3122b304bc..29d1f740e021f 100644 --- a/pandas/core/window/online.py +++ b/pandas/core/window/online.py @@ -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() nobs = (~np.isnan(weighted_avg)).astype(np.int64) result[0] = np.where(nobs >= minimum_periods, weighted_avg, np.nan)