Skip to content

Commit

Permalink
BUG: scatter discarding string columns (#56142)
Browse files Browse the repository at this point in the history
* BUG: scatter discarding string columns

* Add test
  • Loading branch information
phofl authored Nov 26, 2023
1 parent 6d1b07f commit 45b937d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v2.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,8 @@ Period
Plotting
^^^^^^^^
- Bug in :meth:`DataFrame.plot.box` with ``vert=False`` and a matplotlib ``Axes`` created with ``sharey=True`` (:issue:`54941`)
- Bug in :meth:`DataFrame.plot.scatter` discaring string columns (:issue:`56142`)
- Bug in :meth:`Series.plot` when reusing an ``ax`` object failing to raise when a ``how`` keyword is passed (:issue:`55953`)
-

Groupby/resample/rolling
^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion pandas/plotting/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ def _compute_plot_data(self):

# GH 18755, include object and category type for scatter plot
if self._kind == "scatter":
include_type.extend(["object", "category"])
include_type.extend(["object", "category", "string"])

numeric_data = data.select_dtypes(include=include_type, exclude=exclude_type)

Expand Down
13 changes: 10 additions & 3 deletions pandas/tests/plotting/frame/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import numpy as np
import pytest

import pandas.util._test_decorators as td

from pandas.core.dtypes.api import is_list_like

import pandas as pd
Expand All @@ -22,6 +24,7 @@
Series,
bdate_range,
date_range,
option_context,
plotting,
)
import pandas._testing as tm
Expand Down Expand Up @@ -794,13 +797,17 @@ def test_scatterplot_datetime_data(self, x, y):

_check_plot_works(df.plot.scatter, x=x, y=y)

@pytest.mark.parametrize(
"infer_string", [False, pytest.param(True, marks=td.skip_if_no("pyarrow"))]
)
@pytest.mark.parametrize("x, y", [("a", "b"), (0, 1)])
@pytest.mark.parametrize("b_col", [[2, 3, 4], ["a", "b", "c"]])
def test_scatterplot_object_data(self, b_col, x, y):
def test_scatterplot_object_data(self, b_col, x, y, infer_string):
# GH 18755
df = DataFrame({"a": ["A", "B", "C"], "b": b_col})
with option_context("future.infer_string", infer_string):
df = DataFrame({"a": ["A", "B", "C"], "b": b_col})

_check_plot_works(df.plot.scatter, x=x, y=y)
_check_plot_works(df.plot.scatter, x=x, y=y)

@pytest.mark.parametrize("ordered", [True, False])
@pytest.mark.parametrize(
Expand Down

0 comments on commit 45b937d

Please sign in to comment.