Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
11 changes: 8 additions & 3 deletions pandas/plotting/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def __init__(
colormap=None,
table=False,
layout=None,
include_bool=False,
**kwds
):

Expand Down Expand Up @@ -191,6 +192,7 @@ def __init__(
self.colormap = colormap

self.table = table
self.include_bool = include_bool

self.kwds = kwds

Expand Down Expand Up @@ -400,9 +402,12 @@ def _compute_plot_data(self):
# GH16953, _convert is needed as fallback, for ``Series``
# with ``dtype == object``
data = data._convert(datetime=True, timedelta=True)
numeric_data = data.select_dtypes(
include=[np.number, "datetime", "datetimetz", "timedelta"]
)
select_include_type = [np.number, "datetime", "datetimetz", "timedelta"]

# GH23719, allow plotting boolean
if self.include_bool is True:
select_include_type.append(np.bool_)
numeric_data = data.select_dtypes(include=select_include_type)

try:
is_empty = numeric_data.empty
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/plotting/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ def test_label(self):
ax.legend() # draw it
self._check_legend_labels(ax, labels=["LABEL"])

def test_boolean(self):
# GH 23719
s = Series([False, False, True])
_check_plot_works(s.plot, include_bool=True)

msg = "no numeric data to plot"
with pytest.raises(TypeError, match=msg):
_check_plot_works(s.plot)

def test_line_area_nan_series(self):
values = [1, 2, np.nan, 3]
s = Series(values)
Expand Down