-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
API: Improper x/y arg given to df.plot #18695
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1680,7 +1680,7 @@ def _plot(data, x=None, y=None, subplots=False, | |
else: | ||
raise ValueError("%r is not a valid plot kind" % kind) | ||
|
||
from pandas import DataFrame | ||
from pandas import DataFrame, Series | ||
if kind in _dataframe_kinds: | ||
if isinstance(data, DataFrame): | ||
plot_obj = klass(data, x=x, y=y, subplots=subplots, ax=ax, | ||
|
@@ -1706,11 +1706,15 @@ def _plot(data, x=None, y=None, subplots=False, | |
if x is not None: | ||
if is_integer(x) and not data.columns.holds_integer(): | ||
x = data.columns[x] | ||
elif not isinstance(data[x], Series): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
and change the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Not sure what you mean here? I changed the test to use |
||
raise ValueError("x must be a label or position") | ||
data = data.set_index(x) | ||
|
||
if y is not None: | ||
if is_integer(y) and not data.columns.holds_integer(): | ||
y = data.columns[y] | ||
elif not isinstance(data[y], Series): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So if I do df.plot.line(x='x', y=['y1', 'y2', 'y3']) this is now a ValueError? |
||
raise ValueError("y must be a label or position") | ||
label = kwds['label'] if 'label' in kwds else y | ||
series = data[y].copy() # Don't modify | ||
series.name = label | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2170,6 +2170,15 @@ def test_invalid_kind(self): | |
with pytest.raises(ValueError): | ||
df.plot(kind='aasdf') | ||
|
||
def test_invalid_xy_args(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you parameterize this on x, y |
||
df = DataFrame({"A": [1, 2], 'B': [3, 4], 'C': [5, 6]}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can yu add the issue number here |
||
bad_arg = ['B', 'C'] | ||
valid_arg = 'A' | ||
with pytest.raises(ValueError): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you also add a dataframe with duplicate columns as a test, e.g.
|
||
df.plot(x=bad_arg, y=valid_arg) | ||
with pytest.raises(ValueError): | ||
df.plot(x=valid_arg, y=bad_arg) | ||
|
||
@pytest.mark.slow | ||
def test_hexbin_basic(self): | ||
df = self.hexbin_df | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can move this to plotting bugs.