Skip to content

Conversation

@attack68
Copy link
Contributor

@attack68 attack68 commented Jan 25, 2021

Also minor edits to docs to extend information and show examples.

cc @TomAugspurger

@attack68
Copy link
Contributor Author

attack68 commented Feb 1, 2021

this is ready for review.

It fixes the functionality and edits the docs where necessary, including some better examples.

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure we should change this. why can't the user just wrap the return value inside the apply.

@jreback jreback added the Styler conditional formatting using DataFrame.style label Feb 7, 2021
@attack68
Copy link
Contributor Author

attack68 commented Feb 7, 2021

not sure we should change this. why can't the user just wrap the return value inside the apply.

Dont know why this restriction was placed in the first place. If you use axis in [0,1] then your function must return 1-dim array like (numpy array allowed), but axis=None must need a DataFrame. This makes it quite painful to implement simple numpy functions like nanmax cause the user has to deal with the different cases and match the return type.

The builtin functions always have, for example, logic like this:

        if data.ndim == 1:  # Series from .apply
            return [attr if v else "" for v in extrema]
        else:  # DataFrame from .tee
            return pd.DataFrame(
                np.where(extrema, attr, ""), index=data.index, columns=data.columns
            )

I dont really understand the downside to just handling an array function output in all cases for axis.

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok @attack68 this is ok, yeah consistency is better here. small comments, ping on green.

on ``axis``), and return an object with the same shape.
Must return a DataFrame with identical index and
column labels when ``axis=None``.
column labels or an ndarray of appropriate shape when ``axis=None``.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same shape as input

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add versionchanged 1.3

@jreback jreback modified the milestones: 1.2.3, 1.3 Feb 7, 2021
@attack68
Copy link
Contributor Author

attack68 commented Feb 8, 2021

@jreback changes done. mostly green. fails unrelated it seems

@jreback jreback merged commit 1927652 into pandas-dev:master Feb 8, 2021
@jreback
Copy link
Contributor

jreback commented Feb 8, 2021

thanks @attack68

@attack68 attack68 deleted the styler_apply branch February 10, 2021 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Styler conditional formatting using DataFrame.style

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ENH: Styler.apply with axis=None can accept ndarray

2 participants