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): add map_dict method for Series #6946

Merged
merged 2 commits into from
Feb 17, 2023

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Feb 16, 2023

Expose the useful new map_dict functionality on Series (via @expr_dispatch):

import polars as pl

country_lookup = {
    "JPN": "Japan",
    "FRA": "France",
    "NLD": "Netherlands",
}
s = pl.Series("iso3166", ["FRA", "???", "JPN", "NLD"])

s.map_dict(
    country_lookup, 
    default = s,
).rename("country_name")

# shape: (4,)
# Series: 'country_name' [str]
# [
#     "France"
#     "???"
#     "Japan"
#     "Netherlands"
# ]

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars labels Feb 16, 2023
@ritchie46
Copy link
Member

Thanks! Docs entry?😊

@alexander-beedie
Copy link
Collaborator Author

Thanks! Docs entry?😊

Lol... my kryptonite; had realised and was adding it as you typed 🤣

@ritchie46 ritchie46 merged commit c5d1b8e into pola-rs:master Feb 17, 2023
@alexander-beedie alexander-beedie deleted the series-map-dict branch February 18, 2023 18:42
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.

2 participants