Skip to content

ENH: Added more options for formats.style.bar #14757

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 2 commits into from
May 2, 2017

Conversation

jmarrec
Copy link
Contributor

@jmarrec jmarrec commented Nov 28, 2016

  • 4 tests added and passed
  • passes git diff upstream/master | flake8 --diff
  • Update documentation

You can now have the df.style.bar be centered on zero or midpoint value (in
addition to the already existing way of having the min value at the left side of the cell)


Documentation:

I have produced the following example that I think does a pretty good job of explaining the new capabilities

import pandas as pd
from IPython.display import HTML

# Case 1: s.min() < 0:
test1 = pd.Series([-100,-60,-30,-20], name='All Negative')
# Case 2: s.max() < 0:
test2 = pd.Series([10,20,50,100], name='All Positive')
# Case 3:
test3 = pd.Series([-10,-5,0,90], name='Both Pos and Neg')

head = """
<table>
    <thead>
        <th>Align</th>
        <th>All Negative</th>
        <th>All Positive</th>
        <th>Both Neg and Pos</th>
    </thead>
    </tbody>

"""

aligns = ['left','zero','mid']
for align in aligns:
    row = "<tr><th>{}</th>".format(align)
    for serie in [test1,test2,test3]:
        s = serie.copy()
        s.name=''
        row += "<td>{}</td>".format(s.to_frame().style.bar(align=align, 
                                                           color=['#d65f5f', '#5fba7d'], 
                                                           width=100).render()) #testn['width']
    row += '</tr>'
    head += row
    
head+= """
</tbody>
</table>"""
        

HTML(head)

screen shot 2016-11-28 at 17 06 21

What do you think?

@codecov-io
Copy link

codecov-io commented Nov 28, 2016

Codecov Report

Merging #14757 into master will decrease coverage by 0.02%.
The diff coverage is 92.5%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #14757      +/-   ##
==========================================
- Coverage   90.88%   90.86%   -0.03%     
==========================================
  Files         162      162              
  Lines       50821    50862      +41     
==========================================
+ Hits        46190    46215      +25     
- Misses       4631     4647      +16
Flag Coverage Δ
#multiple 88.64% <92.5%> (-0.03%) ⬇️
#single 40.3% <10%> (-0.03%) ⬇️
Impacted Files Coverage Δ
pandas/io/formats/style.py 95.89% <92.5%> (-0.48%) ⬇️
pandas/plotting/_converter.py 63.54% <0%> (-1.82%) ⬇️
pandas/core/common.py 90.68% <0%> (-0.35%) ⬇️
pandas/core/generic.py 91.63% <0%> (ø) ⬆️
pandas/core/config_init.py 94.52% <0%> (+0.23%) ⬆️

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 6d0118e...c7d41fb. Read the comment docs.

" of length 2 [ `color_negative`, `color_positive`] "
"(eg: color=['#d65f5f', '#5fba7d'])\n"
"Only the first two list elements will be used here.")
warnings.warn(msg, UserWarning)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I do raise TypeError(msg) instead of issuing a warning?

(removing the line saying that only two elements will be used of course...)

Copy link
Member

Choose a reason for hiding this comment

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

I prefer ValueError

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, done.

@sinhrks sinhrks added the Output-Formatting __repr__ of pandas objects, to_string label Nov 28, 2016
" of length 2 [ `color_negative`, `color_positive`] "
"(eg: color=['#d65f5f', '#5fba7d'])\n"
"Only the first two list elements will be used here.")
warnings.warn(msg, UserWarning)
Copy link
Member

Choose a reason for hiding this comment

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

I prefer ValueError


normed = s * 50 * width / (100 * m)

base = 'width: 10em; height: 80%;'
Copy link
Member

Choose a reason for hiding this comment

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

pls pass base from .bar because these are identical.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@jreback
Copy link
Contributor

jreback commented Dec 26, 2016

can you rebase / update

