Skip to content

Commit

Permalink
format empty df (#3719)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jun 17, 2022
1 parent 74081ac commit c13c42f
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
4 changes: 2 additions & 2 deletions polars/polars-arrow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ description = "Arrow interfaces for Polars DataFrame library"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
# arrow = { package = "arrow2", git = "https://github.com/jorgecarleitao/arrow2", rev = "39db6fb7514364bfea08d594793b23e1ed5a7def", features = ["compute_concatenate"], default-features = false }
arrow = { package = "arrow2", git = "https://github.com/jorgecarleitao/arrow2", rev = "d4873fcb9b201d591049055c0e554dbdd2c45ad3", features = ["compute_concatenate"], default-features = false }
# arrow = { package = "arrow2", path = "../../../arrow2", features = ["compute_concatenate"], default-features = false }
arrow = { package = "arrow2", git = "https://github.com/ritchie46/arrow2", branch = "arity_assign", features = ["compute_concatenate"], default-features = false }
# arrow = { package = "arrow2", git = "https://github.com/ritchie46/arrow2", branch = "arity_assign", features = ["compute_concatenate"], default-features = false }
# arrow = { package = "arrow2", version = "0.12", default-features = false, features = ["compute_concatenate"] }
hashbrown = "0.12"
num = "^0.4"
Expand Down
8 changes: 4 additions & 4 deletions polars/polars-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ thiserror = "^1.0"

[dependencies.arrow]
package = "arrow2"
# git = "https://github.com/jorgecarleitao/arrow2"
git = "https://github.com/ritchie46/arrow2"
# rev = "39db6fb7514364bfea08d594793b23e1ed5a7def"
git = "https://github.com/jorgecarleitao/arrow2"
# git = "https://github.com/ritchie46/arrow2"
rev = "d4873fcb9b201d591049055c0e554dbdd2c45ad3"
# path = "../../../arrow2"
branch = "arity_assign"
# branch = "arity_assign"
# version = "0.12"
default-features = false
features = [
Expand Down
4 changes: 4 additions & 0 deletions polars/polars-core/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ pub fn concat_str(s: &[Series], delimiter: &str) -> Result<Utf8Chunked> {
"expected multiple series in concat_str function".into(),
));
}
if s[0].is_empty() {
return Ok(Utf8Chunked::full_null(s[0].name(), 0));
}

let len = s.iter().map(|s| s.len()).max().unwrap();

let cas = s
Expand Down
4 changes: 2 additions & 2 deletions polars/polars-io/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ private = ["polars-time/private"]
[dependencies]
ahash = "0.7"
anyhow = "1.0"
# arrow = { package = "arrow2", git = "https://github.com/jorgecarleitao/arrow2", rev = "39db6fb7514364bfea08d594793b23e1ed5a7def", default-features = false }
arrow = { package = "arrow2", git = "https://github.com/ritchie46/arrow2", branch = "arity_assign", default-features = false }
arrow = { package = "arrow2", git = "https://github.com/jorgecarleitao/arrow2", rev = "d4873fcb9b201d591049055c0e554dbdd2c45ad3", default-features = false }
# arrow = { package = "arrow2", git = "https://github.com/ritchie46/arrow2", branch = "arity_assign", default-features = false }
# arrow = { package = "arrow2", version = "0.12", default-features = false }
# arrow = { package = "arrow2", path = "../../../arrow2", default-features = false }
csv-core = { version = "0.1.10", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion py-polars/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions py-polars/tests/test_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,18 @@ def test_ljust_and_rjust() -> None:
"ljust": ["foo ", "longer_foo", "longest_fooooooo", "hi "],
"ljust_len": [10, 10, 16, 10],
}


def test_format_empty_df() -> None:
df = pl.DataFrame(
[
pl.Series("val1", [], dtype=pl.Categorical),
pl.Series("val2", [], dtype=pl.Categorical),
]
).select(
[
pl.format("{}:{}", pl.col("val1"), pl.col("val2")).alias("cat"),
]
)
assert df.shape == (0, 1)
assert df.dtypes == [pl.Utf8]

0 comments on commit c13c42f

Please sign in to comment.