diff options
Diffstat (limited to 'venv/lib/python3.8/site-packages/narwhals/series_struct.py')
-rw-r--r-- | venv/lib/python3.8/site-packages/narwhals/series_struct.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/venv/lib/python3.8/site-packages/narwhals/series_struct.py b/venv/lib/python3.8/site-packages/narwhals/series_struct.py new file mode 100644 index 0000000..6f92e7b --- /dev/null +++ b/venv/lib/python3.8/site-packages/narwhals/series_struct.py @@ -0,0 +1,33 @@ +from __future__ import annotations + +from typing import Generic + +from narwhals.typing import SeriesT + + +class SeriesStructNamespace(Generic[SeriesT]): + def __init__(self, series: SeriesT) -> None: + self._narwhals_series = series + + def field(self, name: str) -> SeriesT: + r"""Retrieve a Struct field as a new expression. + + Arguments: + name: Name of the struct field to retrieve. + + Returns: + A new Series. + + Examples: + >>> import polars as pl + >>> import narwhals as nw + >>> s_native = pl.Series( + ... [{"id": "0", "name": "john"}, {"id": "1", "name": "jane"}] + ... ) + >>> s = nw.from_native(s_native, series_only=True) + >>> s.struct.field("name").to_list() + ['john', 'jane'] + """ + return self._narwhals_series._with_compliant( + self._narwhals_series._compliant_series.struct.field(name) + ) |