@TomAugspurger TomAugspurger requested review from TomAugspurger and removed request for TomAugspurger December 27, 2016 13:37
@jorisvandenbossche
Copy link
Member

cc @TomAugspurger

@jmarrec
Copy link
Contributor Author

jmarrec commented Jan 2, 2017

Sorry for the delay, I'm trying to rebase right now (on 9947a99), but I'm getting a few errors

When doing just 'import pandas as pd':

AttributeError: module 'pandas' has no attribute 'compat'

When running the 'formats' nosetests:

AttributeError: module 'pandas.lib' has no attribute 'is_decimal'

Is it only me or is the master broken somehow?

@jreback
Copy link
Contributor

jreback commented Jan 2, 2017

you need to rebuild the extensions

python setup.py build_ext --inplace

generally you should do this anytime you pull from master (and there is an update)

@jmarrec
Copy link
Contributor Author

jmarrec commented Jan 2, 2017

That makes sense, thanks! After building everything works like it used to.

@jreback
Copy link
Contributor

jreback commented Feb 27, 2017

can you rebase / update

@jmarrec
Copy link
Contributor Author

jmarrec commented Feb 28, 2017

Done. When do you think this will be merged in?

@jmarrec
Copy link
Contributor Author

jmarrec commented Feb 28, 2017

The CircleCI has tests that fails, but they run fine on my local branch.

For example:

pandas$ nosetests pandas/tests/formats/test_style.py:TestStyler.test_bar_align_mid_all_pos
.
----------------------------------------------------------------------
Ran 1 test in 0.044s

OK

@jreback
Copy link
Contributor

jreback commented Feb 28, 2017

we switched to pytest recently FYI

take a look here: https://travis-ci.org/pandas-dev/pandas/jobs/206164419

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

pls add a whatsnew note (and you have some failing tests)

