Skip to content

BUG-26214 fix colors parameter in DataFrame.boxplot #26456

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

Merged
merged 7 commits into from
Sep 20, 2019

Conversation

JustinZhengBC
Copy link
Contributor

@JustinZhengBC JustinZhengBC commented May 19, 2019

This PR fixes issues in the handling of the color parameter in the implementation of DataFrame.boxplot that do not exist in DataFrame.plot.box

  • the color parameter is now removed from kwds before the matplotlib call, preventing an error
  • an alternative implementation of color extraction from color, as _get_standard_colors did not preserve the appropriate order (without looking at that function, one can see that the previous implementation would give the boxes and the medians the same color even when otherwise specified)
  • checking that color is actually a dict

@codecov
Copy link

codecov bot commented May 19, 2019

Codecov Report

Merging #26456 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #26456      +/-   ##
==========================================
- Coverage   91.73%   91.73%   -0.01%     
==========================================
  Files         174      174              
  Lines       50754    50762       +8     
==========================================
+ Hits        46560    46565       +5     
- Misses       4194     4197       +3
Flag Coverage Δ
#multiple 90.23% <100%> (ø) ⬆️
#single 41.68% <0%> (-0.1%) ⬇️
Impacted Files Coverage Δ
pandas/plotting/_core.py 84.06% <100%> (+0.16%) ⬆️
pandas/io/gbq.py 78.94% <0%> (-10.53%) ⬇️
pandas/core/frame.py 97.02% <0%> (-0.12%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 80bddaf...5cc6812. Read the comment docs.

@codecov
Copy link

codecov bot commented May 19, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@9c7e604). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #26456   +/-   ##
=========================================
  Coverage          ?   91.86%           
=========================================
  Files             ?      179           
  Lines             ?    50712           
  Branches          ?        0           
=========================================
  Hits              ?    46585           
  Misses            ?     4127           
  Partials          ?        0
Flag Coverage Δ
#multiple 90.45% <100%> (?)
#single 41.11% <0%> (?)
Impacted Files Coverage Δ
pandas/plotting/_matplotlib/boxplot.py 77.37% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9c7e604...9c6fc49. Read the comment docs.

@@ -424,7 +424,7 @@ Plotting
- Fixed bug where :class:`api.extensions.ExtensionArray` could not be used in matplotlib plotting (:issue:`25587`)
- Bug in an error message in :meth:`DataFrame.plot`. Improved the error message if non-numerics are passed to :meth:`DataFrame.plot` (:issue:`25481`)
- Bug in incorrect ticklabel positions when plotting an index that are non-numeric / non-datetime (:issue:`7612` :issue:`15912` :issue:`22334`)
-
- Bug where :meth:`DataFrame.boxplot` would not accept a `color` parameter like `DataFrame.plot.box` (:issue:`26214`)
Copy link
Member

Choose a reason for hiding this comment

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

Does the behavior here match exactly what you'd get with DataFrame.plot.box? I assume the latter just passes kwargs on through but this looks to do special handling, so not entirely equivalent right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DataFrame.plot.box does special handling too. Neither color nor any of its valid keys are listed as a valid kwarg in matplotlib.pyplot.boxplot

@WillAyd
Copy link
Member

WillAyd commented May 19, 2019

So does plot.box accept this and are they now fully aligned? cc @datapythonista

@datapythonista
Copy link
Member

Would be nice to wait until #26414 is in master to merge this.

@jreback
Copy link
Contributor

jreback commented Jun 8, 2019

we merged the refactor of the mpl backend, can you merge master and update to the new locations.

valid_keys = ['boxes', 'whiskers', 'medians', 'caps']
for i in range(4):
if valid_keys[i] in colors:
result[i] = colors[valid_keys[i]]
Copy link
Contributor

Choose a reason for hiding this comment

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

Should invalid colors raise? To catch issues like .boxplot(colors={'boxse': 'red'})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They did in DataFrame.plot.box, so yes, I think so

@JustinZhengBC
Copy link
Contributor Author

@jreback I've merged master and updated the PR


colors = kwds.pop('color', None)
if colors:
if isinstance(colors, dict):
Copy link
Contributor

Choose a reason for hiding this comment

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

could be is_dict_like

@WillAyd
Copy link
Member

WillAyd commented Aug 26, 2019

@JustinZhengBC can you move whatsnew to 1.0.0 and merge master?

@JustinZhengBC
Copy link
Contributor Author

@WillAyd done

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

Just so I'm clear - is the logic here the same for DataFrame.plot.box or do they diverge?

@WillAyd WillAyd added this to the 1.0 milestone Aug 26, 2019
Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

looks like a merge conflict in whatsnew but otherwise lgtm. @TomAugspurger maybe thoughts on this?

@WillAyd
Copy link
Member

WillAyd commented Sep 19, 2019

@JustinZhengBC can you merge master and fix merge conflict?

@TomAugspurger any thoughts on this? If not planning to merge in 2 days

@TomAugspurger
Copy link
Contributor

Fixed the merge conflict. Merge on green.

@WillAyd WillAyd merged commit 3ffcc74 into pandas-dev:master Sep 20, 2019
@WillAyd
Copy link
Member

WillAyd commented Sep 20, 2019

Thanks @JustinZhengBC !

proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

_dataframe.boxplot_ with _where_ and _by_ does not respect color keyword
6 participants