Skip to content
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: Styler.where possible deprecation #40821

Merged
merged 10 commits into from Apr 26, 2021
Merged

Conversation

attack68
Copy link
Contributor

@attack68 attack68 commented Apr 7, 2021

closes #40124

Proposal to deprecate the method: Styler.where, since Styler.applymap and Styler.where are so similar in function, and return signatures, that it is almost confusing to have 2 methods for the same thing.

Note that Styler.where offers no advantage over applymap since internally it just restructures the callable and uses applymap itself:

def where(..):
    return self.applymap(lambda val: value if cond(val, **kwargs) else other, subset=subset)

pandas/io/formats/style.py Outdated Show resolved Hide resolved
@jreback
Copy link
Contributor

jreback commented Apr 8, 2021

i would actually deprecate .applymap, as its a non-vectorized version of .where (not that this matters for Styler generally).

ok can you separate out the bug fix and do the deprecation in a different PR? (where can discuss)

@attack68
Copy link
Contributor Author

attack68 commented Apr 9, 2021

i would actually deprecate .applymap, as its a non-vectorized version of .where (not that this matters for Styler generally).

ok can you separate out the bug fix and do the deprecation in a different PR? (where can discuss)

my other PR #40845 fixes the bug. This one I left as the potential deprecation. Styler.where is not vectorized, it's effectively a one-liner invoking applymap.

@attack68 attack68 changed the title DEPR/BUG: Styler.where bug fix and possible deprecation DEPR: Styler.where possible deprecation Apr 9, 2021
# Conflicts:
#	pandas/io/formats/style.py
#	pandas/tests/io/formats/style/test_style.py
# Conflicts:
#	pandas/io/formats/style.py
@jreback jreback added Deprecate Functionality to remove in pandas Code Style Code style, linting, code_checks labels Apr 12, 2021
@jreback
Copy link
Contributor

jreback commented Apr 12, 2021

cc @pandas-dev/pandas-core any thoughts here

@rhshadrach
Copy link
Member

rhshadrach commented Apr 13, 2021

To use where in order to accomplish applymap seems unnatural:

df.where(cond=lambda _: True, some_style)

To use applymap to accomplish where seems natural:

df.applymap(lambda x: some_style if cond(x) else other_style)

@dsaxton
Copy link
Member

dsaxton commented Apr 13, 2021

To use where in order to accomplish applymap seems unnatural:

df.where(cond=lambda _: True, some_style)

To use applymap to accomplish where seems natural:

df.applymap(lambda x: some_style if cond(x) else other_style)

I think I agree with this. As a user I always find myself having to stop and think what where actually does, on the other hand methods like map, apply, and applymap are more obvious.

@jreback jreback added this to the 1.3 milestone Apr 26, 2021
@jreback jreback merged commit 8e21df2 into pandas-dev:master Apr 26, 2021
@jreback
Copy link
Contributor

jreback commented Apr 26, 2021

ok thanks, yeah no harm in deprecating

@attack68 attack68 deleted the where_fix branch April 26, 2021 12:34
yeshsurya pushed a commit to yeshsurya/pandas that referenced this pull request May 6, 2021
JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Style Code style, linting, code_checks Deprecate Functionality to remove in pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DEPR: Styler.where in favour of using applymap and apply
4 participants