def _bar_left(s, color, width, base):
"""
The minimum value is aligned at the left of the cell
.. versionadded:: 0.17.1
Copy link
Contributor

Choose a reason for hiding this comment

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

you don't need the vesionadded tags (and they are outdated)

@@ -348,6 +348,109 @@ def test_bar_0points(self):
', transparent 0%)']}
self.assertEqual(result, expected)

def test_bar_align_zero_pos_and_neg(self):
df = pd.DataFrame({'A': [-10, 0, 20, 90]})
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add this issue number as a comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean this pull request number? #14757?

@jreback
Copy link
Contributor

jreback commented Feb 28, 2017

@TomAugspurger can you review

@jreback
Copy link
Contributor

jreback commented Feb 28, 2017

@jmarrec I would also take your above picture and add it to the style docs themselves (choose a nice place for it).

@jmarrec
Copy link
Contributor Author

jmarrec commented Feb 28, 2017

My failing tests are in python 2.7 only, because I expect 80.0% but I get 80% instead.

Eg:

Result in Python 2.7:

 (3, 0): ['width: 10em',
  ' height: 80%',
  'background: linear-gradient(90deg, transparent 0%, transparent 80%, #d65f5f 80%, #d65f5f 100%, transparent 100%)']}

expected:


 (3, 0): ['width: 10em',
  ' height: 80%',
  'background: linear-gradient(90deg, transparent 0%, transparent 80.0%, #d65f5f 80.0%, #d65f5f 100%, transparent 100%)']}

@jreback
Copy link
Contributor

jreback commented Feb 28, 2017

ok, so can do 1 of 2 things.

  • conform both results in py2 and py3 (e.g. you are formatting the string)
    or
  • use a subtition for that value in the test (with different values for py2 and py3).

ideally first way is better

]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use `Styler.set_properties` when the style doesn't actually depend on the values."
"New in version 0.19.2 is the ability to customize further the bar chart: You can now have the `df.style.bar` be centered on zero or midpoint value (in addition to the already existing way of having the min value at the left side of the cell), and you can pass a list of `[color_negative, color_positive]`.\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

-> 0.20.0

width: float
A number between 0 or 100. The largest value will cover ``width``
percent of the cell's width
align : str, default 'left'
.. versionadded:: 0.19.2
Copy link
Contributor

Choose a reason for hiding this comment

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

-> 0.20.0
also need a blank line before/after the versionadded tag

@jreback
Copy link
Contributor

jreback commented Feb 28, 2017

cc @jorisvandenbossche

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

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

Nice enhancement! Added some comments

]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use `Styler.set_properties` when the style doesn't actually depend on the values."
"New in version 0.20.0 is the ability to customize further the bar chart: You can now have the `df.style.bar` be centered on zero or midpoint value (in addition to the already existing way of having the min value at the left side of the cell), and you can pass a list of `[color_negative, color_positive]`.\n",
Copy link
Member

Choose a reason for hiding this comment

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

The table below is a nice overview. But it is also a bit hard to interpret as a user what is the actual code he/she should use. Can you add first an example with the existing frame? Eg df.style.bar(subset=['B'], align='mid'). And then give the overview table.

.. versionadded:: 0.17.1

Parameters
----------
subset: IndexSlice, default None
a valid slice for ``data`` to limit the style application to
axis: int
color: str
color: str (for align='left') or 2-tuple/list (for align='zero', 'mid')
Copy link
Member

Choose a reason for hiding this comment

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

In the _bar_left function also a tuple is accepted, which contradicts with this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching that.

- 'zero' : a value of zero is located at the center of the cell
- 'mid' : the center of the cell is at (max-min)/2, or
if values are all negative (positive) the zero is aligned
at the right (left) of the cell
Copy link
Member

Choose a reason for hiding this comment

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

I find the names a bit confusing. As 'zero' is actually more 'centered'? While I first thought 'mid' would give me centered bars, but that depends on the actual values you have.

BTW, 'mid' actually seems a more sensible default. Maybe we should change that? (cc @TomAugspurger)

Copy link
Contributor

Choose a reason for hiding this comment

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

I find the names a bit confusing. As 'zero' is actually more 'centered'?

I think this is only true if you have all positive values. So

pd.DataFrame(np.arange(-2, 5)).style.bar(align='zero')

Makes sense to me since zero is at the middle.

BTW, 'mid' actually seems a more sensible default.

Probably, but I'm not sure it's worth breaking API. Maybe with a deprecation cycle?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jorisvandenbossche: @TomAugspurger is correct, it's really centered on zero. The example I tried to include in the doc and that I pasted in the first post of this PR should highlight that fact, otherwise I should revise it.

I have no idea how you handle deprecation cycles etc, so I'll leave that completely up to you guys.

color=color, width=width, base=base)
elif align == 'mid':
self.apply(self._bar_center_mid, subset=subset, axis=axis,
color=color, width=width, base=base)
Copy link
Member

Choose a reason for hiding this comment

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

Can you do here an "else" clause to raise a ValueError when a not accepted value for align was passed? and also add a test for it.
(with playing a bit, I already was bitten by this by trying to pass 'right' and 'center' to align, and thinking that it was not working :-))

@jmarrec
Copy link
Contributor Author

jmarrec commented Mar 9, 2017

@jorisvandenbossche I haven't forgotten about your comments, it just fell on my back burner. I'll try to get to it asap in the coming days.

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.

This is really close. I think just adding the test for raising with invalid aligns. Do you have time to update @jmarrec ?

width: float
A number between 0 or 100. The largest value will cover ``width``
percent of the cell's width
align : str, default 'left'
.. versionadded:: 0.19.2
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you change these to 0.20.0

def _bar_left(s, color, width, base):
"""
The minimum value is aligned at the left of the cell
.. versionadded:: 0.17.1
Copy link
Contributor

Choose a reason for hiding this comment

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

