def _apply(self, func, axis=0, subset=None, **kwargs):
    subset = (slice(None) if (subset is None) else subset)
    subset = _non_reducing_slice(subset)
    data = self.data.loc[subset]
    if (axis is not None):
        result = data.apply(func, axis=axis, result_type='expand', **kwargs)
        result.columns = data.columns
    else:
        result = func(data, **kwargs)
        if (not isinstance(result, pd.DataFrame)):
            raise TypeError('Function {func!r} must return a DataFrame when passed to `Styler.apply` with axis=None'.format(func=func))
        if (not (result.index.equals(data.index) and result.columns.equals(data.columns))):
            msg = 'Result of {func!r} must have identical index and columns as the input'.format(func=func)
            raise ValueError(msg)
    result_shape = result.shape
    expected_shape = self.data.loc[subset].shape
    if (result_shape != expected_shape):
        msg = 'Function {func!r} returned the wrong shape.\nResult has shape: {res}\nExpected shape:   {expect}'.format(func=func, res=result.shape, expect=expected_shape)
        raise ValueError(msg)
    self._update_ctx(result)
    return self
def _apply(self, func, axis=0, subset=None, **kwargs):
    subset = (slice(None) if (subset is None) else subset)
    subset = _non_reducing_slice(subset)
    data = self.data.loc[subset]
    if (axis is not None):
        result = data.apply(func, axis=axis, result_type='expand', **kwargs)
        result.columns = data.columns
    else:
        result = func(data, **kwargs)
        if (not isinstance(result, pd.DataFrame)):
            raise TypeError('Function {func!r} must return a DataFrame when passed to `Styler.apply` with axis=None'.format(func=func))
        if (not (result.index.equals(data.index) and result.columns.equals(data.columns))):
            msg = 'Result of {func!r} must have identical index and columns as the input'.format(func=func)
            raise ValueError(msg)
    result_shape = result.shape
    expected_shape = self.data.loc[subset].shape
    if (result_shape != expected_shape):
        msg = 'Function {func!r} returned the wrong shape.\nResult has shape: {res}\nExpected shape:   {expect}'.format(func=func, res=result.shape, expect=expected_shape)
        raise ValueError(msg)
    self._update_ctx(result)
    return self