Skip to content

DEPR: Styler.where in favour of using applymap and apply #40124

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

Closed
attack68 opened this issue Feb 28, 2021 · 0 comments · Fixed by #40821 or #40845
Closed

DEPR: Styler.where in favour of using applymap and apply #40124

attack68 opened this issue Feb 28, 2021 · 0 comments · Fixed by #40821 or #40845
Labels
API - Consistency Internal Consistency of API/Behavior Styler conditional formatting using DataFrame.style
Milestone

Comments

@attack68
Copy link
Contributor

Styler by definition is a conditional renderer. The functions it provides, apply and applymap, serve as conditional functions to render a style.

The function Styler.where therefore, in the first case, seems unnecessary and indirectly confusing since it is a conditional rendering function implying perhaps the other methods are not. Not only is it just a 'convenience' wrapper of applymap:

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

But I also think, in the second case, it is quite inconvenient for a couple reasons:

  1. The docs are ambiguous:
cond: callable: cond should take a scalar and return a boolean.
**kwargs: dict: pass along to cond.

and in fact kwargs appear in the code but do nothing.

  1. It feels that there is more benefit to be had by a user learning how you use apply and applymap to the same effect through good examples.

For example:
styler.applymap(lambda v: props if cond(v) else None, subset=subset) or
styler.apply(lambda d: np.where(d > 10, props, ""), axis=None, subset=subset)

seem pretty straightforward replacements???

Perhaps documenting in the first instance that apply and applymap are preferred over where is non-controversial.

@attack68 attack68 added Needs Triage Issue that has not been reviewed by a pandas team member Usage Question API - Consistency Internal Consistency of API/Behavior and removed Usage Question labels Feb 28, 2021
@jbrockmendel jbrockmendel added the Styler conditional formatting using DataFrame.style label Mar 24, 2021
@attack68 attack68 removed the Needs Triage Issue that has not been reviewed by a pandas team member label Mar 25, 2021
@jreback jreback added this to the 1.3 milestone Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API - Consistency Internal Consistency of API/Behavior Styler conditional formatting using DataFrame.style
Projects
None yet
3 participants