.. versionadded:: 0.20.0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you sure you want me to do that? This method was added in 0.17.1, I just modified it to accept a tuple of color.

Copy link
Contributor Author

@jmarrec jmarrec Apr 5, 2017

Choose a reason for hiding this comment

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

@jreback told me in an earlier review (Feb 28) that I didn't need the versionadded tags for these, so I deleted them all. Which?

def _bar_center_zero(s, color, width, base):
"""
Creates a bar chart where the zero is centered in the cell
.. versionadded:: 0.19.2
Copy link
Contributor

Choose a reason for hiding this comment

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

.. versionadded:: 0.20.0

def _bar_center_mid(s, color, width, base):
"""
Creates a bar chart where the midpoint is centered in the cell
.. versionadded:: 0.19.2
Copy link
Contributor

Choose a reason for hiding this comment

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

.. versionadded:: 0.20.0

width: float
A number between 0 or 100. The largest value will cover ``width``
percent of the cell's width
align : str, default 'left'
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 the proper format on this line is

align : {'left', 'zero',' mid'}

But the explanations below are great. Keep those too.

- 'zero' : a value of zero is located at the center of the cell
- 'mid' : the center of the cell is at (max-min)/2, or
if values are all negative (positive) the zero is aligned
at the right (left) of the cell
Copy link
Contributor

Choose a reason for hiding this comment

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

I find the names a bit confusing. As 'zero' is actually more 'centered'?

I think this is only true if you have all positive values. So

pd.DataFrame(np.arange(-2, 5)).style.bar(align='zero')

Makes sense to me since zero is at the middle.

BTW, 'mid' actually seems a more sensible default.

Probably, but I'm not sure it's worth breaking API. Maybe with a deprecation cycle?

@TomAugspurger TomAugspurger mentioned this pull request Apr 3, 2017
@jmarrec
Copy link
Contributor Author

jmarrec commented Apr 4, 2017

@TomAugspurger Really sorry, it had fallen on the back burner. I'll get on it this week, will try for tomorrow, so I can put this to bed.

@jmarrec
Copy link
Contributor Author

jmarrec commented Apr 5, 2017

Yikes, this looks really messy sorry. For some reason when I rebased on upstream/master today, my branch diverged. I merged origin/style-bar back into my local branch, and pushed... I didn't know it'd clutter this PR that much, and now that I pushed I don't want to rewrite history.

Anyways, I think I made all the changes you three requested, except the versionadded tags on each of the _bar_xxx methods since @jreback had told me to delete them and it seems @TomAugspurger reviewed an older version where they were still there but outdated (I have deleted them a while ago). If you want me to add them I guess I can. Otherwise I hope this is ready to go!

@jreback
Copy link
Contributor

jreback commented Apr 5, 2017

@jmarrec looks like you pushed all commits, do this

git rebase -i thisbranch origin/master
git push yourorigin thisbranch -f

to fix

@jmarrec
Copy link
Contributor Author

jmarrec commented Apr 5, 2017

@jreback in your example 'origin' means this 'pandas-dev' repo right?

I end up with a detached HEAD, I'm afraid of force pushing. Is that expected?

@jreback
Copy link
Contributor

jreback commented Apr 5, 2017

i'll fix your branch give me about 15 min

jreback pushed a commit to jreback/pandas that referenced this pull request Apr 5, 2017
Author: Julien Marrec <[email protected]>

Closes pandas-dev#14757 from jmarrec/style-bar and squashes the following commits:

