Skip to content

Commit

Permalink
Fix doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
mcrumiller committed Feb 12, 2024
1 parent 54b0cf1 commit 788484f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crates/polars-ops/src/chunked_array/strings/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ pub trait StringNameSpaceImpl: AsString {
/// Slice the last `n` values of the string.
///
/// Determines a substring starting at offset `n` of each element in `array`. `n` can be
/// negative, in which case the slice begins `n` characters from the end of the string.
/// negative, in which case the slice begins `n` characters from the start of the string.
fn str_tail(&self, n: &Series) -> PolarsResult<StringChunked> {
let ca = self.as_string();
let n = n.strict_cast(&DataType::Int64)?;
Expand Down
4 changes: 4 additions & 0 deletions py-polars/polars/expr/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -2214,6 +2214,7 @@ def head(self, n: int | IntoExprColumn = 10) -> Expr:
Examples
--------
Return up to the first 5 characters:
>>> df = pl.DataFrame({"s": ["pear", None, "papaya", "dragonfruit"]})
>>> df.with_columns(pl.col("s").str.head(5).alias("s_head_5"))
shape: (4, 2)
Expand All @@ -2229,6 +2230,7 @@ def head(self, n: int | IntoExprColumn = 10) -> Expr:
└─────────────┴──────────┘
Return characters determined by column `n`:
>>> df = pl.DataFrame(
... {
... "s": ["pear", None, "papaya", "dragonfruit"],
Expand Down Expand Up @@ -2285,6 +2287,7 @@ def tail(self, n: int | IntoExprColumn = 10) -> Expr:
Examples
--------
Return up to the last 5 characters:
>>> df = pl.DataFrame({"s": ["pear", None, "papaya", "dragonfruit"]})
>>> df.with_columns(pl.col("s").str.tail(5).alias("s_tail_5"))
shape: (4, 2)
Expand All @@ -2300,6 +2303,7 @@ def tail(self, n: int | IntoExprColumn = 10) -> Expr:
└─────────────┴──────────┘
Return characters determined by column `n`:
>>> df = pl.DataFrame(
... {
... "s": ["pear", None, "papaya", "dragonfruit"],
Expand Down
12 changes: 8 additions & 4 deletions py-polars/polars/series/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,7 @@ def head(self, n: int | IntoExprColumn = 10) -> Series:
Returns
-------
Expr
Series
Series of data type :class:`String`.
Notes
Expand All @@ -1670,6 +1670,7 @@ def head(self, n: int | IntoExprColumn = 10) -> Series:
Examples
--------
Return up to the first 5 characters.
>>> s = pl.Series(["pear", None, "papaya", "dragonfruit"])
>>> s.str.head(5)
shape: (4,)
Expand All @@ -1682,6 +1683,7 @@ def head(self, n: int | IntoExprColumn = 10) -> Series:
]
Return up to the 3rd character from the end.
>>> s = pl.Series(["pear", None, "papaya", "dragonfruit"])
>>> s.str.head(-3)
shape: (4,)
Expand All @@ -1706,7 +1708,7 @@ def tail(self, n: int | IntoExprColumn = 10) -> Series:
Returns
-------
Expr
Series
Series of data type :class:`String`.
Notes
Expand All @@ -1727,7 +1729,8 @@ def tail(self, n: int | IntoExprColumn = 10) -> Series:
Examples
--------
Return up to the last 5 characters.
Return up to the last 5 characters:
>>> s = pl.Series(["pear", None, "papaya", "dragonfruit"])
>>> s.str.tail(5)
shape: (4,)
Expand All @@ -1739,7 +1742,8 @@ def tail(self, n: int | IntoExprColumn = 10) -> Series:
"fruit"
]
Return from the 3rd character to the end.
Return from the 3rd character to the end:
>>> s = pl.Series(["pear", None, "papaya", "dragonfruit"])
>>> s.str.tail(-3)
shape: (4,)
Expand Down

0 comments on commit 788484f

Please sign in to comment.