Skip to content

Commit 180207c

Browse files
committed
fix: check if int series, return current otherwise
1 parent cf55e0c commit 180207c

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

pandas/plotting/_matplotlib/core.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -1805,14 +1805,9 @@ def _kind(self) -> Literal["bar", "barh"]:
18051805
def orientation(self) -> PlottingOrientation:
18061806
return "vertical"
18071807

1808-
# GH56460 checks similar to LinePlot's _is_ts_plot and _use_dynamic_x
1809-
@final
1810-
def _is_ts_plot(self, data) -> bool:
1811-
return self.use_index and use_dynamic_x(self._get_ax(0), data)
1812-
18131808
@final
18141809
def _set_tick_pos(self, data) -> np.ndarray:
1815-
if self._is_series and not self._is_ts_plot(data):
1810+
if self._is_series and is_integer_dtype(data.index):
18161811
return np.array(self._get_xticks(), dtype=int)
18171812
else:
18181813
return np.arange(len(data))

pandas/tests/plotting/test_series.py

+19-13
Original file line numberDiff line numberDiff line change
@@ -974,25 +974,31 @@ def test_series_none_color(self):
974974
expected = _unpack_cycler(mpl.pyplot.rcParams)[:1]
975975
_check_colors(ax.get_lines(), linecolors=expected)
976976

977-
@pytest.mark.parametrize(
978-
"plot_data",
979-
[
980-
(
981-
{
982-
"bars": {-1: 0.5, 0: 1.0, 1: 3.0, 2: 3.5, 3: 1.5},
983-
"pct": {-1: 1.0, 0: 2.0, 1: 3.0, 2: 4.0, 3: 8.0},
984-
}
985-
)
986-
],
987-
)
988-
def test_bar_plot_x_axis(self, plot_data):
989-
df = DataFrame(plot_data)
977+
def test_bar_plot_x_axis(self):
978+
df = DataFrame(
979+
{
980+
"bars": {-1: 0.5, 0: 1.0, 1: 3.0, 2: 3.5, 3: 1.5},
981+
"pct": {-1: 1.0, 0: 2.0, 1: 3.0, 2: 4.0, 3: 8.0},
982+
}
983+
)
990984
ax_bar = df["bars"].plot(kind="bar")
991985
df["pct"].plot(kind="line")
992986
actual_bar_x = [ax.get_x() + ax.get_width() / 2.0 for ax in ax_bar.patches]
993987
expected_x = [-1, 0, 1, 2, 3]
994988
assert actual_bar_x == expected_x
995989

990+
def test_non_numeric_bar_plt(self):
991+
df = DataFrame(
992+
{
993+
"bars": {"a": 0.5, "b": 1.0},
994+
"pct": {"a": 4.0, "b": 2.0},
995+
}
996+
)
997+
ax_bar = df["bars"].plot(kind="bar")
998+
actual_bar_x = [ax.get_x() + ax.get_width() / 2.0 for ax in ax_bar.patches]
999+
expected_x = [0, 1]
1000+
assert actual_bar_x == expected_x
1001+
9961002
@pytest.mark.slow
9971003
def test_plot_no_warning(self, ts):
9981004
# GH 55138

0 commit comments

Comments
 (0)