Skip to content

Commit

Permalink
Added StringCache Python API example (#3659)
Browse files Browse the repository at this point in the history
  • Loading branch information
cnpryer committed Jun 11, 2022
1 parent ef4d7fc commit 0c30f86
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions py-polars/polars/string_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ class StringCache:
"""
Context manager that allows data sources to share the same categorical features.
This will temporarily cache the string categories until the context manager is finished.
>>> df = pl.DataFrame(
... {
... "a_col": ["red", "green", "blue"],
... "b_col": ["yellow", "orange", "black"],
... }
... )
>>> with pl.StringCache():
... df = df.with_columns(
... [
... pl.col("a_col").cast(pl.Categorical).alias("a_col"),
... pl.col("b_col").cast(pl.Categorical).alias("b_col"),
... ]
... )
...
"""

def __init__(self) -> None:
Expand Down

0 comments on commit 0c30f86

Please sign in to comment.