-
-
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
Conversation
Thanks, this will be for 0.22 since it's an API change. Some people may have been ignoring the warning and relying on this. Did you look into how difficult it'd be to properly support multiple columns for |
I did think about this - the usecase that isn't already covered wasn't clear to me, especially given the complexity it would add to the method/API. The |
I don't have a strong opinion. I think the equivalent output would be The release not can go in |
Thanks, I see api changes section will update that |
Codecov Report
@@ Coverage Diff @@
## master #18695 +/- ##
==========================================
- Coverage 91.6% 91.59% -0.02%
==========================================
Files 153 153
Lines 51272 51276 +4
==========================================
- Hits 46967 46964 -3
- Misses 4305 4312 +7
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #18695 +/- ##
==========================================
- Coverage 91.6% 91.59% -0.02%
==========================================
Files 153 153
Lines 51272 51276 +4
==========================================
- Hits 46967 46964 -3
- Misses 4305 4312 +7
Continue to review full report at Codecov.
|
pandas/tests/plotting/test_frame.py
Outdated
@@ -2170,6 +2170,15 @@ def test_invalid_kind(self): | |||
with pytest.raises(ValueError): | |||
df.plot(kind='aasdf') | |||
|
|||
def test_invalid_xy_args(self): | |||
df = DataFrame({"A": [1, 2], 'B': [3, 4], 'C': [5, 6]}) |
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.
can yu add the issue number here
pandas/tests/plotting/test_frame.py
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
can you parameterize this on x, y
pandas/tests/plotting/test_frame.py
Outdated
df = DataFrame({"A": [1, 2], 'B': [3, 4], 'C': [5, 6]}) | ||
bad_arg = ['B', 'C'] | ||
valid_arg = 'A' | ||
with pytest.raises(ValueError): |
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.
can you also add a dataframe with duplicate columns as a test, e.g.
In [6]: df = DataFrame([[1, 3, 5], [2, 4, 6]], columns=list('AAB'))
In [7]: df
Out[7]:
A A B
0 1 3 5
1 2 4 6
In [8]: df['A']
Out[8]:
A A
0 1 3
1 2 4
doc/source/whatsnew/v0.22.0.txt
Outdated
@@ -188,6 +188,7 @@ Other API Changes | |||
- :func:`pandas.DataFrame.merge` no longer casts a ``float`` column to ``object`` when merging on ``int`` and ``float`` columns (:issue:`16572`) | |||
- The default NA value for :class:`UInt64Index` has changed from 0 to ``NaN``, which impacts methods that mask with NA, such as ``UInt64Index.where()`` (:issue:`18398`) | |||
- Refactored ``setup.py`` to use ``find_packages`` instead of explicitly listing out all subpackages (:issue:`18535`) | |||
- :func: `DataFrame.plot` now raises a ``ValueError`` when the ``x`` or ``y`` argument is improperly formed (:issue:`18671`) |
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.
pandas/plotting/_core.py
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
from pandas.core.dtypes.generic import ABCSeries, ABCDataFrame
not isinstance(data[x], ABCSeries)
and change the DataFrame
tests to use ABCDataFrame
(and remove the inline import)
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.
and change the DataFrame tests to use ABCDataFrame (and remove the inline import)
Not sure what you mean here? I changed the test to use ABCDataFrame
but that doesn't seem right?
thanks @masongallo nice patch! keep em coming! |
pandas/plotting/_core.py
Outdated
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 comment
The 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?
See #19699
…On Tue, Mar 20, 2018 at 1:29 PM, flutefreak7 ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In pandas/plotting/_core.py
<#18695 (comment)>:
> 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):
So if I do df.plot.line(x='x', y=['y1', 'y2', 'y3']) this is now a
ValueError?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#18695 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABQHIlLuQemvhx7IqH8azMnUaXdQQf1Qks5tgUqAgaJpZM4Q7XF0>
.
|
git diff upstream/master -u -- "*.py" | flake8 --diff
I'm not incredibly familiar with your codebase so I did my best to follow conventions. Not sure what to do with whatsnew for this case?
Description:
df.plot
to match specifications in documentation