From 9437a0a7f53d7ab8c73a926c5a0f0e9bd6673bba Mon Sep 17 00:00:00 2001 From: FBruzzesi Date: Wed, 7 Aug 2024 22:38:48 +0200 Subject: [PATCH] list -> numpy constant creation --- sklego/meta/grouped_predictor.py | 2 +- sklego/meta/hierarchical_predictor.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sklego/meta/grouped_predictor.py b/sklego/meta/grouped_predictor.py index f751503c..40878201 100644 --- a/sklego/meta/grouped_predictor.py +++ b/sklego/meta/grouped_predictor.py @@ -153,7 +153,7 @@ def __add_shrinkage_column(self, frame, groups=None): frame = frame.select( nw.from_dict( - data={self._global_col_name: [self._global_col_value] * n_samples}, + data={self._global_col_name: np.full(shape=n_samples, fill_value=self._global_col_value)}, native_namespace=nw.get_native_namespace(frame), )[self._global_col_name], nw.all(), diff --git a/sklego/meta/hierarchical_predictor.py b/sklego/meta/hierarchical_predictor.py index 30c1ba36..5d71cc5c 100644 --- a/sklego/meta/hierarchical_predictor.py +++ b/sklego/meta/hierarchical_predictor.py @@ -283,7 +283,7 @@ def fit(self, X, y=None): native_namespace = nw.get_native_namespace(X) target_series = nw.from_dict({self._TARGET_NAME: y}, native_namespace=native_namespace)[self._TARGET_NAME] - global_series = nw.from_dict({self._GLOBAL_NAME: [1] * n_samples}, native_namespace=native_namespace)[ + global_series = nw.from_dict({self._GLOBAL_NAME: np.ones(n_samples)}, native_namespace=native_namespace)[ self._GLOBAL_NAME ] frame = X.with_columns( @@ -322,7 +322,7 @@ def _predict_estimators(self, X, method_name): n_samples = X.shape[0] native_namespace = nw.get_native_namespace(X) - global_series = nw.from_dict({self._GLOBAL_NAME: [1] * n_samples}, native_namespace=native_namespace)[ + global_series = nw.from_dict({self._GLOBAL_NAME: np.ones(n_samples)}, native_namespace=native_namespace)[ self._GLOBAL_NAME ]