diff --git a/CHANGELOG.md b/CHANGELOG.md index ad769aaf..0057b82f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ Changes relevant to the users of python-tcod are documented here. This project adheres to [Semantic Versioning](https://semver.org/) since version `2.0.0`. ## [Unreleased] +### Changed +- Renamed `gauss` methods to fix typos. ## [16.1.1] - 2023-07-10 ### Changed diff --git a/tcod/random.py b/tcod/random.py index b574cab8..c9e54286 100644 --- a/tcod/random.py +++ b/tcod/random.py @@ -14,6 +14,7 @@ from typing import Any, Hashable import tcod.constants +from tcod._internal import deprecate from tcod.cffi import ffi, lib MERSENNE_TWISTER = tcod.constants.RNG_MT @@ -110,7 +111,7 @@ def uniform(self, low: float, high: float) -> float: """ return float(lib.TCOD_random_get_double(self.random_c, low, high)) - def guass(self, mu: float, sigma: float) -> float: + def gauss(self, mu: float, sigma: float) -> float: """Return a random number using Gaussian distribution. Args: @@ -119,10 +120,17 @@ def guass(self, mu: float, sigma: float) -> float: Returns: float: A random float. + + .. versionchanged:: Unreleased + Renamed from `guass` to `gauss`. """ return float(lib.TCOD_random_get_gaussian_double(self.random_c, mu, sigma)) - def inverse_guass(self, mu: float, sigma: float) -> float: + @deprecate("This is a typo, rename this to 'gauss'", category=FutureWarning) + def guass(self, mu: float, sigma: float) -> float: # noqa: D102 + return self.gauss(mu, sigma) + + def inverse_gauss(self, mu: float, sigma: float) -> float: """Return a random Gaussian number using the Box-Muller transform. Args: @@ -131,9 +139,16 @@ def inverse_guass(self, mu: float, sigma: float) -> float: Returns: float: A random float. + + .. versionchanged:: Unreleased + Renamed from `inverse_guass` to `inverse_gauss`. """ return float(lib.TCOD_random_get_gaussian_double_inv(self.random_c, mu, sigma)) + @deprecate("This is a typo, rename this to 'inverse_gauss'", category=FutureWarning) + def inverse_guass(self, mu: float, sigma: float) -> float: # noqa: D102 + return self.inverse_gauss(mu, sigma) + def __getstate__(self) -> Any: """Pack the self.random_c attribute into a portable state.""" state = self.__dict__.copy() diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 502d9ea9..356de7d3 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -8,6 +8,7 @@ import tcod.constants import tcod.event import tcod.libtcodpy +import tcod.random with pytest.warns(): import libtcodpy @@ -53,3 +54,11 @@ def test_line_where() -> None: with pytest.warns(): where = tcod.libtcodpy.line_where(1, 0, 3, 4) np.testing.assert_array_equal(where, [[1, 1, 2, 2, 3], [0, 1, 2, 3, 4]]) + + +def test_gauss_typo() -> None: + rng = tcod.random.Random() + with pytest.warns(FutureWarning, match=r"gauss"): + rng.guass(1, 1) + with pytest.warns(FutureWarning, match=r"inverse_gauss"): + rng.inverse_guass(1, 1)