Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego committed Jun 10, 2024
1 parent adc03ea commit 14d49cc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
28 changes: 21 additions & 7 deletions py-polars/polars/expr/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -9078,30 +9078,27 @@ 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
-------
Expr
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 │
Expand All @@ -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
--------
Expand Down
25 changes: 18 additions & 7 deletions py-polars/polars/series/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -6593,25 +6593,21 @@ 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
-------
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
--------
Expand All @@ -6620,14 +6616,29 @@ 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]]
[
[1, 2, 3]
[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))

Expand Down

0 comments on commit 14d49cc

Please sign in to comment.