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
3 changes: 1 addition & 2 deletions src/cmap/_colormap.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,7 @@ def __call__(
xa = np.array(x, copy=True)
if not xa.dtype.isnative:
# Native byteorder is faster.
native: Literal[">", "<"] = ">" if xa.dtype.byteorder in ("<", "=") else "<"
xa = xa.view(xa.dtype.newbyteorder(native))
xa = xa.byteswap().view(xa.dtype.newbyteorder())
if xa.dtype.kind == "f":
xa *= N
# xa == 1 (== N after multiplication) is not out of range.
Expand Down
8 changes: 8 additions & 0 deletions tests/test_colormap.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ def test_colormap_apply() -> None:
assert cmap1(swapped).shape == (10, 10, 4)


def test_non_native_byte_order_maps_the_same_colors() -> None:
cmap = Colormap(["red", "blue"], under="green", over="yellow", bad="black")
native = np.array([-0.5, 0.0, 0.5, 1.0, 1.5, np.nan])
non_native = native.astype(native.dtype.newbyteorder())

npt.assert_array_equal(cmap(non_native), cmap(native))


def test_colormap_masked_array_with_unmasked_nan() -> None:
cmap = Colormap("viridis", bad="red")
mask = [True, False, False, False]
Expand Down
Loading