File tree Expand file tree Collapse file tree 1 file changed +18
-10
lines changed
pandas/plotting/_matplotlib Expand file tree Collapse file tree 1 file changed +18
-10
lines changed Original file line number Diff line number Diff line change 1
1
from typing import (
2
2
TYPE_CHECKING ,
3
3
Collection ,
4
+ Iterator ,
4
5
List ,
5
6
Optional ,
6
7
Sequence ,
13
14
import matplotlib .colors
14
15
import numpy as np
15
16
16
- import pandas .core .common as com
17
17
from pandas .core .dtypes .common import is_list_like
18
18
19
+ import pandas .core .common as com
20
+
19
21
if TYPE_CHECKING :
20
22
from matplotlib .colors import Colormap
21
23
@@ -103,25 +105,30 @@ def _get_colors_from_color(
103
105
if len (color ) == 0 :
104
106
raise ValueError (f"Invalid color argument: { color } " )
105
107
106
- if isinstance (color , str ):
107
- if _is_single_color (color ):
108
- # GH #36972
109
- return [color ]
110
- else :
111
- return list (color )
108
+ if isinstance (color , str ) and _is_single_color (color ):
109
+ # GH #36972
110
+ return [color ]
112
111
113
112
if _is_floats_color (color ):
114
113
color = cast (Sequence [float ], color )
115
114
return [color ]
116
115
117
116
color = cast (Collection [Color ], color )
118
- colors = []
117
+ return list (_gen_list_of_colors_from_iterable (color ))
118
+
119
+
120
+ def _gen_list_of_colors_from_iterable (color : Collection [Color ]) -> Iterator [Color ]:
121
+ """
122
+ Yield colors from string of several letters or from collection of colors.
123
+ """
119
124
for x in color :
125
+ if isinstance (x , str ):
126
+ # to avoid warnings on upper case single letter colors
127
+ x = x .lower ()
120
128
if _is_single_color (x ):
121
- colors . append ( x )
129
+ yield x
122
130
else :
123
131
raise ValueError (f"Invalid color { x } " )
124
- return colors
125
132
126
133
127
134
def _is_floats_color (color : Union [Color , Collection [Color ]]) -> bool :
@@ -172,6 +179,7 @@ def _is_single_color(color: Color) -> bool:
172
179
- 'red'
173
180
- 'green'
174
181
- 'C3'
182
+ - 'firebrick'
175
183
176
184
Parameters
177
185
----------
You can’t perform that action at this time.
0 commit comments