-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
DEPR: Change boxplot return_type kwarg #12216
DEPR: Change boxplot return_type kwarg #12216
Conversation
Tests still need to be updated |
@TomAugspurger pls update |
ce3ab8d
to
97462df
Compare
@TomAugspurger can you update |
Still working on this. It looks I didn't properly deprecate the |
@TomAugspurger if you can get to this would be great, otherwise push to 0.19 :< |
I’ll update tonight or tomorrow morning. Might want to push anyway since I’ve found a discrepancy between our documented behavior and actual behavior for
|
@TomAugspurger ok, we do have a little time, and this has been around for a while. I'll keep it here and move later (or you decide its a real stumbling block) |
97462df
to
420d7b3
Compare
Well, here's a not so great thing. I think we'll have to keep the behavior of # before
a = df.groupby('d').boxplot() # OD[dict] warned
b = df.boxplot() # dict, warned
c = df.boxplot(by='d') # [axes], didn't warn
c = df.boxplot(by='d', return_type='axes') # OD[axes] and # after
a = df.groupby('d').boxplot() # OD[axes]
b = df.boxplot() # axes
c = df.boxplot(by='d') # [axes]
c = df.boxplot(by='d', return_type='axes') # OD[axes] I had hoped to just make the default 'axes', but since I din't warn in the 3rd example, I don't think we can change that. Are we OK with that? Here's the updated docs: Plot functions return scalar or arrays of :class:`matplotlib Axes <matplotlib.axes.Axes>`.
In ``boxplot``, the return type can be controlled by the ``return_type``, keyword. The valid choices are ``{"axes", "dict", "both"}``.
``'axes'`` returns a single matplotlib axes.
``'dict'`` returns a dict of matplotlib artists, similar to the matplotlib boxplot function.
``'both'`` returns a named tuple of axes and dicts.
When ``by`` is not None, you get back an ``OrderedDict`` of whatever ``return_type`` is, unless ``return_type`` is just ``None``, in which case you get back an array of axes. |
420d7b3
to
e7c5e0d
Compare
Finally, when calling boxplot on a :class:`Groupby` object, a dict of ``return_type`` | ||
Plot functions return scalar or arrays of :class:`matplotlib Axes <matplotlib.axes.Axes>`. | ||
In ``boxplot``, the return type can be controlled by the ``return_type``, keyword. The valid choices are ``{"axes", "dict", "both"}``. | ||
``'axes'`` returns a single matplotlib axes. |
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 keep those as a list?
(maybe not fully on topic, but) Is there actually a reason we are using OrderDicts here ? For example why not a series? This would give both the key access of an OrderDict as the integer indexing of a an array (and seems more natural in pandas) |
On returning a series: that is also what |
e7c5e0d
to
9844471
Compare
But more on topic: wouldn't it be possible to raise that warning now for the third case? (but keeps its behaviour as you proposed) So we can maybe in a future release align the behaviour fully. |
Basically, plot functions return :class:`matplotlib Axes <matplotlib.axes.Axes>` as a return value. | ||
In ``boxplot``, the return type can be changed by argument ``return_type``, and whether the subplots is enabled (``subplots=True`` in ``plot`` or ``by`` is specified in ``boxplot``). | ||
Plot functions return scalar or arrays of :class:`matplotlib Axes <matplotlib.axes.Axes>`. | ||
In ``boxplot``, the return type can be controlled by the ``return_type``, keyword. The valid choices are ``{"axes", "dict", "both"}``. If the ``by`` argument is ``None``, |
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.
would add a warning box that this is changed in 0.18.0
@TomAugspurger lgtm. just some small doc comments. ping when updated. |
9844471
to
bbc3413
Compare
lgtm. |
Forgot to send the post I had started last night, I could deprecate the third case ( If we aren't warning on that case, this is good to go. |
@TomAugspurger About my comment on using Series instead of OrderedDict, wouldn't that be a possible way to just change it? To be clear: the third case is |
@jorisvandenbossche yes, that makes much more sense. It's not clear to me the best way to get to there though. Do we return a |
To answer that question, we should have an idea to which extent it would break people's code. And that is of course difficult to guess, but I think in the case of The questions is also, do we return Series for the cases where now already OrderedDicts are returned? Again, the most logical usecase (accessing a value by its key) keeps working, but things might not. |
My thinking was similar, the most common operations upon receiving the array or dict of axes is to 1. do nothing, 2. select individual axes by position or key. Thankfully Series handles both of those. I'll update tonight to return Series of |
* if ``return_type`` is ``'both'`` a namedtuple containing the :class:`matplotlib Axes <matplotlib.axes.Axes>` | ||
and :class:`matplotlib Lines <matplotlib.lines.Line2D>` is returned | ||
Faceted boxplots, created by ``Groupby.boxplot`` or ``DataFrame.boxplot`` with the ``by`` | ||
keyword will return either a NumPy array of ``axes``, when ``return_type='axes'``, |
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.
This is only true in case of DataFrame.boxplot
, not for Groupby.boxplot
(unless you changed that)
51731a8
to
29c8efc
Compare
Ok, this is probably more info than anyone cares about, but The key one to note is the difference between
Since we didn't deprecate the difference there, I'll leave it in place. Will get this all cleaned up tonight and submit for review. Sorry this has taken so long :/ |
is there a reason we r not deprecating seems otherwise this is very confusing and not consistent |
29c8efc
to
9df4c84
Compare
Updated, Travis is green. To summarize the changes:
Extremely 😞 I believe that after this deprecation we should have a clear path forward API-wise, unless I'm missing something. |
|
||
Most plot functions return a scalar or an array of :class:`matplotlib Axes <matplotlib.axes.Axes>`. | ||
In ``boxplot``, the return type can be controlled by the ``return_type``, keyword. The valid choices are ``{"axes", "dict", "both"}``. If the ``by`` argument is ``None``, | ||
|
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 you need this with the table below. IOW would rather see the table, then comment if needed on particular ones?
9df4c84
to
c3e4057
Compare
c3e4057
to
40d5970
Compare
FYI the only CI failure here was codecov. |
When grouping with ``by``, a dict mapping columns to ``return_type`` | ||
is returned. | ||
When grouping with ``by``, a Series mapping columns to ``return_type`` | ||
is returned, unless ``return_type`` is None, in which case a NumPy |
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.
maybe add a link to the docs here
couple comments, but lgtm. merge on green. this has been outstanding for quite a while, let's just put it in. |
Part of pandas-dev#6581 Deprecation started in pandas-dev#7096 Changes the default value of `return_type` in DataFrame.boxplot and DataFrame.plot.box from None to 'axes'.
Aligns behavior of `Groupby.boxplot` and DataFrame.boxplot(by=.) to return a Series.
40d5970
to
60c1c26
Compare
@TomAugspurger Thanks! |
Part of #6581
Deprecation started in #7096
Changes the default value of
return_type
in DataFrame.boxplotand DataFrame.plot.box from None to 'axes'.