Skip to content

Conversation

javadnoorb
Copy link
Contributor

@javadnoorb javadnoorb commented Jul 17, 2018

javadnoorb and others added 30 commits March 21, 2018 20:53
removing PATH_MODE debugging flag
remove whitespaces
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>
* 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
Copy link
Contributor Author

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.

@TomAugspurger
Copy link
Contributor

@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):
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run plt.close() twice?

Copy link
Contributor

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.

@javadnoorb
Copy link
Contributor Author

javadnoorb commented Jul 26, 2018

@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.

@javadnoorb
Copy link
Contributor Author

@jreback @toobaz @TomAugspurger. Just leaving a note. This should be ready for review. -thanks

Copy link
Contributor

@TomAugspurger TomAugspurger left a 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.

  1. core/groupby/ops.py, which you've updated
  2. 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.

- 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`)
Copy link
Contributor

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:

@@ -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
Copy link
Contributor

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.

@javadnoorb
Copy link
Contributor Author

javadnoorb commented Jul 30, 2018

@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:

series_apply_whitelist = ((common_apply_whitelist |

and

dataframe_apply_whitelist = ((common_apply_whitelist |

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 groupby and groupby.plot). 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.

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Jul 31, 2018 via email

@javadnoorb
Copy link
Contributor Author

No, it's not dead code. Just that it doesn't run when groupby.plot.apply is called. Commenting it out causes some tests to fail:

___________________________________________________________________________________________________ TestDataFrameGroupByPlots.test_series_groupby_plotting_nominally_works ___________________________________________________________________________________________________

self = <pandas.tests.plotting.test_groupby.TestDataFrameGroupByPlots object at 0x1a1fb72278>

    def test_series_groupby_plotting_nominally_works(self):
        n = 10
        weight = Series(np.random.normal(166, 20, size=n))
        height = Series(np.random.normal(60, 10, size=n))
        with tm.RNGContext(42):
            gender = np.random.choice(['male', 'female'], size=n)
    
        weight.groupby(gender).plot()
        tm.close()
>       height.groupby(gender).hist()

pandas/tests/plotting/test_groupby.py:49: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <pandas.core.groupby.generic.SeriesGroupBy object at 0x1a1fc10d30>, attr = 'hist'

    def __getattr__(self, attr):
        if attr in self._internal_names_set:
            return object.__getattribute__(self, attr)
        if attr in self.obj:
            return self[attr]
        # if hasattr(self.obj, attr):
        #     return self._make_wrapper(attr)
    
        raise AttributeError("%r object has no attribute %r" %
>                            (type(self).__name__, attr))
E       AttributeError: 'SeriesGroupBy' object has no attribute 'hist'

pandas/core/groupby/groupby.py:537: AttributeError

@jreback
Copy link
Contributor

jreback commented Nov 4, 2018

closing as stale. if you'd like to continue working, pls ping.

@jreback jreback closed this Nov 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

df.groupby(.).plot.scatter() creates a spurious initial plot