-
-
Notifications
You must be signed in to change notification settings - Fork 18.9k
apply_frame_axis0 applies function to first group twice #21943
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
removing PATH_MODE debugging flag
remove whitespaces
…s not exclude x-axis label and tick-labels
remove whitespace
changing for PEP8
changing for PEP8
fixing lint E231
… x,y (pandas-dev#20000) * Add support for list-like y argument * update whatsnew * add doc change for y * Add test cases and fix position args * don't copy save cols ahead of time and update whatsnew * address fdbck
* DOC: Improve the docstring of DataFrame.transpose() Co-authored-by: Carlos Eduardo Moreira dos Santos <cems@cemshost.com.br>
* REF: Mock all S3 Tests Closes pandas-dev#19825
* TST: Fixed version comparison This failed to skip for 3.5.x because the micro component made it False. * Use pandas.compat * More pandas compat
|
||
def f(self): | ||
getattr(self.plot, name)(*args, **kwargs) | ||
# I have no idea why this is needed twice |
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.
RESOLVED: Function was returning next(counter_obj) when I wrote it.
@javadnoorb looks like there are unrelated commits on this PR now, do you need help with git stuff? https://pandas.pydata.org/pandas-docs/stable/contributing.html#working-with-the-code might be helpful as well. |
]) | ||
@td.skip_if_no_mpl | ||
def test_no_double_plot_for_first_group(plotting_method): | ||
class extGroupByPlot(pd.core.groupby.groupby.GroupByPlot): |
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.
I think this test can be simplified.
How about
df = pd.DataFrame({'cat': [1, 1, 2, 2], 'x': [1, 3, 5, 7], 'y': [2, 4, 6, 8]})
df.groupby('cat').plot.scatter(x='x', y='y')
assert plt.get_fignums() == [1, 2]
or something like that.
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'd need to replace .plot.scatter
with your getattr(gr, plotting_method)(x='x', y='y')
, but the basic idea is to test the output, the number of produced figures, is the number of groups.
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.
That looks much better. I didn't know about get_fignums
.
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.
Do you by any chance know how to reset this? It works for the first plot method, but then keep accumulating as pytest.mark.parametrize
is looped through.
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.
Run plt.close()
twice?
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.
Each test should close all its state. plt.close('all')
should do it.
@TomAugspurger yeah. I messed up while syncing my fork. There were too many conflicts after the merge and I manually removed mine against the master, and some newlines were left here and there. Was I supposed to do this manually? I think there was a delay in sync that caused this. Sorry about that. I'll clean it up. |
@jreback @toobaz @TomAugspurger. Just leaving a note. This should be ready for review. -thanks |
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.
It looks like there are two uses of pandas.core.groupby.base.plotting_methods
.
- core/groupby/ops.py, which you've updated
- core/rgoupby/groupby.py in
_make_wrapper
, which hasn't been updated.
Can you try just adding these new methods to plotting_methods
and seeing if anything breaks? Ideally we would just have the one frozenset. I initially added extra_plotting_methods
just to test things out.
doc/source/whatsnew/v0.24.0.txt
Outdated
- Bug in :func:'DataFrame.plot.scatter' and :func:'DataFrame.plot.hexbin' caused x-axis label and ticklabels to disappear when colorbar was on in IPython inline backend (:issue:`10611`, :issue:`10678`, and :issue:`20455`) | ||
- | ||
- Bug in :func:`DataFrame.plot.scatter` and :func:`DataFrame.plot.hexbin` caused x-axis label and ticklabels to disappear when colorbar was on in IPython inline backend (:issue:`10611`, :issue:`10678`, and :issue:`20455`) | ||
- Bug in :func:`DataFrameGroupBy.plot.scatter()` resulted in the first group being plotted twice (:issue:`21609`) |
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.
I don't think DataFrameGroupBy.plot.scatter
is included in our API docs http://pandas-docs.github.io/pandas-docs-travis/api.html. Probably OK to just do
``DataFrameGroupBy.plot.scatter``
instead of the :func:
pandas/core/groupby/groupby.py
Outdated
@@ -311,6 +311,7 @@ def __getattr__(self, name): | |||
def attr(*args, **kwargs): | |||
def f(self): | |||
return getattr(self.plot, name)(*args, **kwargs) | |||
f.__name__ = name |
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.
A comment explaining why we set the name here would be helpful.
@TomAugspurger, I don't think
pandas/pandas/core/groupby/base.py Line 80 in 26b3e7d
and pandas/pandas/core/groupby/base.py Line 86 in 26b3e7d
which are then used as methods for dataframes and series. I think only functions used in this doc can be methods of
Following the other point, adding |
Thanks for the clarification on merging those two sets. Is the make_wrapper code dead? Does removing it break any tests? I’ve never touched them.
…________________________________
From: Javad Noorbakhsh <notifications@github.com>
Sent: Monday, July 30, 2018 2:25:56 PM
To: pandas-dev/pandas
Cc: Tom Augspurger; Mention
Subject: Re: [pandas-dev/pandas] apply_frame_axis0 applies function to first group twice (#21943)
@TomAugspurger<https://github.com/TomAugspurger>, I don't think plotting_methods and extra_plotting_methods should be merged. It leads to some errors like:
AttributeError: type object 'Series' has no attribute 'hexbin'
plotting_methods affects:
https://github.com/pandas-dev/pandas/blob/26b3e7de56fdebaf1842b01d747a1a30a126c54a/pandas/core/groupby/base.py#L80
and
https://github.com/pandas-dev/pandas/blob/26b3e7de56fdebaf1842b01d747a1a30a126c54a/pandas/core/groupby/base.py#L86
which are then used as methods for dataframes and series.
I think only functions used in this doc can be methods of groupby.plot:
http://pandas.pydata.org/pandas-docs/version/0.16.2/generated/pandas.core.groupby.DataFrameGroupBy.plot.html
hist is the only exception because it has dual functionality (both for series/dataframes and groups). But I think it should be sufficient to have it in plotting_methods.
Following the other point, adding extra_plotting_methods to core/goupby/groupby.py:_make_wrapper doesn't seem to do anything when I try it. These curried_with_axis functions are pretty old and have no issue number. I can't track down why they were written, but seems like they just explicitly add an axis to the plot if none is provided.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#21943 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/ABQHIlKw6qDVSnqrNnc8dHZOliHPC3Cyks5uL13EgaJpZM4VSJaX>.
|
No, it's not dead code. Just that it doesn't run when
|
Merge branch 'master' of https://github.com/pandas-dev/pandas into fix_apply_frame_axis0_tmp
closing as stale. if you'd like to continue working, pls ping. |
git diff upstream/master -u -- "*.py" | flake8 --diff