Skip to content

BUG: Allow plotting boolean values #27665

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

Merged
merged 17 commits into from
Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 2 additions & 2 deletions pandas/plotting/_matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
register(explicit=False)


def plot(data, kind, **kwargs):
def plot(data, kind, include_bool=False, **kwargs):
# Importing pyplot at the top of the file (before the converters are
# registered) causes problems in matplotlib 2 (converters seem to not
# work)
Expand All @@ -59,7 +59,7 @@ def plot(data, kind, **kwargs):
ax = plt.gca()
kwargs["ax"] = getattr(ax, "left_ax", ax)
plot_obj = PLOT_CLASSES[kind](data, **kwargs)
plot_obj.generate()
plot_obj.generate(include_bool=include_bool)
plot_obj.draw()
return plot_obj.result

Expand Down
11 changes: 7 additions & 4 deletions pandas/plotting/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ def nseries(self):
def draw(self):
self.plt.draw_if_interactive()

def generate(self):
def generate(self, include_bool=False):
self._args_adjust()
self._compute_plot_data()
self._compute_plot_data(include_bool=include_bool)
self._setup_subplots()
self._make_plot()
self._add_table()
Expand Down Expand Up @@ -388,7 +388,7 @@ def result(self):
else:
return self.axes[0]

def _compute_plot_data(self):
def _compute_plot_data(self, include_bool=False):
data = self.data

if isinstance(data, ABCSeries):
Expand All @@ -400,8 +400,11 @@ def _compute_plot_data(self):
# GH16953, _convert is needed as fallback, for ``Series``
# with ``dtype == object``
data = data._convert(datetime=True, timedelta=True)
select_include_type = [np.number, "datetime", "datetimetz", "timedelta"]
if include_bool is True:
select_include_type.append(np.bool_)
numeric_data = data.select_dtypes(
include=[np.number, "datetime", "datetimetz", "timedelta"]
include=select_include_type
)

try:
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