Skip to content

Commit f79e89a

Browse files
committed
Fix to_rgba to recognise None
1 parent eac6efe commit f79e89a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

mizani/_colors/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def color_tuple_to_hex(t: RGBColor | RGBAColor) -> str:
6161

6262

6363
@overload
64-
def to_rgba(colors: ColorType, alpha: float) -> ColorType: ...
64+
def to_rgba(colors: ColorType | None, alpha: float) -> ColorType: ...
6565

6666

6767
@overload
@@ -83,7 +83,7 @@ def to_rgba(
8383

8484

8585
def to_rgba(
86-
colors: Sequence[ColorType] | AnySeries | ColorType,
86+
colors: Sequence[ColorType] | AnySeries | ColorType | None,
8787
alpha: float | Sequence[float] | AnySeries,
8888
) -> Sequence[ColorType] | ColorType:
8989
"""
@@ -121,6 +121,8 @@ def to_rgba(
121121
return (*colors, alpha) # pyright: ignore[reportReturnType]
122122
else:
123123
return colors
124+
elif colors is None:
125+
return "none"
124126

125127
if isinstance(alpha, (float, int)):
126128
return [to_rgba(c, alpha) for c in colors] # pyright: ignore[reportCallIssue,reportArgumentType]

tests/colors/test_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ def test_to_rgba():
3030
assert to_rgba("red", np.float64(0.5)) == "#FF000080"
3131
assert to_rgba("red", np.int64(1)) == "#FF0000FF" # pyright: ignore[reportCallIssue,reportArgumentType]
3232

33+
assert to_rgba(None, 1) == "none"
34+
assert to_rgba([None, None], 1) == ["none", "none"] # pyright: ignore[reportCallIssue,reportArgumentType]
35+
3336
with pytest.raises(ValueError):
3437
to_rgba("red", "0") # pyright: ignore[reportCallIssue,reportArgumentType]
3538

0 commit comments

Comments
 (0)