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

ENH: Add Styler.where #17474

Merged
merged 5 commits into from Sep 11, 2017

Conversation

Projects
None yet
4 participants
@Licht-T
Contributor

Licht-T commented Sep 8, 2017

  • closes #16255
  • tests added / passed
    Added test_where_subset in pandas/tests/io/formats/test_style.py.
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry
    It makes the redundant style condition simple.
df.style.applymap(lambda val: 'color: %s' % 'red' if val < 0 else 'black')
df.style.where(lambda val: val < 0, 'color: red', 'color: black')
@pep8speaks

This comment has been minimized.

Show comment
Hide comment
@pep8speaks

pep8speaks Sep 8, 2017

Hello @Licht-T! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on September 10, 2017 at 14:48 Hours UTC

pep8speaks commented Sep 8, 2017

Hello @Licht-T! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on September 10, 2017 at 14:48 Hours UTC
@codecov

This comment has been minimized.

Show comment
Hide comment
@codecov

codecov bot Sep 8, 2017

Codecov Report

Merging #17474 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #17474      +/-   ##
==========================================
- Coverage   91.16%   91.14%   -0.02%     
==========================================
  Files         163      163              
  Lines       49561    49561              
==========================================
- Hits        45180    45171       -9     
- Misses       4381     4390       +9
Flag Coverage Δ
#multiple 88.92% <ø> (ø) ⬆️
#single 40.23% <ø> (-0.07%) ⬇️
Impacted Files Coverage Δ
pandas/io/formats/style.py 100% <ø> (ø) ⬆️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.72% <0%> (-0.1%) ⬇️

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 7e4e8ac...9cf48fb. Read the comment docs.

codecov bot commented Sep 8, 2017

Codecov Report

Merging #17474 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #17474      +/-   ##
==========================================
- Coverage   91.16%   91.14%   -0.02%     
==========================================
  Files         163      163              
  Lines       49561    49561              
==========================================
- Hits        45180    45171       -9     
- Misses       4381     4390       +9
Flag Coverage Δ
#multiple 88.92% <ø> (ø) ⬆️
#single 40.23% <ø> (-0.07%) ⬇️
Impacted Files Coverage Δ
pandas/io/formats/style.py 100% <ø> (ø) ⬆️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.72% <0%> (-0.1%) ⬇️

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 7e4e8ac...9cf48fb. Read the comment docs.

@codecov

This comment has been minimized.

Show comment
Hide comment
@codecov

codecov bot Sep 8, 2017

Codecov Report

Merging #17474 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #17474      +/-   ##
==========================================
- Coverage   91.15%   91.13%   -0.02%     
==========================================
  Files         163      163              
  Lines       49534    49534              
==========================================
- Hits        45153    45144       -9     
- Misses       4381     4390       +9
Flag Coverage Δ
#multiple 88.92% <ø> (ø) ⬆️
#single 40.22% <ø> (-0.07%) ⬇️
Impacted Files Coverage Δ
pandas/io/formats/style.py 100% <ø> (ø) ⬆️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.72% <0%> (-0.1%) ⬇️

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 e6aed2e...82ae1dc. Read the comment docs.

codecov bot commented Sep 8, 2017

Codecov Report

Merging #17474 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #17474      +/-   ##
==========================================
- Coverage   91.15%   91.13%   -0.02%     
==========================================
  Files         163      163              
  Lines       49534    49534              
==========================================
- Hits        45153    45144       -9     
- Misses       4381     4390       +9
Flag Coverage Δ
#multiple 88.92% <ø> (ø) ⬆️
#single 40.22% <ø> (-0.07%) ⬇️
Impacted Files Coverage Δ
pandas/io/formats/style.py 100% <ø> (ø) ⬆️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.72% <0%> (-0.1%) ⬇️

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 e6aed2e...82ae1dc. Read the comment docs.

@jreback

can you add a whatsnew note on Other Enahancements as well as use this in the notebook where appropriate

