Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

In Polars, metadata can be linked to a series using the Series.retain method. This method allows you to retain metadata from a series and link it to a new series that is created with a derived transformation. For example:

import polars as pl

# Create a series with metadata
s = pl.Series([1, 2, 3], name="my_series", dtype=pl.Int64)
s.set_meta({"foo": "bar"})

# Create a derived series with metadata linked to the original series
s2 = s.retain(name="my_new_series", meta=s.get_meta())

# Print metadata for the new series
print(s2.get_meta())

In the above example, the s.retain method is used to create a new series called s2 that is a transformation of the original series s. The metadata from s is linked to s2 using the meta parameter in s2.retain.