Skip to content
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

feat(python): Deprecate with_column #6128

Merged
merged 1 commit into from
Jan 25, 2023

Conversation

zundertj
Copy link
Collaborator

@zundertj zundertj commented Jan 8, 2023

See #6117. As you can see, this is a big change.

TODO's:

  • There are two Python tests failing, as it seems that the behaviour between with_column and with_columns is different for Series. I need to look into this.
  • tests for the deprecation warning being raised have to be added
  • I haven't touched the Rust api yet, would we want to do the same there?

Probably later this week done.

@zundertj zundertj marked this pull request as draft January 8, 2023 22:15
@ritchie46
Copy link
Member

I haven't touched the Rust api yet, would we want to do the same there?

In rust it is very common to have similar named methods for different arguments. One takes an expression the other takes a sequence of expressions. I think we should leave it like that.

@zundertj
Copy link
Collaborator Author

zundertj commented Jan 13, 2023

Ok, the failing tests were passing in a pl.Series into LazyFrame.with_columns, whilst that was fine in DataFrame.with_columns. Reason is that DataFrame.with_columns was wrapping it in a list, and then passed it on to LazyFrame.with_columns. I have moved that logic inside LazyFrame.with_columns, added a unit test to verify and now DataFrame.with_columns is the minimum possible wrapper around LazyFrame.with_columns, so there should be no inconsistency.

As a side note, I see that we handle things differently for args vs named_args in with_columns, where the latter has more flexibility (or unclear api), but lets leave that to a separate PR.

@zundertj zundertj changed the title Deprecate with_column refactor(python): Deprecate with_column Jan 13, 2023
@github-actions github-actions bot added python Related to Python Polars refactor Code improvements that do not change functionality labels Jan 13, 2023
exprs = (
[]
if exprs is None
else ([exprs] if isinstance(exprs, pli.Expr) else list(exprs))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry, my brain cant handle this on a Friday night...

@@ -5568,8 +5577,6 @@ def with_columns(
└─────┴──────┴───────┴──────┴───────┘

"""
if exprs is not None and not isinstance(exprs, Sequence):
exprs = [exprs]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is now gone

@zundertj zundertj marked this pull request as ready for review January 13, 2023 20:26
@ritchie46
Copy link
Member

Is everybody good to go on this one? I don't want to merge this immediately, but I want to add the deprecation on the breaking release I plan end of this month. This is core functionality IMO and I think we are becoming used enough that we should introduce a bit of a grace period.

@zundertj
Copy link
Collaborator Author

This will cause for many users deprecation warnings, so please double/triple check that we are happy with this indeed.

@alexander-beedie
Copy link
Collaborator

alexander-beedie commented Jan 14, 2023

This will cause for many users deprecation warnings, so please double/triple check that we are happy with this indeed.

Looks like a winner to me...

One thing: I'd make the DeprecationWarning text "This method will be removed in the future" more specific, eg: "This method will be removed shortly" (and maybe even mention "in 0.16")

@stinodego
Copy link
Member

stinodego commented Jan 17, 2023

I think this is a good move!

And we don't have to remove with_column in 0.16.0, right? As it is widely used, I would suggest to just leave it in until 0.17.0.

I agree with @alexander-beedie that we should include this version information in the deprecation message, to help users schedule their upgrade.

Also, I am going to rebrand this as an 'enhancement', since this affects our public API.

@stinodego stinodego changed the title refactor(python): Deprecate with_column feat(python): Deprecate with_column Jan 17, 2023
@stinodego stinodego removed the refactor Code improvements that do not change functionality label Jan 17, 2023
@github-actions github-actions bot added the enhancement New feature or an improvement of an existing feature label Jan 17, 2023
@zundertj zundertj force-pushed the deprecate_with_column branch 3 times, most recently from 9621946 to a05308a Compare January 17, 2023 22:22
@zundertj
Copy link
Collaborator Author

Rebased & squashed.

@zundertj
Copy link
Collaborator Author

zundertj commented Jan 17, 2023

I think this is a good move!

And we don't have to remove with_column in 0.16.0, right? As it is widely used, I would suggest to just leave it in until 0.17.0.

I agree with @alexander-beedie that we should include this version information in the deprecation message, to help users schedule their upgrade.

Also, I am going to rebrand this as an 'enhancement', since this affects our public API.

I had on purpose not added in a version, because we don't know (yet). I think, given that the warnings will be annoying, people would update relatively quickly their code after the Polars upgrade, but we will have to cater to users who update Polars infrequent. So I did not want to pin us down yet on a timeline. But if there is a good idea for how long it will be until 0.16 or 0.17 land, we can put that in.

@stinodego
Copy link
Member

Fair enough. Maybe @ritchie46 can comment on this. Once we decide on what the deprecation message should be, this PR should be good to go!

@ritchie46
Copy link
Member

Just to be certain, we now accept

  • a single expression
  • a list of expressions
  • multiple expressions as args

in with_columns right?

@stinodego
Copy link
Member

stinodego commented Jan 18, 2023

Yes, that's correct! And also Series / list of Series.

@ritchie46
Copy link
Member

ritchie46 commented Jan 18, 2023

Alright. Thanks all! On the message. I think 0.17 or 0.18 seems a reasonable time duration?

@stinodego
Copy link
Member

I'd say 0.17.0 is fine, as it's still quite far away.

@zundertj zundertj force-pushed the deprecate_with_column branch 2 times, most recently from 30ee907 to 30bddf8 Compare January 19, 2023 20:58
@zundertj
Copy link
Collaborator Author

Added 0.17 to docstring and the warning.

As `with_columns` has a superset of functionality.

Remove test script

Synchronize input arg parsing between DataFrame and LazyFrame with_columns

Update py-polars/polars/internals/dataframe/frame.py

Co-authored-by: Stijn de Gooijer <stijn@degooijer.io>

Update py-polars/polars/internals/lazyframe/frame.py

Co-authored-by: Stijn de Gooijer <stijn@degooijer.io>

Update py-polars/polars/internals/dataframe/frame.py

Co-authored-by: Stijn de Gooijer <stijn@degooijer.io>

Update docstrings

Fix doctests

Revert Cargo.lock

Specify v0.17 in deprecation warnings

Fix faulty merge
@stinodego
Copy link
Member

@ritchie46 is there still some doubt or unclarity about this change?

If not, I think we should go ahead and merge this, as it's big and very prone to merge conflicts.

@ritchie46
Copy link
Member

Alright! Thanks all!

@ritchie46 ritchie46 merged commit e4c71b9 into pola-rs:master Jan 25, 2023
@timreuscher
Copy link

timreuscher commented Jan 26, 2023

Hadn't updated since 0.14.18, just installed 0.15.18, ran some code, saw the warning which made complete sense in both the warning displayed and the change it warned about, did a few search-and-replaces (I guess that's the plural) and no more warnings in less than five minutes.

Just wanted to leave my two cents as an occasional user out in the field that this is an excellent example of how to deprecate old methods. Well done!

@stinodego
Copy link
Member

Thanks! Always nice to hear some positive feedback 😸

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants