Skip to content

Commit

Permalink
Minor formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego committed Aug 3, 2023
1 parent 313b51b commit b17a4f7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
33 changes: 17 additions & 16 deletions py-polars/polars/expr/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -1274,22 +1274,22 @@ def extract_groups(self, pattern: str) -> Expr:
If your pattern contains unnamed groups, their numerical position is converted
to a string.
For example, here we access groups 2 and 3 via the names `"2"` and `"3"`.
>>> df = pl.DataFrame({"col": ["foo bar baz"]})
>>> (
... df.with_columns(
... pl.col("col").str.extract_groups(r"(\S+) (\S+) (.+)")
... ).select(pl.col("col").struct["2"], pl.col("col").struct["3"])
... )
shape: (1, 2)
┌─────┬─────┐
│ 2 ┆ 3 │
│ --- ┆ --- │
│ str ┆ str │
╞═════╪═════╡
│ bar ┆ baz │
└─────┴─────┘
For example, here we access groups 2 and 3 via the names `"2"` and `"3"`::
>>> df = pl.DataFrame({"col": ["foo bar baz"]})
>>> (
... df.with_columns(
... pl.col("col").str.extract_groups(r"(\S+) (\S+) (.+)")
... ).select(pl.col("col").struct["2"], pl.col("col").struct["3"])
... )
shape: (1, 2)
┌─────┬─────┐
│ 2 ┆ 3 │
│ --- ┆ --- │
│ str ┆ str │
╞═════╪═════╡
│ bar ┆ baz │
└─────┴─────┘
Returns
-------
Expand Down Expand Up @@ -1324,6 +1324,7 @@ def extract_groups(self, pattern: str) -> Expr:
└───────────┴────────┘
Unnamed groups have their numerical position converted to a string:
>>> pattern = r"candidate=(\w+)&ref=(\w+)"
>>> (
... df.with_columns(
Expand Down
24 changes: 12 additions & 12 deletions py-polars/polars/series/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,18 +787,18 @@ def extract_groups(self, pattern: str) -> Series:
If your pattern contains unnamed groups, their numerical position is converted
to a string.
For example, we can access the first group via the string `"1"`
>>> (
... pl.Series(["foo bar baz"])
... .str.extract_groups(r"(\w+) (.+) (\w+)")
... .struct["1"]
... )
shape: (1,)
Series: '1' [str]
[
"foo"
]
For example, we can access the first group via the string `"1"`::
>>> (
... pl.Series(["foo bar baz"])
... .str.extract_groups(r"(\w+) (.+) (\w+)")
... .struct["1"]
... )
shape: (1,)
Series: '1' [str]
[
"foo"
]
Returns
-------
Expand Down

0 comments on commit b17a4f7

Please sign in to comment.