pola-rs / polars

Dataframes powered by a multithreaded, vectorized query engine, written in Rust
https://docs.pola.rs
Other
29.13k stars 1.83k forks source link

Rename: Support for ignore_missing parameter #17821

Open raayu83 opened 1 month ago

raayu83 commented 1 month ago

Description

For people who work with column name mappings it would be very useful if there was an option to ignore missing columns on df.rename().

Currently the following fails because some columns in mappings don't exist in the DataFrame:

import polars as pl

mappings = {
    'Hello': 'hello',
    'Goodbye': 'goodbye'
}

df = pl.DataFrame({'Hello': 'World'}).rename(mappings)

Currently you first have to manually remove columns that don't exist in the df from the mappings.

For such usecases, it would be much nicer if there was an ignore_missing Parameter to rename, which defaults to False (mirroring the current behaviour).

etiennebacher commented 1 month ago

No idea if they want to implement this, but if so it should probably be named strict (default to True) as for .drop() (https://github.com/pola-rs/polars/pull/17044).