Skip to content

BUG: scatter discarding string columns #56142

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 2 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
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
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 @@ -541,8 +541,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"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to test this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a test


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