Skip to content

Commit

Permalink
fix n arg in split_exact (#2879)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Mar 11, 2022
1 parent 255fb9a commit 64be773
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions polars/polars-lazy/src/dsl/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl StringNameSpace {
let function = move |s: Series| {
let ca = s.utf8()?;

let mut arrs = (0..n)
let mut arrs = (0..n + 1)
.map(|_| MutableUtf8Array::<i64>::with_capacity(ca.len()))
.collect::<Vec<_>>();

Expand Down Expand Up @@ -151,7 +151,7 @@ impl StringNameSpace {
.map(
function,
GetOutput::from_type(DataType::Struct(
(0..n)
(0..n + 1)
.map(|i| Field::new(&format!("field_{i}"), DataType::Utf8))
.collect(),
)),
Expand All @@ -165,7 +165,7 @@ impl StringNameSpace {
let function = move |s: Series| {
let ca = s.utf8()?;

let mut arrs = (0..n)
let mut arrs = (0..n + 1)
.map(|_| MutableUtf8Array::<i64>::with_capacity(ca.len()))
.collect::<Vec<_>>();

Expand Down Expand Up @@ -200,7 +200,7 @@ impl StringNameSpace {
.map(
function,
GetOutput::from_type(DataType::Struct(
(0..n)
(0..n + 1)
.map(|i| Field::new(&format!("field_{i}"), DataType::Utf8))
.collect(),
)),
Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/internals/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3609,7 +3609,7 @@ def split_exact(self, by: str, n: int, inclusive: bool = False) -> Expr:
>>> (
... pl.DataFrame({"x": ["a_1", None, "c", "d_4"]}).select(
... [
... pl.col("x").str.split_exact("_", 2).alias("fields"),
... pl.col("x").str.split_exact("_", 1).alias("fields"),
... ]
... )
... )
Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/internals/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3890,7 +3890,7 @@ def split_exact(self, by: str, n: int, inclusive: bool = False) -> Series:
>>> (
... pl.DataFrame({"x": ["a_1", None, "c", "d_4"]}).select(
... [
... pl.col("x").str.split_exact("_", 2).alias("fields"),
... pl.col("x").str.split_exact("_", 1).alias("fields"),
... ]
... )
... )
Expand Down
4 changes: 2 additions & 2 deletions py-polars/tests/test_exprs.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def test_wildcard_expansion() -> None:

def test_split_exact() -> None:
df = pl.DataFrame(dict(x=["a_a", None, "b", "c_c"]))
out = df.select([pl.col("x").str.split_exact("_", 3, inclusive=False)]).unnest("x")
out = df.select([pl.col("x").str.split_exact("_", 2, inclusive=False)]).unnest("x")

expected = pl.DataFrame(
{
Expand All @@ -138,7 +138,7 @@ def test_split_exact() -> None:

assert out.frame_equal(expected)

out = df.select([pl.col("x").str.split_exact("_", 2, inclusive=True)]).unnest("x")
out = df.select([pl.col("x").str.split_exact("_", 1, inclusive=True)]).unnest("x")

expected = pl.DataFrame(
{"field_0": ["a_", None, "b", "c_"], "field_1": ["a", None, None, "c"]}
Expand Down

0 comments on commit 64be773

Please sign in to comment.