diff --git a/docs/changelog.rst b/docs/changelog.rst index aed59c3..edee837 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -5,6 +5,7 @@ Changelog Version 0.2.8 ============= +- [Variogram] is now ``pickle.dump()``-able, by removing ``lambda`` usage (thanks to @redhog!) - [Variogram] now raises a `Warning` if all input values are the same - [DOCS] Tutorial added and Dockerfile finalized - [Variogram] `normalize` default value changed to `normalize=False` diff --git a/skgstat/Kriging.py b/skgstat/Kriging.py index fe20659..3cd7162 100644 --- a/skgstat/Kriging.py +++ b/skgstat/Kriging.py @@ -105,7 +105,7 @@ def __init__( self.perf = perf # copy the distance function from the Variogram - self.dist = self.V.dist_function + self.dist = self.V._dist_func_wrapper params = self.V.describe() self.range = params['effective_range'] self.nugget = params['nugget'] diff --git a/skgstat/Variogram.py b/skgstat/Variogram.py index 29c6cc1..8970538 100644 --- a/skgstat/Variogram.py +++ b/skgstat/Variogram.py @@ -594,6 +594,12 @@ def use_nugget(self, nugget): def dist_function(self): return self._dist_func + def _dist_func_wrapper(self, x): + if callable(self._dist_func): + return self._dist_func(x) + else: + return pdist(X=x, metric=self._dist_func) + @dist_function.setter def dist_function(self, func): self.set_dist_function(func=func) @@ -626,7 +632,7 @@ def set_dist_function(self, func): raise NotImplementedError else: # if not ranks, it has to be a scipy metric - self._dist_func = lambda x: pdist(X=x, metric=func) + self._dist_func = func elif callable(func): self._dist_func = func @@ -1014,7 +1020,7 @@ def _calc_distances(self, force=False): else: _x = self._X # else calculate the distances - self._dist = self._dist_func(_x) + self._dist = self._dist_func_wrapper(_x) def _calc_diff(self, force=False): """Calculates the pairwise differences