diff --git a/py-polars/polars/expr/expr.py b/py-polars/polars/expr/expr.py index b34e4f00d66e..954d6cbf1c80 100644 --- a/py-polars/polars/expr/expr.py +++ b/py-polars/polars/expr/expr.py @@ -9078,16 +9078,13 @@ def radians(self) -> Self: def reshape(self, dimensions: tuple[int, ...]) -> Self: """ - Reshape this Expr to a flat Series or an Array Series. + Reshape this Expr to a flat column or an Array column. Parameters ---------- dimensions Tuple of the dimension sizes. If a -1 is used in any of the dimensions, that dimension is inferred. - nested_type - The nested data type to create. List only supports 2 dimension, - whereas Array supports an arbitrary number of dimensions. Returns ------- @@ -9095,13 +9092,13 @@ def reshape(self, dimensions: tuple[int, ...]) -> Self: If a single dimension is given, results in an expression of the original data type. If a multiple dimensions are given, results in an expression of data type - :class:`List` with shape (rows, cols) - or :class:`Array` with shape `dimensions`. + :class:`Array` with shape `dimensions`. Examples -------- >>> df = pl.DataFrame({"foo": [1, 2, 3, 4, 5, 6, 7, 8, 9]}) - >>> df.select(pl.col("foo").reshape((3, 3))) + >>> square = df.select(pl.col("foo").reshape((3, 3))) + >>> square shape: (3, 1) ┌───────────────┐ │ foo │ @@ -9112,6 +9109,23 @@ def reshape(self, dimensions: tuple[int, ...]) -> Self: │ [4, 5, 6] │ │ [7, 8, 9] │ └───────────────┘ + >>> square.select(pl.col("foo").reshape((9,))) + shape: (9, 1) + ┌─────┐ + │ foo │ + │ --- │ + │ i64 │ + ╞═════╡ + │ 1 │ + │ 2 │ + │ 3 │ + │ 4 │ + │ 5 │ + │ 6 │ + │ 7 │ + │ 8 │ + │ 9 │ + └─────┘ See Also -------- diff --git a/py-polars/polars/series/series.py b/py-polars/polars/series/series.py index d45d41c5b964..fcd839740165 100644 --- a/py-polars/polars/series/series.py +++ b/py-polars/polars/series/series.py @@ -6593,16 +6593,13 @@ def replace( def reshape(self, dimensions: tuple[int, ...]) -> Series: """ - Reshape this Series to a flat Series or a Series of Lists. + Reshape this Series to a flat Series or an Array Series. Parameters ---------- dimensions Tuple of the dimension sizes. If a -1 is used in any of the dimensions, that dimension is inferred. - nested_type - The nested data type to create. List only supports 2 dimension, - whereas Array supports an arbitrary number of dimensions. Returns ------- @@ -6610,8 +6607,7 @@ def reshape(self, dimensions: tuple[int, ...]) -> Series: If a single dimension is given, results in a Series of the original data type. If a multiple dimensions are given, results in a Series of data type - :class:`List` with shape (rows, cols) - or :class:`Array` with shape `dimensions`. + :class:`Array` with shape `dimensions`. See Also -------- @@ -6620,7 +6616,8 @@ def reshape(self, dimensions: tuple[int, ...]) -> Series: Examples -------- >>> s = pl.Series("foo", [1, 2, 3, 4, 5, 6, 7, 8, 9]) - >>> s.reshape((3, 3)) + >>> square = s.reshape((3, 3)) + >>> square shape: (3,) Series: 'foo' [array[i64, 3]] [ @@ -6628,6 +6625,20 @@ def reshape(self, dimensions: tuple[int, ...]) -> Series: [4, 5, 6] [7, 8, 9] ] + >>> square.reshape((9,)) + shape: (9,) + Series: 'foo' [i64] + [ + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + ] """ return self._from_pyseries(self._s.reshape(dimensions))