Skip to content

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

Closed
@tobisinghania

Description

@tobisinghania

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"] }

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingneeds triageAwaiting prioritization by a maintainerrustRelated to Rust Polars

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions