Skip to content

Commit 45b937d

Browse files
authored
BUG: scatter discarding string columns (#56142)
* BUG: scatter discarding string columns * Add test
1 parent 6d1b07f commit 45b937d

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

doc/source/whatsnew/v2.2.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,8 @@ Period
546546
Plotting
547547
^^^^^^^^
548548
- Bug in :meth:`DataFrame.plot.box` with ``vert=False`` and a matplotlib ``Axes`` created with ``sharey=True`` (:issue:`54941`)
549+
- Bug in :meth:`DataFrame.plot.scatter` discaring string columns (:issue:`56142`)
549550
- Bug in :meth:`Series.plot` when reusing an ``ax`` object failing to raise when a ``how`` keyword is passed (:issue:`55953`)
550-
-
551551

552552
Groupby/resample/rolling
553553
^^^^^^^^^^^^^^^^^^^^^^^^

pandas/plotting/_matplotlib/core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ def _compute_plot_data(self):
688688

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

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

pandas/tests/plotting/frame/test_frame.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import numpy as np
1313
import pytest
1414

15+
import pandas.util._test_decorators as td
16+
1517
from pandas.core.dtypes.api import is_list_like
1618

1719
import pandas as pd
@@ -22,6 +24,7 @@
2224
Series,
2325
bdate_range,
2426
date_range,
27+
option_context,
2528
plotting,
2629
)
2730
import pandas._testing as tm
@@ -794,13 +797,17 @@ def test_scatterplot_datetime_data(self, x, y):
794797

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

800+
@pytest.mark.parametrize(
801+
"infer_string", [False, pytest.param(True, marks=td.skip_if_no("pyarrow"))]
802+
)
797803
@pytest.mark.parametrize("x, y", [("a", "b"), (0, 1)])
798804
@pytest.mark.parametrize("b_col", [[2, 3, 4], ["a", "b", "c"]])
799-
def test_scatterplot_object_data(self, b_col, x, y):
805+
def test_scatterplot_object_data(self, b_col, x, y, infer_string):
800806
# GH 18755
801-
df = DataFrame({"a": ["A", "B", "C"], "b": b_col})
807+
with option_context("future.infer_string", infer_string):
808+
df = DataFrame({"a": ["A", "B", "C"], "b": b_col})
802809

803-
_check_plot_works(df.plot.scatter, x=x, y=y)
810+
_check_plot_works(df.plot.scatter, x=x, y=y)
804811

805812
@pytest.mark.parametrize("ordered", [True, False])
806813
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)