diff --git a/pandas/plotting/_matplotlib/style.py b/pandas/plotting/_matplotlib/style.py index 962f9711d9916..09c1d2adcf45b 100644 --- a/pandas/plotting/_matplotlib/style.py +++ b/pandas/plotting/_matplotlib/style.py @@ -199,10 +199,10 @@ def _get_colors_from_color( raise ValueError(f"Invalid color argument: {color}") if _is_single_color(color): - color = cast(Color, color) + color = cast("Color", color) return [color] - color = cast(Collection[Color], color) + color = cast("Collection[Color]", color) return list(_gen_list_of_colors_from_iterable(color)) @@ -241,11 +241,14 @@ def _gen_list_of_colors_from_iterable(color: Collection[Color]) -> Iterator[Colo def _is_floats_color(color: Color | Collection[Color]) -> bool: """Check if color comprises a sequence of floats representing color.""" - return bool( - is_list_like(color) - and (len(color) == 3 or len(color) == 4) - and all(isinstance(x, (int, float)) for x in color) - ) + if not is_list_like(color): + return False + if len(color) != 3 and len(color) != 4: + return False + for x in color: + if not isinstance(x, (int, float)): + return False + return True def _get_colors_from_color_type(color_type: str, num_colors: int) -> list[Color]: