Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cmap/_colormap.py
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ def reversed(self) -> ColorStops:
rev_lutfunc = partial(self._reverser, lut_func)
return type(self)(lut_func=rev_lutfunc)
# invert the positions in the stops
rev_stops = self._stops[::-1]
rev_stops = self._stops[::-1].copy()
rev_stops[:, 0] = 1 - rev_stops[:, 0]
return type(self)(rev_stops, interpolation=self._interpolation)

Expand Down
9 changes: 9 additions & 0 deletions tests/test_colormap.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ def test_colorstops() -> None:
assert reversed(cmap.color_stops) == ColorStops.parse(["b", "m", "r"])


def test_colorstops_reversed_does_not_mutate_source() -> None:
stops = ColorStops.parse(["red", "green", "blue"])
before = np.asarray(stops).copy()

stops.reversed()

npt.assert_array_equal(np.asarray(stops), before)


def test_colormap_copy() -> None:
"""Test Colormap copy."""
import pickle
Expand Down
Loading