From fc8346c3d50db359402e666d73a54392275a4b4b Mon Sep 17 00:00:00 2001 From: cmdlineluser <99486669+cmdlineluser@users.noreply.github.com> Date: Mon, 31 Jul 2023 20:29:26 +0100 Subject: [PATCH] update examples --- py-polars/polars/expr/string.py | 29 +++++++++++++++-------------- py-polars/polars/series/string.py | 10 +++++----- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/py-polars/polars/expr/string.py b/py-polars/polars/expr/string.py index 7c77f514e683..3493a7ef6bec 100644 --- a/py-polars/polars/expr/string.py +++ b/py-polars/polars/expr/string.py @@ -1289,24 +1289,25 @@ def extract_groups(self, pattern: str) -> Expr: ... data={ ... "url": [ ... "http://vote.com/ballon_dor?candidate=messi&ref=python", - ... "http://vote.com/ballon_dor?candidate=haaland&ref=polars", + ... "http://vote.com/ballon_dor?candidate=weghorst&ref=polars", ... "http://vote.com/ballon_dor?error=404&ref=rust", ... ] ... } ... ) - >>> df.select( - ... captures = pl.col("url").str.extract_groups(r"candidate=(?\w+)&ref=(?\w+)") - ... ).unnest("captures") - shape: (3, 3) - ┌──────────────────────────────┬───────────┬────────┐ - │ 0 ┆ candidate ┆ ref │ - │ --- ┆ --- ┆ --- │ - │ str ┆ str ┆ str │ - ╞══════════════════════════════╪═══════════╪════════╡ - │ candidate=messi&ref=python ┆ messi ┆ python │ - │ candidate=haaland&ref=polars ┆ haaland ┆ polars │ - │ null ┆ null ┆ null │ - └──────────────────────────────┴───────────┴────────┘ + >>> pattern = r"candidate=(?\w+)&ref=(?\w+)" + >>> df.select(captures=pl.col("url").str.extract_groups(pattern)).unnest( + ... "captures" + ... ) + shape: (3, 2) + ┌───────────┬────────┐ + │ candidate ┆ ref │ + │ --- ┆ --- │ + │ str ┆ str │ + ╞═══════════╪════════╡ + │ messi ┆ python │ + │ weghorst ┆ polars │ + │ null ┆ null │ + └───────────┴────────┘ """ return wrap_expr(self._pyexpr.str_extract_groups(pattern)) diff --git a/py-polars/polars/series/string.py b/py-polars/polars/series/string.py index 6fd544a021c8..7f3e1740ff07 100644 --- a/py-polars/polars/series/string.py +++ b/py-polars/polars/series/string.py @@ -791,17 +791,17 @@ def extract_groups(self, pattern: str) -> Series: ... name="url", ... values=[ ... "http://vote.com/ballon_dor?candidate=messi&ref=python", - ... "http://vote.com/ballon_dor?candidate=haaland&ref=polars", + ... "http://vote.com/ballon_dor?candidate=weghorst&ref=polars", ... "http://vote.com/ballon_dor?error=404&ref=rust", ... ], ... ) >>> s.str.extract_groups(r"candidate=(?\w+)&ref=(?\w+)") shape: (3,) - Series: 'url' [struct[3]] + Series: 'url' [struct[2]] [ - {"candidate=messi&ref=python","messi","python"} - {"candidate=haaland&ref=polars","haaland","polars"} - {null,null,null} + {"messi","python"} + {"weghorst","polars"} + {null,null} ] """