Skip to content

Commit

Permalink
Enable PERF checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
KelSolaar committed Dec 22, 2024
1 parent 357800e commit bfafc38
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 37 deletions.
6 changes: 3 additions & 3 deletions colour/algebra/tests/test_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ def test_nan__call__(self) -> None:
try:
linear_interpolator = LinearInterpolator(case, case)
linear_interpolator(case[0])
except ValueError:
except ValueError: # noqa: PERF203
pass


Expand Down Expand Up @@ -1377,7 +1377,7 @@ def test_nan__call__(self) -> None:
try:
sprague_interpolator = SpragueInterpolator(case, case)
sprague_interpolator(case[0]) # pragma: no cover
except AssertionError:
except AssertionError: # noqa: PERF203
pass


Expand Down Expand Up @@ -1574,7 +1574,7 @@ def test_nan__call__(self) -> None:
try:
null_interpolator = NullInterpolator(case, case)
null_interpolator(case[0])
except ValueError:
except ValueError: # noqa: PERF203
pass


Expand Down
2 changes: 1 addition & 1 deletion colour/geometry/vertices.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def primitive_vertices_grid_mpl(
quads = []
for i in range(width_segments):
for j in range(height_segments):
quads.append(
quads.append( # noqa: PERF401
primitive_vertices_quad_mpl(
w_x, h_y, depth, (i * w_x + u, j * h_y + v), axis
)
Expand Down
11 changes: 5 additions & 6 deletions colour/io/fichet2021.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,12 @@ def from_spectral_image(path: str | Path) -> Specification_Fichet2021:
wavelength = match_groups_to_nm(match.group(1), multiplier, units)
components["T"][wavelength] = i

attributes = []
for attribute in image_specification.extra_attribs:
attributes.append(
Image_Specification_Attribute(
attribute.name, attribute.value, attribute.type
)
attributes = [
Image_Specification_Attribute(
attribute.name, attribute.value, attribute.type
)
for attribute in image_specification.extra_attribs
]

return Specification_Fichet2021(
path,
Expand Down
14 changes: 7 additions & 7 deletions colour/io/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def read_image_OpenImageIO(
] = "float32",
additional_data: bool = False,
**kwargs: Any,
) -> NDArrayReal | Tuple[NDArrayReal, Tuple[Image_Specification_Attribute]]:
) -> NDArrayReal | Tuple[NDArrayReal, Tuple[Image_Specification_Attribute, ...]]:
"""
Read the image data at given path using *OpenImageIO*.
Expand Down Expand Up @@ -410,15 +410,15 @@ def read_image_OpenImageIO(
image = cast(NDArrayReal, np.squeeze(image))

if additional_data:
extra_attributes = []
for attribute in image_specification.extra_attribs:
extra_attributes.append(
Image_Specification_Attribute(
attribute.name, attribute.value, attribute.type
)
extra_attributes = [
Image_Specification_Attribute(
attribute.name, attribute.value, attribute.type
)
for attribute in image_specification.extra_attribs
]

return image, tuple(extra_attributes)

return image


Expand Down
2 changes: 1 addition & 1 deletion colour/io/uprtek_sekonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def as_array(a: Any) -> list:
self._metadata[attribute] = method(
value # pyright: ignore
)
except (TypeError, ValueError):
except (TypeError, ValueError): # noqa: PERF203
self._metadata[attribute] = value
else:
break
Expand Down
2 changes: 1 addition & 1 deletion colour/models/tests/test_cam02_ucs.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,5 +557,5 @@ def test_nan_UCS_Luo2006_to_XYZ(self) -> None:
for case in cases:
try:
UCS_Luo2006_to_XYZ(case, COEFFICIENTS_UCS_LUO2006["CAM02-LCD"])
except ValueError as error:
except ValueError as error: # noqa: PERF203
attest("CAM_Specification_CIECAM02" in str(error))
11 changes: 5 additions & 6 deletions colour/quality/cfi2017.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,23 +503,22 @@ def tcs_colorimetry_data(
]
)
Jpapbp = JMh_CIECAM02_to_CAM02UCS(JMh)
tcs_data = []

specification = as_float_array(specification).transpose((0, 2, 1))
specification = [CAM_Specification_CIECAM02(*t) for t in specification]

for sd_idx in range(len(sd_irradiance)):
tcs_data.append(
return tuple(
[
DataColorimetry_TCS_CIE2017(
sds_tcs.display_labels,
XYZ[sd_idx],
specification[sd_idx],
JMh[sd_idx],
Jpapbp[sd_idx],
)
)

return tuple(tcs_data)
for sd_idx in range(len(sd_irradiance))
]
)


def delta_E_to_R_f(delta_E: ArrayLike) -> NDArrayFloat:
Expand Down
2 changes: 1 addition & 1 deletion colour/recovery/tests/test_otsu2018.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def test_XYZ_to_sd_Otsu2018(self) -> None:
"""Test :func:`colour.recovery.otsu2018.XYZ_to_sd_Otsu2018` definition."""

# Tests the round-trip with values of a colour checker.
for _name, sd in SDS_COLOURCHECKERS["ColorChecker N Ohta"].items():
for sd in SDS_COLOURCHECKERS["ColorChecker N Ohta"].values():
XYZ = sd_to_XYZ(sd, self._cmfs, self._sd_D65) / 100
Lab = XYZ_to_Lab(XYZ, self._xy_D65)

Expand Down
4 changes: 2 additions & 2 deletions colour/utilities/verbose.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ def _get_package_version(package: str, mapping: Mapping) -> str:
package = mapping.get(package, package) # noqa: PLW2901

environment["Development"][package] = version
except Exception: # pragma: no cover # noqa: BLE001, S112
except Exception: # pragma: no cover # noqa: BLE001, PERF203, S112
continue

environment["Development"].update(ANCILLARY_DEVELOPMENT_PACKAGES)
Expand All @@ -902,7 +902,7 @@ def _get_package_version(package: str, mapping: Mapping) -> str:
package = mapping.get(package, package) # noqa: PLW2901

environment["Extras"][package] = version
except Exception: # pragma: no cover # noqa: BLE001, S112
except Exception: # pragma: no cover # noqa: BLE001, PERF203, S112
continue

environment["Extras"].update(ANCILLARY_EXTRAS_PACKAGES)
Expand Down
14 changes: 6 additions & 8 deletions colour/volume/rgb.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,17 @@ def RGB_colourspace_limits(colourspace: RGB_Colourspace) -> NDArrayFloat:
[-107.8503557..., 94.4894974...]])
"""

Lab_c = []
for combination in list(itertools.product([0, 1], repeat=3)):
Lab_c.append(
Lab = np.array(
[
XYZ_to_Lab(
RGB_to_XYZ(combination, colourspace),
colourspace.whitepoint,
)
)
Lab = np.array(Lab_c)
for combination in list(itertools.product([0, 1], repeat=3))
]
)

limits = []
for i in np.arange(3):
limits.append((np.min(Lab[..., i]), np.max(Lab[..., i])))
limits = [(np.min(Lab[..., i]), np.max(Lab[..., i])) for i in np.arange(3)]

return np.array(limits)

Expand Down
2 changes: 1 addition & 1 deletion colour/volume/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def generate_pulse_waves(
if pulse_order.lower() == "bins":
for square_wave_basis in square_waves_basis:
for i in range(bins):
square_waves.append(np.roll(square_wave_basis, i))
square_waves.append(np.roll(square_wave_basis, i)) # noqa: PERF401
else:
for i in range(bins):
for j, square_wave_basis in enumerate(square_waves_basis):
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ select = [
"N", # pep8-naming
"NPY", # Numpy
"PD", # pandas-vet
"PERF", # Perflint
"PIE", # flake8-pie
"PGH", # pygrep-hooks
"PL", # pylint
Expand Down

0 comments on commit bfafc38

Please sign in to comment.