From 70a10ba6ca9267c68b69b0f0de1f0c6151cd1198 Mon Sep 17 00:00:00 2001 From: Said Obakrim <47177344+sobakrim@users.noreply.github.com> Date: Mon, 2 Mar 2026 17:34:08 +0100 Subject: [PATCH] Refactor execute method to support ndarray for points Updated execute method to accept both dict and ndarray for points, enhancing flexibility. Adjusted how points are processed and passed to the model. --- src/pykrige/compat.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/pykrige/compat.py b/src/pykrige/compat.py index d0ca37c..98a8306 100644 --- a/src/pykrige/compat.py +++ b/src/pykrige/compat.py @@ -267,27 +267,40 @@ def predict(self, x, *args, **kwargs): return self.execute(points, *args, **kwargs)[0] def execute(self, points, *args, **kwargs): - # TODO array of Points, (x, y) pairs of shape (N, 2) """ Execute. - + Parameters ---------- - points: dict - + points: dict OR ndarray + - dict: must contain xpoints/ypoints (and zpoints for 3D) + - ndarray: shape (N,2) for 2D or (N,3) for 3D + Returns ------- - Prediction array - Variance array + prediction: ndarray + variance: ndarray """ + # Accept array-like points for convenience + if not isinstance(points, dict): + pts = np.asarray(points) + if pts.ndim == 1: + pts = pts.reshape(1, -1) + points = self._dimensionality_check(pts, ext="points") + default_kw = dict(style="points", backend="loop") default_kw.update(kwargs) - points.update(default_kw) + + pts_kw = dict(points) + pts_kw.update(default_kw) + if isinstance(self.model, (OrdinaryKriging, OrdinaryKriging3D)): - points.update(dict(n_closest_points=self.n_closest_points)) + pts_kw.update(dict(n_closest_points=self.n_closest_points)) else: print("n_closest_points will be ignored for UniversalKriging") - prediction, variance = self.model.execute(**points) + pass + + prediction, variance = self.model.execute(**pts_kw) return prediction, variance