Skip to content

Commit

Permalink
Fix various deprecation warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
KelSolaar committed Sep 29, 2024
1 parent 9a0d8b5 commit c15f8c3
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 37 deletions.
22 changes: 11 additions & 11 deletions colour/blindness/machado2009.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,17 @@ def matrix_RGB_to_WSYBRG(

R, G, B = tsplit(primaries.values)

WS_R = np.trapz(R * WS, wavelengths) # pyright: ignore
WS_G = np.trapz(G * WS, wavelengths) # pyright: ignore
WS_B = np.trapz(B * WS, wavelengths) # pyright: ignore
WS_R = np.trapezoid(R * WS, wavelengths) # pyright: ignore
WS_G = np.trapezoid(G * WS, wavelengths) # pyright: ignore
WS_B = np.trapezoid(B * WS, wavelengths) # pyright: ignore

YB_R = np.trapz(R * YB, wavelengths) # pyright: ignore
YB_G = np.trapz(G * YB, wavelengths) # pyright: ignore
YB_B = np.trapz(B * YB, wavelengths) # pyright: ignore
YB_R = np.trapezoid(R * YB, wavelengths) # pyright: ignore
YB_G = np.trapezoid(G * YB, wavelengths) # pyright: ignore
YB_B = np.trapezoid(B * YB, wavelengths) # pyright: ignore

RG_R = np.trapz(R * RG, wavelengths) # pyright: ignore
RG_G = np.trapz(G * RG, wavelengths) # pyright: ignore
RG_B = np.trapz(B * RG, wavelengths) # pyright: ignore
RG_R = np.trapezoid(R * RG, wavelengths) # pyright: ignore
RG_G = np.trapezoid(G * RG, wavelengths) # pyright: ignore
RG_B = np.trapezoid(B * RG, wavelengths) # pyright: ignore

M_G = as_float_array(
[
Expand Down Expand Up @@ -219,8 +219,8 @@ def msds_cmfs_anomalous_trichromacy_Machado2009(
"deuteranomaly simulation."
)

area_L = np.trapz(L, cmfs.wavelengths) # pyright: ignore
area_M = np.trapz(M, cmfs.wavelengths) # pyright: ignore
area_L = np.trapezoid(L, cmfs.wavelengths) # pyright: ignore
area_M = np.trapezoid(M, cmfs.wavelengths) # pyright: ignore

def alpha(x: NDArrayFloat) -> NDArrayFloat:
"""Compute :math:`alpha` factor."""
Expand Down
6 changes: 3 additions & 3 deletions colour/colorimetry/photometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def luminous_flux(
extrapolator_kwargs={"method": "Constant", "left": 0, "right": 0},
)

flux = K_m * np.trapz(lef.values * sd.values, sd.wavelengths) # pyright: ignore
flux = K_m * np.trapezoid(lef.values * sd.values, sd.wavelengths) # pyright: ignore

return as_float_scalar(flux)

Expand Down Expand Up @@ -130,9 +130,9 @@ def luminous_efficiency(
extrapolator_kwargs={"method": "Constant", "left": 0, "right": 0},
)

efficiency = np.trapz( # pyright: ignore
efficiency = np.trapezoid( # pyright: ignore
lef.values * sd.values, sd.wavelengths
) / np.trapz( # pyright: ignore
) / np.trapezoid( # pyright: ignore
sd.values, sd.wavelengths
)

Expand Down
2 changes: 1 addition & 1 deletion colour/colorimetry/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ def __contains__(self, wavelength: ArrayLike) -> bool:

return bool(
np.all(
np.in1d( # pyright: ignore
np.isin( # pyright: ignore
np.around(
wavelength, # pyright: ignore
decimals,
Expand Down
2 changes: 1 addition & 1 deletion colour/continuous/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ def __setitem__(self, x: ArrayLike | slice, y: ArrayLike):
y = np.resize(y, x.shape)

# Matching domain, updating existing `self._range` values.
mask = np.in1d(x, self._domain) # pyright: ignore
mask = np.isin(x, self._domain) # pyright: ignore
x_m = x[mask]
indexes = np.searchsorted(self._domain, x_m)
self._range[indexes] = y[mask]
Expand Down
2 changes: 1 addition & 1 deletion colour/notation/hexadecimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def HEX_to_RGB(HEX: ArrayLike) -> NDArrayFloat:
array([ 0.6666666..., 0.8666666..., 1. ])
"""

HEX = np.core.defchararray.lstrip(HEX, "#") # pyright: ignore
HEX = np.char.lstrip(HEX, "#") # pyright: ignore

def to_RGB(x: list) -> list:
"""Convert given hexadecimal representation to *RGB*."""
Expand Down
7 changes: 5 additions & 2 deletions colour/utilities/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class MixinDataclassArray(MixinDataclassIterable):
- :class:`colour.utilities.MixinDataclassFields`
"""

def __array__(self, dtype: Type[DTypeReal] | None = None) -> NDArray:
def __array__(self, dtype: Type[DTypeReal] | None = None, copy=None) -> NDArray:
"""
Implement support for :class:`dataclass`-like class conversion to
:class:`numpy.ndarray` class.
Expand All @@ -253,6 +253,9 @@ def __array__(self, dtype: Type[DTypeReal] | None = None) -> NDArray:
:class:`numpy.dtype` to use for conversion to `np.ndarray`, default
to the :class:`numpy.dtype` defined by
:attr:`colour.constant.DTYPE_FLOAT_DEFAULT` attribute.
copy
Whether to return a copy of the underlying data, will always be
`True`, irrespective of the parameter value.
Returns
-------
Expand Down Expand Up @@ -2090,7 +2093,7 @@ def in_array(a: ArrayLike, b: ArrayLike, tolerance: Real = EPSILON) -> NDArray:
--------
>>> a = np.array([0.50, 0.60])
>>> b = np.linspace(0, 10, 101)
>>> np.in1d(a, b)
>>> np.isin(a, b)
array([ True, False], dtype=bool)
>>> in_array(a, b)
array([ True, True], dtype=bool)
Expand Down
36 changes: 18 additions & 18 deletions colour/utilities/tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def test__array__(self):
method.
"""

np.testing.assert_array_equal(np.array(self._data), self._array)
np.testing.assert_array_equal(self._data, self._array)

assert np.array(self._data, dtype=DTYPE_INT_DEFAULT).dtype == DTYPE_INT_DEFAULT

Expand Down Expand Up @@ -344,107 +344,107 @@ def test_arithmetical_operation(self):
"""

np.testing.assert_allclose(
np.array(self._data.arithmetical_operation(10, "+", False)),
self._data.arithmetical_operation(10, "+", False),
self._array + 10,
atol=TOLERANCE_ABSOLUTE_TESTS,
)

np.testing.assert_allclose(
np.array(self._data.arithmetical_operation(10, "-", False)),
self._data.arithmetical_operation(10, "-", False),
self._array - 10,
atol=TOLERANCE_ABSOLUTE_TESTS,
)

np.testing.assert_allclose(
np.array(self._data.arithmetical_operation(10, "*", False)),
self._data.arithmetical_operation(10, "*", False),
self._array * 10,
atol=TOLERANCE_ABSOLUTE_TESTS,
)

np.testing.assert_allclose(
np.array(self._data.arithmetical_operation(10, "/", False)),
self._data.arithmetical_operation(10, "/", False),
self._array / 10,
atol=TOLERANCE_ABSOLUTE_TESTS,
)

np.testing.assert_allclose(
np.array(self._data.arithmetical_operation(10, "**", False)),
self._data.arithmetical_operation(10, "**", False),
self._array**10,
atol=TOLERANCE_ABSOLUTE_TESTS,
)

np.testing.assert_allclose(
np.array(self._data + 10),
self._data + 10,
self._array + 10,
atol=TOLERANCE_ABSOLUTE_TESTS,
)

np.testing.assert_allclose(
np.array(self._data - 10),
self._data - 10,
self._array - 10,
atol=TOLERANCE_ABSOLUTE_TESTS,
)

np.testing.assert_allclose(
np.array(self._data * 10),
self._data * 10,
self._array * 10,
atol=TOLERANCE_ABSOLUTE_TESTS,
)

np.testing.assert_allclose(
np.array(self._data / 10),
self._data / 10,
self._array / 10,
atol=TOLERANCE_ABSOLUTE_TESTS,
)

np.testing.assert_allclose(
np.array(self._data**10),
self._data**10,
self._array**10,
atol=TOLERANCE_ABSOLUTE_TESTS,
)

data = deepcopy(self._data)

np.testing.assert_allclose(
np.array(data.arithmetical_operation(10, "+", True)),
data.arithmetical_operation(10, "+", True),
self._array + 10,
atol=TOLERANCE_ABSOLUTE_TESTS,
)

np.testing.assert_allclose(
np.array(data.arithmetical_operation(10, "-", True)),
data.arithmetical_operation(10, "-", True),
self._array,
atol=TOLERANCE_ABSOLUTE_TESTS,
)

np.testing.assert_allclose(
np.array(data.arithmetical_operation(10, "*", True)),
data.arithmetical_operation(10, "*", True),
self._array * 10,
atol=TOLERANCE_ABSOLUTE_TESTS,
)

np.testing.assert_allclose(
np.array(data.arithmetical_operation(10, "/", True)),
data.arithmetical_operation(10, "/", True),
self._array,
atol=TOLERANCE_ABSOLUTE_TESTS,
)

np.testing.assert_allclose(
np.array(data.arithmetical_operation(10, "**", True)),
data.arithmetical_operation(10, "**", True),
self._array**10,
atol=TOLERANCE_ABSOLUTE_TESTS,
)

data = deepcopy(self._data)

np.testing.assert_allclose(
np.array(data.arithmetical_operation(self._array, "+", False)),
data.arithmetical_operation(self._array, "+", False),
data + self._array,
atol=TOLERANCE_ABSOLUTE_TESTS,
)

np.testing.assert_allclose(
np.array(data.arithmetical_operation(data, "+", False)),
data.arithmetical_operation(data, "+", False),
data + data,
atol=TOLERANCE_ABSOLUTE_TESTS,
)
Expand Down

0 comments on commit c15f8c3

Please sign in to comment.