Skip to content

Commit

Permalink
More delimiter to sep (#1426)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghuls committed Sep 23, 2021
1 parent ddd46fe commit e0d1da1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions polars/polars-lazy/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ pub fn argsort_by(by: Vec<Expr>, reverse: &[bool]) -> Expr {
#[cfg(feature = "concat_str")]
#[cfg_attr(docsrs, doc(cfg(feature = "concat_str")))]
/// Concat string columns in linear time
pub fn concat_str(s: Vec<Expr>, delimiter: &str) -> Expr {
let delimiter = delimiter.to_string();
pub fn concat_str(s: Vec<Expr>, sep: &str) -> Expr {
let sep = sep.to_string();
let function = NoEq::new(Arc::new(move |s: &mut [Series]| {
polars_core::functions::concat_str(s, &delimiter).map(|ca| ca.into_series())
polars_core::functions::concat_str(s, &sep).map(|ca| ca.into_series())
}) as Arc<dyn SeriesUdf>);
Expr::Function {
input: s,
Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/eager/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ def to_csv(
>>> "bar": [6, 7, 8, 9, 10],
>>> "ham": ['a', 'b', 'c', 'd','e']
>>> })
>>> df.to_csv('new_file.csv', delimiter=',')
>>> df.to_csv('new_file.csv', sep=',')
"""
if file is None:
Expand Down
8 changes: 4 additions & 4 deletions py-polars/polars/lazy/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,22 +624,22 @@ def argsort_by(
return pl.lazy.expr.wrap_expr(pyargsort_by(exprs, reverse))


def concat_str(exprs: tp.List["pl.Expr"], delimiter: str = "") -> "pl.Expr":
def concat_str(exprs: tp.List["pl.Expr"], sep: str = "") -> "pl.Expr":
"""
Concat Utf8 Series in linear time. Non utf8 columns are cast to utf8.
Parameters
----------
exprs
Columns to concat into a Utf8 Series
delimiter
sep
String value that will be used to separate the values.
"""
exprs = pl.lazy.expr._selection_to_pyexpr_list(exprs)
return pl.lazy.expr.wrap_expr(_concat_str(exprs, delimiter))
return pl.lazy.expr.wrap_expr(_concat_str(exprs, sep))


def concat_list(exprs: tp.List["pl.Expr"], delimiter: str = "") -> "pl.Expr":
def concat_list(exprs: tp.List["pl.Expr"]) -> "pl.Expr":
"""
Concat the arrays in a Series dtype List in linear time.
Expand Down
4 changes: 2 additions & 2 deletions py-polars/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ fn toggle_string_cache(toggle: bool) {
}

#[pyfunction]
fn concat_str(s: Vec<dsl::PyExpr>, delimiter: &str) -> dsl::PyExpr {
fn concat_str(s: Vec<dsl::PyExpr>, sep: &str) -> dsl::PyExpr {
let s = s.into_iter().map(|e| e.inner).collect();
polars::lazy::functions::concat_str(s, delimiter).into()
polars::lazy::functions::concat_str(s, sep).into()
}

#[pyfunction]
Expand Down
2 changes: 1 addition & 1 deletion py-polars/tests/test_lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def test_window_deadlock():
def test_concat_str():
df = pl.DataFrame({"a": ["a", "b", "c"], "b": [1, 2, 3]})

out = df[[pl.concat_str(["a", "b"], delimiter="-")]]
out = df[[pl.concat_str(["a", "b"], sep="-")]]
assert out["a"] == ["a-1", "a-2", "a-3"]


Expand Down

0 comments on commit e0d1da1

Please sign in to comment.