Skip to content

Conversation

@topper-123
Copy link
Contributor

@topper-123 topper-123 commented Jun 10, 2023

Deprecate allowing using raw, result_type etc. as positional parameters in DataFrame.apply & Series.apply, i.e. requiring them to be keyword-only in the future.

EDIT: updated for intent.

@topper-123 topper-123 changed the title DEPR: deprectate positional params in (DataFrame|Series).apply DEPR: deprectate some positional params in (DataFrame|Series).apply Jun 10, 2023
@mroeschke mroeschke added Deprecate Functionality to remove in pandas Apply Apply, Aggregate, Transform, Map labels Jun 12, 2023
topper-123 and others added 2 commits June 12, 2023 20:09
Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>
request.node.add_marker(
pytest.mark.xfail(
raises=TypeError,
raises=TypeError if how == "agg" else FutureWarning,
Copy link
Member

Choose a reason for hiding this comment

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

I think this only fails because we configure pytest to raise internal pandas warnings as errors. Could you find a way to test the warning instead (or refactor the test entirely since it's tested above)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made a new version.

@phofl
Copy link
Member

phofl commented Jun 13, 2023

Why are you deprecating them? Do you intend to change anything that wouldn’t be possible otherwise?

@topper-123
Copy link
Contributor Author

topper-123 commented Jun 20, 2023

Why are you deprecating them? Do you intend to change anything that wouldn’t be possible otherwise?

Concretely I did it because ser.apply(func, 0) appears to be similar to ser.agg(func, 0), but actually isn't (ser.apply(func, 0) is actually ser.apply(func, convert_dtype=0), while ser.agg(func, 0) is ser.agg(func, axis=0)). Similarly, ser.apply(func, 0) seems to be similar to df.apply(func, 0) but isn't.

So this is a proposal to make the signatures more similar across these methods, by being able to add an axis: Axis = 0 positional parameter to Series.apply after this deprecation has been completed.

EDIT: So this is mostly motivated by the second positional param in Series.apply. I can revert the the DataFrame.apply part.

@rhshadrach
Copy link
Member

rhshadrach commented Jun 22, 2023

Concretely I did it because ser.apply(func, 0) appears to be similar to ser.agg(func, 0), but actually isn't (ser.apply(func, 0) is actually ser.apply(func, convert_dtype=0), while ser.agg(func, 0) is ser.agg(func, axis=0)). Similarly, ser.apply(func, 0) seems to be similar to df.apply(func, 0) but isn't.

I don't think this is a good reason to deprecate other arguments. I think we should be deprecating the other arguments only if they are deemed "not worth the maintenance burden". It's not clear to me if that's the case here. Otherwise we should find other solutions.

Would making the signature Series.apply(func, *, args, kwargs, convert_dtype, ...) satisfy without losing functionality?

@phofl
Copy link
Member

phofl commented Jun 22, 2023

Personally I also object to the positional deprecation, this probably impact a lot of users while not offering any benefit on our side (maintenance wise) and I am also not convinced that this brings a big enough improvement for users to make it worthwhile.

@topper-123
Copy link
Contributor Author

topper-123 commented Jun 23, 2023

Would making the signature Series.apply(func, *, args, kwargs, convert_dtype, ...) satisfy without losing functionality?

I must have written my intention out badly, i.e. I did not intend to propose deprecate the arguments, just them being positional. So my intention is to keep the arguments, but make them keyword-only in v3.0.

Is there opposition to do that (I can check if there’s some bad phrasings in the PR if we agree on that goal)?

@topper-123 topper-123 changed the title DEPR: deprectate some positional params in (DataFrame|Series).apply DEPR: deprectate using some params as positional in (DataFrame|Series).apply Jun 23, 2023
@topper-123 topper-123 changed the title DEPR: deprectate using some params as positional in (DataFrame|Series).apply DEPR: deprecate using some params as positional in (DataFrame|Series).apply Jun 23, 2023
@topper-123
Copy link
Contributor Author

I’ve updated the title & OP to better reflect my intentions.

@phofl
Copy link
Member

phofl commented Jun 23, 2023

Yes, I object to this. The benefits don't outweigh the downside for me (as written above).

I'd feel differently if there was a maintenance benefit, but looks like this is purely cosmetic

@rhshadrach
Copy link
Member

Would making the signature Series.apply(func, *, args, kwargs, convert_dtype, ...) satisfy without losing functionality?

I must have written my intention out badly

Ah - no, the issue was my reading comprehension!

@github-actions
Copy link
Contributor

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Jul 24, 2023
@mroeschke
Copy link
Member

Seems like this proposal would need more discussion in an issue before proceeding so closing for now. Can reopen if we decided to move forward with this approach

@mroeschke mroeschke closed this Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Apply Apply, Aggregate, Transform, Map Deprecate Functionality to remove in pandas Stale

4 participants