polars-upgrade icon indicating copy to clipboard operation
polars-upgrade copied to clipboard

keep_name() not getting replaced name.keep()

Open vracharya opened this issue 2 years ago • 3 comments

polars source version: 0.18.3 polars target version: 0.20.14 polars_upgrade version: 0.3.1

Instance 1: Code: df = (df.with_columns(plcs.by_dtype(pl.Null).cast(pl.Utf8).keep_name())) Expected result: df = (df.with_columns(plcs.by_dtype(pl.Null).cast(pl.Utf8).name.keep())) Actual Result: No change

Instance 2: # cols is a pl.Expr Code: return cols.keep_name() if kwargs.get('keep_name') else cols Expected result: return cols.name.keep() if kwargs.get('keep_name') else cols Actual Result: No change

vracharya avatar Mar 08 '24 17:03 vracharya

I think the second one is too risky to do statically

for the first one, did you do import polars.selectors as plcs?

MarcoGorelli avatar Mar 08 '24 19:03 MarcoGorelli

I think the second one is too risky to do statically

for the first one, did you do import polars.selectors as plcs?

Yes @ plcs.

For the second one: risky because keep_name() could be a function name being used by some other library, and there's no way to know that cols is a polars Expr?

vracharya avatar Mar 08 '24 19:03 vracharya

there's no way to know that cols is a polars Expr

that's it, polars-upgrade just does static analysis - not saying it's not possible, but it would be quite tricky without doing a more involved analysis

MarcoGorelli avatar Mar 08 '24 21:03 MarcoGorelli