dc3cbe8 [Julien Marrec] Added a whatsnew note
af6c9bd [Julien Marrec] Added a simple example before the parametric one
80a3ce0 [Julien Marrec] Check for bad align value and raise. Wrote test for it too
5875eb9 [Julien Marrec] Change docstrings for color and align
5a22ee1 [Julien Marrec] Merge commit '673fb8f828952a4907e5659c1fcf83b771db7280' into style-bar
0e74b4d [Julien Marrec] Fix versionadded
1b7ffa2 [Julien Marrec] Added documentation on the new df.style.bar options for align and Colors in the documentation.
46bee6d [Julien Marrec] Change the tests to match new float formats.
01c200c [Julien Marrec] Format flots to avoid issue with py2.7 / py3.5 compta.
7ac2443 [Julien Marrec] Changes according to @sinhrks: Raise ValueError instead of warnings when color isn’t a str or 2-tuple/list. Passing “base” from bar().
e3f714c [Julien Marrec] Added a check on color argument that will issue a warning. Not sure if need to raise TypeError or issue a UserWarning if a list with more than two elements is passed.
f12faab [Julien Marrec] Fixed line too long `git diff upstream/master | flake8 --diff now passes`
7c89137 [Julien Marrec] ENH: Added more options for formats.style.bar
673fb8f [Julien Marrec] Fix versionadded
506f3d2 [Julien Marrec] Added documentation on the new df.style.bar options for align and Colors in the documentation.
e0563d5 [Julien Marrec] Change the tests to match new float formats.
d210938 [Julien Marrec] Format flots to avoid issue with py2.7 / py3.5 compta.
b22f639 [Julien Marrec] Changes according to @sinhrks: Raise ValueError instead of warnings when color isn’t a str or 2-tuple/list. Passing “base” from bar().
3046626 [Julien Marrec] Added a check on color argument that will issue a warning. Not sure if need to raise TypeError or issue a UserWarning if a list with more than two elements is passed.
524a9ab [Julien Marrec] Fixed line too long `git diff upstream/master | flake8 --diff now passes`
d1eafbb [Julien Marrec] ENH: Added more options for formats.style.bar
@jmarrec
Copy link
Contributor Author

jmarrec commented May 1, 2017

