Skip to content

Commit 1c280cf

Browse files
committed
Merge pull request #10962 from sinhrks/plot_dupcolumns
BUG: DataFrame subplot with duplicated columns output incorrect result
2 parents 80cb9f4 + b28250f commit 1c280cf

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

doc/source/whatsnew/v0.17.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -927,3 +927,4 @@ Bug Fixes
927927
- Bug in ``groupby`` incorrect computation for aggregation on ``DataFrame`` with ``NaT`` (E.g ``first``, ``last``, ``min``). (:issue:`10590`)
928928
- Bug when constructing ``DataFrame`` where passing a dictionary with only scalar values and specifying columns did not raise an error (:issue:`10856`)
929929
- Bug in ``.var()`` causing roundoff errors for highly similar values (:issue:`10242`)
930+
- Bug in ``DataFrame.plot(subplots=True)`` with duplicated columns outputs incorrect result (:issue:`10962`)

pandas/tests/test_graphics.py

+22
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,28 @@ def test_subplots_sharex_axes_existing_axes(self):
16461646
for ax in axes.ravel():
16471647
self._check_visible(ax.get_yticklabels(), visible=True)
16481648

1649+
@slow
1650+
def test_subplots_dup_columns(self):
1651+
# GH 10962
1652+
df = DataFrame(np.random.rand(5, 5), columns=list('aaaaa'))
1653+
axes = df.plot(subplots=True)
1654+
for ax in axes:
1655+
self._check_legend_labels(ax, labels=['a'])
1656+
self.assertEqual(len(ax.lines), 1)
1657+
tm.close()
1658+
1659+
axes = df.plot(subplots=True, secondary_y='a')
1660+
for ax in axes:
1661+
# (right) is only attached when subplots=False
1662+
self._check_legend_labels(ax, labels=['a'])
1663+
self.assertEqual(len(ax.lines), 1)
1664+
tm.close()
1665+
1666+
ax = df.plot(secondary_y='a')
1667+
self._check_legend_labels(ax, labels=['a (right)'] * 5)
1668+
self.assertEqual(len(ax.lines), 0)
1669+
self.assertEqual(len(ax.right_ax.lines), 5)
1670+
16491671
def test_negative_log(self):
16501672
df = - DataFrame(rand(6, 4),
16511673
index=list(string.ascii_letters[:6]),

pandas/tools/plotting.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -920,11 +920,11 @@ def _iter_data(self, data=None, keep_index=False, fillna=None):
920920
else:
921921
columns = data.columns
922922

923-
for col in columns:
923+
for col, values in data.iteritems():
924924
if keep_index is True:
925-
yield col, data[col]
925+
yield col, values
926926
else:
927-
yield col, data[col].values
927+
yield col, values.values
928928

929929
@property
930930
def nseries(self):

0 commit comments

Comments
 (0)