Skip to content

Column rename does not update schema and subsequent operations fail #22779

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

Open
2 tasks done
tobisinghania opened this issue May 16, 2025 · 0 comments
Open
2 tasks done
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer rust Related to Rust Polars

Comments

@tobisinghania
Copy link

Checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of Polars.

Reproducible example

  #[test]
    fn polars_rename_error() -> Result<(), Box<dyn Error>> {
        let mut left = df! { "col1" => [1,2,3,4,5]}?;
        let mut right = df! { "col1" => [1,2,3,4,5]}?;

        right.rename("col1", "col1_right".into())?;

        println!("{:?}", right.schema()); // <--- this shows "col1" instead of "col1_right"

        let res = left
            .lazy()
            .join(
                right.lazy(),
                ["col1".into()],
                ["col1_right".into()],
                JoinArgs::default()
            )
            .collect()
            .unwrap(); // <-- this fails with a ColumnNotFound error
        Ok(())
    }

Log output

Schema:
name: col1, field: Int32

thread 'tests::polars_rename_error' panicked at src/main.rs:81:14:
called `Result::unwrap()` on an `Err` value: ColumnNotFound(ErrString("col1_right\n\nResolved plan until failure:\n\n\t---> FAILED HERE RESOLVING 'sink' <---\nDF [\"col1\"]; PROJECT */1 COLUMNS"))

Issue description

When renaming a column in a dataframe, it seems the schema does not get updated accordingly and subsequent operations, like the Join operation in the provided example fail.
The example uses the lazy api for joining, but the issue exists when joining with the non-lazy api as well.

When I serialze the frame to parquet it seems to get serialized correctly and if I re-read it from the serialized format before using it in the join operation, the join succeeds.

This might be a duplicate of #20407.

Expected behavior

Renaming a column should update the schema and subsequent operations should be able to assume, that the new column name exists.

Installed versions

polars = { version = "0.47.1", features = ["dtype-full", "lazy"] }

@tobisinghania tobisinghania added bug Something isn't working rust Related to Rust Polars needs triage Awaiting prioritization by a maintainer labels May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer rust Related to Rust Polars
Projects
None yet
Development

No branches or pull requests

1 participant