Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update boxplot.py #60783

Open
wants to merge 4 commits into
base: 2.3.x
Choose a base branch
from
Open
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
17 changes: 10 additions & 7 deletions pandas/plotting/_matplotlib/boxplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
TYPE_CHECKING,
Literal,
NamedTuple,
Optional,
Union,
)
import warnings

Expand Down Expand Up @@ -98,7 +100,8 @@ def __init__(self, data, return_type: str = "axes", **kwargs) -> None:
# error: Signature of "_plot" incompatible with supertype "MPLPlot"
@classmethod
def _plot( # type: ignore[override]
cls, ax: Axes, y: np.ndarray, column_num=None, return_type: str = "axes", **kwds
cls, ax: Axes, y: np.ndarray, column_num: Optional[int] = None, return_type: str = "axes", **kwds

):
ys: np.ndarray | list[np.ndarray]
if y.ndim == 2:
Expand All @@ -107,6 +110,9 @@ def _plot( # type: ignore[override]
# if any cols are empty
# GH 8181
ys = [v if v.size > 0 else np.array([np.nan]) for v in ys]
for v in ys:
if v.size == 0:
warnings.warn("Empty array detected, replacing with NaN", stacklevel=find_stack_level())
else:
ys = remove_na_arraylike(y)
bp = ax.boxplot(ys, **kwds)
Expand Down Expand Up @@ -166,10 +172,8 @@ def _caps_c(self):
def _get_colors(
self,
num_colors=None,
color_kwds: dict[str, MatplotlibColor]
| MatplotlibColor
| Collection[MatplotlibColor]
| None = "color",
color_kwds: Optional[Union[dict[str, MatplotlibColor],
MatplotlibColor, Collection[MatplotlibColor]]] = "color",
) -> None:
pass

Expand Down Expand Up @@ -391,8 +395,7 @@ def _get_colors():
result[key_to_index[key]] = value
else:
raise ValueError(
f"color dict contains invalid key '{key}'. "
f"The key must be either {valid_keys}"
f"color dict contains invalid key '{key}'. The key must be either {valid_keys}"
)
else:
result.fill(colors)
Expand Down
Loading