Show outdated Hide outdated pandas/io/formats/style.py Outdated
Show outdated Hide outdated pandas/io/formats/style.py Outdated
Show outdated Hide outdated pandas/io/formats/style.py Outdated
Show outdated Hide outdated pandas/io/formats/style.py Outdated
Show outdated Hide outdated pandas/tests/io/formats/test_style.py Outdated
for slice_ in slices:
result = self.df.style.where(f, style1, style2,
subset=slice_)._compute().ctx
expected = self.df.style.applymap(g, subset=slice_)._compute().ctx

This comment has been minimized.

@TomAugspurger

TomAugspurger Sep 8, 2017

Contributor

These tests are fine, but could you add one test that checks the generated values directly against the dictionary?

@TomAugspurger

TomAugspurger Sep 8, 2017

Contributor

These tests are fine, but could you add one test that checks the generated values directly against the dictionary?

@Licht-T

This comment has been minimized.

Show comment
Hide comment
@Licht-T

Licht-T Sep 9, 2017

Contributor

@jreback @TomAugspurger Thanks for your review. Fixed and added some new tests.

Contributor

Licht-T commented Sep 9, 2017

@jreback @TomAugspurger Thanks for your review. Fixed and added some new tests.

@Licht-T

This comment has been minimized.

Show comment
Hide comment
@Licht-T

Licht-T Sep 9, 2017

Contributor

Travis CI seems not work well due to its own error.
Could someone restart the Travis CI build?

Contributor

Licht-T commented Sep 9, 2017

Travis CI seems not work well due to its own error.
Could someone restart the Travis CI build?

@jreback

jreback approved these changes Sep 9, 2017

this seems ok, @TomAugspurger . do we have a section in api.rst for things like this?

Show outdated Hide outdated doc/source/whatsnew/v0.21.0.txt Outdated
Show outdated Hide outdated pandas/io/formats/style.py Outdated
@Licht-T

This comment has been minimized.

Show comment
Hide comment
@Licht-T

Licht-T Sep 10, 2017

Contributor

@jreback Thanks for your suggestion. Fixed!

Contributor

Licht-T commented Sep 10, 2017

@jreback Thanks for your suggestion. Fixed!

Show outdated Hide outdated doc/source/whatsnew/v0.21.0.txt Outdated
Returns
-------
self : Styler

This comment has been minimized.

@jreback

jreback Sep 10, 2017

Contributor

can you add a See Also here (pointing to .applymap) and the reciprical one there

@jreback

jreback Sep 10, 2017

Contributor

can you add a See Also here (pointing to .applymap) and the reciprical one there

Show outdated Hide outdated doc/source/whatsnew/v0.21.0.txt Outdated
@Licht-T

This comment has been minimized.

Show comment
Hide comment
@Licht-T

Licht-T Sep 10, 2017

Contributor

@jreback Thanks. All is now fixed.

Contributor

Licht-T commented Sep 10, 2017

@jreback Thanks. All is now fixed.

@jreback jreback added this to the 0.21.0 milestone Sep 11, 2017

@jreback jreback merged commit 42ed4f1 into pandas-dev:master Sep 11, 2017

3 checks passed

ci/circleci Your tests passed on CircleCI!
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@jreback

This comment has been minimized.

Show comment
Hide comment
@jreback

jreback Sep 11, 2017

Contributor

thanks @Licht-T

If you'd have a pass thru the actual documentation notebook and make a PR for anything where we should logically use .where to make the syntax more clear would be great (or indicate that it looks good).

Contributor

jreback commented Sep 11, 2017

thanks @Licht-T

If you'd have a pass thru the actual documentation notebook and make a PR for anything where we should logically use .where to make the syntax more clear would be great (or indicate that it looks good).

alanbato added a commit to alanbato/pandas that referenced this pull request Nov 10, 2017

No-Stream added a commit to No-Stream/pandas that referenced this pull request Nov 28, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment