From d8a44856741cad334cf02e93ccf23d2cd6b05b46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Tue, 21 Jun 2022 09:37:59 +0200 Subject: [PATCH 1/4] Coverage: add missing checks for variogram fit --- tests/test_covmodel.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_covmodel.py b/tests/test_covmodel.py index 741129d6..415bc691 100644 --- a/tests/test_covmodel.py +++ b/tests/test_covmodel.py @@ -279,11 +279,20 @@ def test_fitting(self): # init guess with self.assertRaises(ValueError): model.fit_variogram(self.gamma_x, self.gamma_y, init_guess="wrong") + with self.assertRaises(ValueError): + model.fit_variogram( + self.gamma_x, self.gamma_y, init_guess={"wrong": 1} + ) + # sill fixing model.var_bounds = [0, np.inf] model.fit_variogram( self.gamma_x, np.array(self.gamma_y) + 1, sill=2, alpha=False ) self.assertAlmostEqual(model.var + model.nugget, 2) + # check isotropicity for latlon models + model = Stable(latlon=True) + with self.assertRaises(ValueError): + model.fit_variogram(self.gamma_x, 3 * [self.gamma_y]) def test_covmodel_class(self): model_std = Gaussian(rescale=3, var=1.1, nugget=1.2, len_scale=1.3) From dd9dd45de113ff1ed4f4ea1fb6094da00fde1a04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Tue, 21 Jun 2022 00:31:46 +0200 Subject: [PATCH 2/4] Cython: solve -Wsometimes-uninitialized warning - not adding low-level checks --- src/gstools/variogram/estimator.pyx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gstools/variogram/estimator.pyx b/src/gstools/variogram/estimator.pyx index 6c5a67df..a3f40b5e 100644 --- a/src/gstools/variogram/estimator.pyx +++ b/src/gstools/variogram/estimator.pyx @@ -156,7 +156,7 @@ cdef _estimator_func choose_estimator_func(str estimator_type): cdef _estimator_func estimator_func if estimator_type == 'm': estimator_func = estimator_matheron - elif estimator_type == 'c': + else: # estimator_type == 'c' estimator_func = estimator_cressie return estimator_func @@ -164,7 +164,7 @@ cdef _normalization_func choose_estimator_normalization(str estimator_type): cdef _normalization_func normalization_func if estimator_type == 'm': normalization_func = normalization_matheron - elif estimator_type == 'c': + else: # estimator_type == 'c' normalization_func = normalization_cressie return normalization_func @@ -172,7 +172,7 @@ cdef _normalization_func_vec choose_estimator_normalization_vec(str estimator_ty cdef _normalization_func_vec normalization_func_vec if estimator_type == 'm': normalization_func_vec = normalization_matheron_vec - elif estimator_type == 'c': + else: # estimator_type == 'c' normalization_func_vec = normalization_cressie_vec return normalization_func_vec From 67de60e5d1cddbdfdfdde02b820853f6af71ebab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Tue, 21 Jun 2022 09:10:54 +0200 Subject: [PATCH 3/4] coverage: fix typo --- src/gstools/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gstools/__init__.py b/src/gstools/__init__.py index a82839cc..2d0e7232 100644 --- a/src/gstools/__init__.py +++ b/src/gstools/__init__.py @@ -180,7 +180,7 @@ try: from gstools._version import __version__ -except ModuleNotFoundError: # pragma: nocover +except ModuleNotFoundError: # pragma: no cover # package is not installed __version__ = "0.0.0.dev0" From 62a90fab28b9af6530d3c49db3c4092f935c67e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Mon, 20 Jun 2022 23:55:34 +0200 Subject: [PATCH 4/4] CovModel: add bounds check for optional arguments --- src/gstools/covmodel/base.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/gstools/covmodel/base.py b/src/gstools/covmodel/base.py index f87aee80..2dab3e7c 100644 --- a/src/gstools/covmodel/base.py +++ b/src/gstools/covmodel/base.py @@ -1138,6 +1138,13 @@ def __eq__(self, other): return False return compare(self, other) + def __setattr__(self, name, value): + """Set an attribute.""" + super().__setattr__(name, value) + # if an optional variogram argument was given, check bounds + if hasattr(self, "_opt_arg") and name in self._opt_arg: + self.check_arg_bounds() + def __repr__(self): """Return String representation.""" return model_repr(self)