Skip to content

Commit eac6efe

Browse files
committed
Fix to_rgba when alpha is a numpy type
1 parent faceaa6 commit eac6efe

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

mizani/_colors/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from typing import TYPE_CHECKING, overload
44

5+
import numpy as np
6+
57
from mizani._colors.named_colors import get_named_color
68

79
if TYPE_CHECKING:
@@ -104,7 +106,7 @@ def to_rgba(
104106
if colors == "none" or colors == "None":
105107
return "none"
106108

107-
if isinstance(alpha, (float, int)):
109+
if isinstance(alpha, (float, int, np.floating, np.integer)):
108110
c = get_named_color(colors)
109111
if len(c) > 7:
110112
return c

tests/colors/test_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import numpy as np
12
import pandas as pd
23
import pytest
34

@@ -26,6 +27,8 @@ def test_to_rgba():
2627

2728
assert to_rgba((0, 0, 1, 0.2), 1) == (0, 0, 1, 0.2)
2829
assert to_rgba("none", 0.5) == "none"
30+
assert to_rgba("red", np.float64(0.5)) == "#FF000080"
31+
assert to_rgba("red", np.int64(1)) == "#FF0000FF" # pyright: ignore[reportCallIssue,reportArgumentType]
2932

3033
with pytest.raises(ValueError):
3134
to_rgba("red", "0") # pyright: ignore[reportCallIssue,reportArgumentType]

0 commit comments

Comments
 (0)