Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/pykrige/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ def _adjust_for_anisotropy(X, center, scaling, angle):
float array [n_samples, n_dim], the X array adjusted for anisotropy.
"""

# Cast to float so integer input coordinates work: the in-place subtraction
# below would otherwise raise a UFuncTypeError under NumPy's "same_kind"
# casting rule when ``X`` is an integer array (see GH #300).
X = np.asarray(X, dtype=np.float64)
center = np.asarray(center)[None, :]
angle = np.asarray(angle) * np.pi / 180

Expand Down
18 changes: 18 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,24 @@ def test_core_adjust_for_anisotropy_3d():
assert_allclose(X_adj[:, 2], np.array([0.0, 0.0, 2.0]), **allclose_pars)


def test_core_adjust_for_anisotropy_integer_coords():
# Integer input coordinates must not raise a casting error (GH #300):
# the in-place subtraction inside _adjust_for_anisotropy used to fail
# under NumPy's "same_kind" rule when X had an integer dtype.
X_int = np.array([[1, 0, -1, 0], [0, 1, 0, -1]]).T
X_float = X_int.astype(np.float64)
X_adj_int = core._adjust_for_anisotropy(X_int, [0.0, 0.0], [2.0], [90.0])
X_adj_float = core._adjust_for_anisotropy(X_float, [0.0, 0.0], [2.0], [90.0])
assert_allclose(X_adj_int, X_adj_float, **allclose_pars)
# An integer OrdinaryKriging run with integer query points must work too.
x = np.array([10, 20, 30, 40, 50])
y = np.array([10, 25, 35, 45, 60])
z = np.array([1.1, 2.2, 0.5, 3.1, 1.7])
ok = OrdinaryKriging(x, y, z, variogram_model="linear")
values, _ = ok.execute("points", np.array([15, 25]), np.array([15, 25]))
assert np.all(np.isfinite(values))


def test_core_make_variogram_parameter_list():
# test of first case - variogram_model_parameters is None
# function should return None unaffected
Expand Down