@jreback will this make it in (or through #15900, now closed)?

@jreback
Copy link
Contributor

jreback commented May 1, 2017

see the comments - iirc needs some more tests

@jmarrec
Copy link
Contributor Author

jmarrec commented May 1, 2017

Well, missing I'm missing something obvious, but I don't see any comments left to address, that's precisely why I'm asking.

Like I wrote a month ago, the only "open" things is what @TomAugspurger asked, that is to change the version added tags, but he was reviewing an outdated version, because before that you already told me to delete these version added tags, which I did.

@TomAugspurger
Copy link
Contributor

I think @jorisvandenbossche's comment https://github.com/pandas-dev/pandas/pull/14757/files/b22f6392b3416cdc02138a79efb8f179751c8141#r104129905 is still outstanding. Handling cases like .bar(align='foo'). That should raise with something like ValueError('align' must be one of {'left', 'zero', 'mid'}, got 'foo' instead)

Also can you change all of the self.assertEqual(left, right)s to assert left == right?

@jmarrec
Copy link
Contributor Author

jmarrec commented May 1, 2017

Was done on April 5, see https://github.com/jmarrec/pandas/blob/style-bar/pandas/formats/style.py#L1034.

I did the change you requested (in all the file not just my changes, used a regex...).

Now, is everything ok?

@TomAugspurger
Copy link
Contributor

Whoops, looks like some git issues. Let me see if I can rebase for you, one sec.

@jmarrec
Copy link
Contributor Author

jmarrec commented May 1, 2017

If you find how to fix it (Jreback did earlier), if you could please share which commands did the trick, that'd be great thanks

You can now have the bar be centered on zero or midpoint value (in
addition to the already existing way of having the min value at the left side of the cell)

Fixed line too long
`git diff upstream/master | flake8 --diff now passes`

Change the tests to match new float formats.

Added documentation on the new df.style.bar options for align and Colors in the documentation.

Fix versionadded

ENH: Added more options for formats.style.bar

You can now have the bar be centered on zero or midpoint value (in
addition to the already existing way of having the min value at the left side of the cell)

Fixed line too long
`git diff upstream/master | flake8 --diff now passes`

Change the tests to match new float formats.

Added documentation on the new df.style.bar options for align and Colors in the documentation.

Fix versionadded

Check for bad align value and raise. Wrote test for it too

Added a simple example before the parametric one

Added a whatsnew note

Replaced 'self.assertEqual(left, rigth)' by 'assert left == right' like
@TomAugspurger asked

rebased
@TomAugspurger
Copy link
Contributor

Typically it's just git fetch upstream, then git rebase upstream/master. This was a bit tricker than usual because it's been sitting out for so long (sorry about that) and we've re-arranged a lot of things now. This causes conflicts, since two commits touched the same lines so you have to go in and fix them manually with your editor. Then it's git add <files> and git rebase --continue. until you're fully rebased.

ca9c0d5 should have everything down in a single commit, if you want to give that a skim to make sure I didn't miss anything.

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

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

Added a commit with a small doc correction (indentation and white space). And also aligned the signature with documentation, adding the new keyword at the end, not breaking people who used axis positional

@jorisvandenbossche
Copy link
Member

Let's merge this PR, but, I find we should think about changing the default value. If we all think 'mid' is the more sensible default, IMO we should just change it.
It's a while that I look into the PR in detail, but if I recall correctly, the 'mid' argument would only change things in case of negative values? (which I think is a less occurring usecase, and currently also a bid odd result?) If that is correct, I would opt to just change it.

@TomAugspurger TomAugspurger merged commit 217864e into pandas-dev:master May 2, 2017
@gfyoung
Copy link
Member

gfyoung commented May 2, 2017

@TomAugspurger : For subsequent PR's, could you check to make sure that old nosetest idiom is not being used? I found a couple in the diff that you just merged in.

@TomAugspurger
Copy link
Contributor

My apologies. I thought I caught all those in the rebase :/

I'll submit a fix now.

@gfyoung
Copy link
Member

gfyoung commented May 2, 2017

No worries. I'm putting up a PR to remove vestigial statements like these, so that won't be necessary.

I just wanted to alert you about it for subsequent PR's.

pcluo pushed a commit to pcluo/pandas that referenced this pull request May 22, 2017
* ENH: Added more options for formats.style.bar

You can now have the bar be centered on zero or midpoint value (in
addition to the already existing way of having the min value at the left side of the cell)

Fixed line too long
`git diff upstream/master | flake8 --diff now passes`

Change the tests to match new float formats.

Added documentation on the new df.style.bar options for align and Colors in the documentation.

Fix versionadded

ENH: Added more options for formats.style.bar

You can now have the bar be centered on zero or midpoint value (in
addition to the already existing way of having the min value at the left side of the cell)

Fixed line too long
`git diff upstream/master | flake8 --diff now passes`

Change the tests to match new float formats.

Added documentation on the new df.style.bar options for align and Colors in the documentation.

Fix versionadded

Check for bad align value and raise. Wrote test for it too

Added a simple example before the parametric one

Added a whatsnew note

Replaced 'self.assertEqual(left, rigth)' by 'assert left == right' like
@TomAugspurger asked

rebased

* small doc fixes
@halflings
Copy link

This is breaking the previous behavior of Pandas when using .plot.bar : passing a list of colors (with 2 elements or more) would give each bar a different color, as it is the case in matplotlib.
I also think passing an array with two values which are implicitly interpreted as [negative_color, positive_color] is confusing, and we should have instead two explicit parameters for this feature.

Example of bar coloring breaking in 0.20:

import pandas as pd
df = pd.DataFrame(dict(created=[0, 1, 2, 3], amount=[6, 1, 2, 5], is_active=[0, 1, 0, 1]))
df.set_index('created').plot.bar(y='amount', color=df.is_active.apply(lambda v : ['red', 'blue'][v]

Shows this in previous verisons:

download
))

Everything is blue in 0.20+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants