Skip to content

Commit f93a1cb

Browse files
committed
Fix gauss function typos
1 parent 9c29b1a commit f93a1cb

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Changes relevant to the users of python-tcod are documented here.
44
This project adheres to [Semantic Versioning](https://semver.org/) since version `2.0.0`.
55

66
## [Unreleased]
7+
### Changed
8+
- Renamed `gauss` methods to fix typos.
79

810
## [16.1.1] - 2023-07-10
911
### Changed

tcod/random.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from typing import Any, Hashable
1515

1616
import tcod.constants
17+
from tcod._internal import deprecate
1718
from tcod.cffi import ffi, lib
1819

1920
MERSENNE_TWISTER = tcod.constants.RNG_MT
@@ -110,7 +111,7 @@ def uniform(self, low: float, high: float) -> float:
110111
"""
111112
return float(lib.TCOD_random_get_double(self.random_c, low, high))
112113

113-
def guass(self, mu: float, sigma: float) -> float:
114+
def gauss(self, mu: float, sigma: float) -> float:
114115
"""Return a random number using Gaussian distribution.
115116
116117
Args:
@@ -119,10 +120,17 @@ def guass(self, mu: float, sigma: float) -> float:
119120
120121
Returns:
121122
float: A random float.
123+
124+
.. versionchanged:: Unreleased
125+
Renamed from `guass` to `gauss`.
122126
"""
123127
return float(lib.TCOD_random_get_gaussian_double(self.random_c, mu, sigma))
124128

125-
def inverse_guass(self, mu: float, sigma: float) -> float:
129+
@deprecate("This is a typo, rename this to 'gauss'", category=FutureWarning)
130+
def guass(self, mu: float, sigma: float) -> float: # noqa: D102
131+
return self.gauss(mu, sigma)
132+
133+
def inverse_gauss(self, mu: float, sigma: float) -> float:
126134
"""Return a random Gaussian number using the Box-Muller transform.
127135
128136
Args:
@@ -131,9 +139,16 @@ def inverse_guass(self, mu: float, sigma: float) -> float:
131139
132140
Returns:
133141
float: A random float.
142+
143+
.. versionchanged:: Unreleased
144+
Renamed from `inverse_guass` to `inverse_gauss`.
134145
"""
135146
return float(lib.TCOD_random_get_gaussian_double_inv(self.random_c, mu, sigma))
136147

148+
@deprecate("This is a typo, rename this to 'inverse_gauss'", category=FutureWarning)
149+
def inverse_guass(self, mu: float, sigma: float) -> float: # noqa: D102
150+
return self.inverse_gauss(mu, sigma)
151+
137152
def __getstate__(self) -> Any:
138153
"""Pack the self.random_c attribute into a portable state."""
139154
state = self.__dict__.copy()

tests/test_deprecated.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import tcod.constants
99
import tcod.event
1010
import tcod.libtcodpy
11+
import tcod.random
1112

1213
with pytest.warns():
1314
import libtcodpy
@@ -53,3 +54,11 @@ def test_line_where() -> None:
5354
with pytest.warns():
5455
where = tcod.libtcodpy.line_where(1, 0, 3, 4)
5556
np.testing.assert_array_equal(where, [[1, 1, 2, 2, 3], [0, 1, 2, 3, 4]])
57+
58+
59+
def test_gauss_typo() -> None:
60+
rng = tcod.random.Random()
61+
with pytest.warns(FutureWarning, match=r"gauss"):
62+
rng.guass(1, 1)
63+
with pytest.warns(FutureWarning, match=r"inverse_gauss"):
64+
rng.inverse_guass(1, 1)

0 commit comments

Comments
 (0)