Skip to content

Commit 6d05e19

Browse files
authored
Fixed warning due to deprecated np.asscalar() (#3)
* Fixed warning due to deprecated `np.asscalar()` Numpy function * Fixed mypy errors
1 parent 80489c5 commit 6d05e19

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

pnoise/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def _get_version() -> str:
55
try:
66
from importlib.metadata import version
77
except ModuleNotFoundError:
8-
from importlib_metadata import version
8+
from importlib_metadata import version # type: ignore
99

1010
return version(__name__)
1111

pnoise/pnoise.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""pnoise library"""
22
"""
33
Ported from the Processing project - http://processing.org
4-
Copyright (c) 2021 Antoine Beyeler
4+
Copyright (c) 2021-2022 Antoine Beyeler
55
Copyright (c) 2012-15 The Processing Foundation
66
Copyright (c) 2004-12 Ben Fry and Casey Reas
77
Copyright (c) 2001-04 Massachusetts Institute of Technology
@@ -51,7 +51,7 @@ def perlin(
5151
y: Union[Number, Sequence[Number]],
5252
z: Union[Number, Sequence[Number]],
5353
grid_mode: bool = True,
54-
) -> np.ndarray:
54+
) -> Union[np.ndarray, float]:
5555
"""Compute perlin noise for a range of values.
5656
5757
Each of the x, y, and z argument may be 1D sequence of float. Perlin noise will be
@@ -65,7 +65,10 @@ def perlin(
6565
if not grid_mode or single:
6666
grid = np.array([x, y, z], dtype=float)
6767
else:
68-
grid = np.array(np.meshgrid(x, y, z, indexing="ij", copy=False), dtype=float)
68+
grid = np.array(
69+
np.meshgrid(np.array(x), np.array(y), np.array(z), indexing="ij", copy=False),
70+
dtype=float,
71+
)
6972

7073
np.abs(grid, out=grid)
7174
grid_i = grid.astype(int)
@@ -109,7 +112,7 @@ def perlin(
109112
grid[idx] -= 1.0
110113

111114
if single:
112-
return np.asscalar(r)
115+
return float(r.item())
113116
elif not grid_mode:
114117
return r
115118
else:

0 commit comments

Comments
 (0)