DEPR: Styler.where
in favour of using applymap
and apply
· Issue #40124 · pandas-dev/pandas (original) (raw)
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:
- 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.
- It feels that there is more benefit to be had by a user learning how you use
apply
andapplymap
to the same effect through good examples.
For example:styler.applymap(lambda v: props if cond(v) else None, subset=subset)
orstyler.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.