Skip to content

Commit

Permalink
fix(rust, python): Add list inner dtype when printing Series (#6233)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghuls authored Jan 15, 2023
1 parent 6a1d8bf commit a445cfc
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 16 deletions.
5 changes: 3 additions & 2 deletions polars/polars-core/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ impl Debug for Series {
format_array!(f, self.duration().unwrap(), &dt, self.name(), "Series")
}
DataType::List(_) => {
format_array!(f, self.list().unwrap(), "list", self.name(), "Series")
let dt = format!("{}", self.dtype());
format_array!(f, self.list().unwrap(), &dt, self.name(), "Series")
}
#[cfg(feature = "object")]
DataType::Object(_) => format_object_array(f, self, self.name(), "Series"),
Expand Down Expand Up @@ -940,7 +941,7 @@ mod test {

assert_eq!(
r#"shape: (2,)
Series: 'a' [list]
Series: 'a' [list[i32]]
[
[1, 2, 3]
null
Expand Down
10 changes: 5 additions & 5 deletions py-polars/polars/internals/expr/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def diff(self, n: int = 1, null_behavior: NullBehavior = "ignore") -> pli.Expr:
>>> s = pl.Series("a", [[1, 2, 3, 4], [10, 2, 1]])
>>> s.arr.diff()
shape: (2,)
Series: 'a' [list]
Series: 'a' [list[i64]]
[
[null, 1, ... 1]
[null, -8, -1]
Expand All @@ -512,7 +512,7 @@ def shift(self, periods: int = 1) -> pli.Expr:
>>> s = pl.Series("a", [[1, 2, 3, 4], [10, 2, 1]])
>>> s.arr.shift()
shape: (2,)
Series: 'a' [list]
Series: 'a' [list[i64]]
[
[null, 1, ... 3]
[null, 10, 2]
Expand Down Expand Up @@ -540,7 +540,7 @@ def slice(
>>> s = pl.Series("a", [[1, 2, 3, 4], [10, 2, 1]])
>>> s.arr.slice(1, 2)
shape: (2,)
Series: 'a' [list]
Series: 'a' [list[i64]]
[
[2, 3]
[2, 1]
Expand All @@ -565,7 +565,7 @@ def head(self, n: int | str | pli.Expr = 5) -> pli.Expr:
>>> s = pl.Series("a", [[1, 2, 3, 4], [10, 2, 1]])
>>> s.arr.head(2)
shape: (2,)
Series: 'a' [list]
Series: 'a' [list[i64]]
[
[1, 2]
[10, 2]
Expand All @@ -588,7 +588,7 @@ def tail(self, n: int | str | pli.Expr = 5) -> pli.Expr:
>>> s = pl.Series("a", [[1, 2, 3, 4], [10, 2, 1]])
>>> s.arr.tail(2)
shape: (2,)
Series: 'a' [list]
Series: 'a' [list[i64]]
[
[3, 4]
[2, 1]
Expand Down
10 changes: 5 additions & 5 deletions py-polars/polars/internals/series/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def diff(self, n: int = 1, null_behavior: NullBehavior = "ignore") -> pli.Series
>>> s = pl.Series("a", [[1, 2, 3, 4], [10, 2, 1]])
>>> s.arr.diff()
shape: (2,)
Series: 'a' [list]
Series: 'a' [list[i64]]
[
[null, 1, ... 1]
[null, -8, -1]
Expand All @@ -215,7 +215,7 @@ def shift(self, periods: int = 1) -> pli.Series:
>>> s = pl.Series("a", [[1, 2, 3, 4], [10, 2, 1]])
>>> s.arr.shift()
shape: (2,)
Series: 'a' [list]
Series: 'a' [list[i64]]
[
[null, 1, ... 3]
[null, 10, 2]
Expand All @@ -240,7 +240,7 @@ def slice(self, offset: int, length: int | None = None) -> pli.Series:
>>> s = pl.Series("a", [[1, 2, 3, 4], [10, 2, 1]])
>>> s.arr.slice(1, 2)
shape: (2,)
Series: 'a' [list]
Series: 'a' [list[i64]]
[
[2, 3]
[2, 1]
Expand All @@ -262,7 +262,7 @@ def head(self, n: int = 5) -> pli.Series:
>>> s = pl.Series("a", [[1, 2, 3, 4], [10, 2, 1]])
>>> s.arr.head(2)
shape: (2,)
Series: 'a' [list]
Series: 'a' [list[i64]]
[
[1, 2]
[10, 2]
Expand All @@ -284,7 +284,7 @@ def tail(self, n: int = 5) -> pli.Series:
>>> s = pl.Series("a", [[1, 2, 3, 4], [10, 2, 1]])
>>> s.arr.tail(2)
shape: (2,)
Series: 'a' [list]
Series: 'a' [list[i64]]
[
[3, 4]
[2, 1]
Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/internals/series/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2351,7 +2351,7 @@ def is_in(self, other: Series | Sequence[Any]) -> Series:
>>> optional_members = pl.Series("optional_members", [1, 2, 3])
>>> print(sets)
shape: (3,)
Series: 'sets' [list]
Series: 'sets' [list[i64]]
[
[1, 2, 3]
[1, 2]
Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/internals/series/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def extract_all(self, pattern: str | pli.Series) -> pli.Series:
>>> s = pl.Series("foo", ["123 bla 45 asd", "xyz 678 910t"])
>>> s.str.extract_all(r"(\d+)")
shape: (2,)
Series: 'foo' [list]
Series: 'foo' [list[str]]
[
["123", "45"]
["678", "910"]
Expand Down
2 changes: 1 addition & 1 deletion py-polars/tests/unit/io/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_date_list_fmt() -> None:
assert (
str(df.groupby("index", maintain_order=True).agg(pl.col("mydate"))["mydate"])
== """shape: (3,)
Series: 'mydate' [list]
Series: 'mydate' [list[date]]
[
[2020-01-01]
[2020-01-02]
Expand Down
2 changes: 1 addition & 1 deletion py-polars/tests/unit/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -1664,7 +1664,7 @@ def test_groupby_cat_list() -> None:
assert (
str(grouped)
== """shape: (3,)
Series: 'cat_column' [list]
Series: 'cat_column' [list[cat]]
[
["a", "b"]
["b", "a"]
Expand Down

0 comments on commit a445cfc

Please sign in to comment.