Skip to content

Commit 26b91c4

Browse files
committed
lint and docs
1 parent 720e309 commit 26b91c4

File tree

4 files changed

+17
-22
lines changed

4 files changed

+17
-22
lines changed

doc/source/user_guide/reshaping.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -804,12 +804,12 @@ Note to subdivide over multiple columns we can pass in a list to the
804804
805805
.. _reshaping.explode:
806806

807-
Exploding a List-like Column
807+
Exploding a list-like column
808808
----------------------------
809809

810810
.. versionadded:: 0.25.0
811811

812-
Sometimes the value column is list-like.
812+
Sometimes the values in a column are list-like.
813813

814814
.. ipython:: python
815815
@@ -818,7 +818,7 @@ Sometimes the value column is list-like.
818818
df = pd.DataFrame({'keys': keys, 'values': values})
819819
df
820820
821-
We can 'explode' this transforming each element of a list-like to a row, by using :meth:`~Series.explode`. This will replicate the index values:
821+
We can 'explode' the ``values`` column, transforming each list-like to a separate row, by using :meth:`~Series.explode`. This will replicate the index values from the original row:
822822

823823
.. ipython:: python
824824

pandas/_libs/lib.pyx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -932,15 +932,12 @@ def is_list_like(obj: object, allow_sets: bool = True):
932932
cdef inline bint c_is_list_like(object obj, bint allow_sets):
933933
return (
934934
isinstance(obj, abc.Iterable)
935-
and
936935
# we do not count strings/unicode/bytes as list-like
937-
not isinstance(obj, (str, bytes))
938-
and
936+
and not isinstance(obj, (str, bytes))
939937
# exclude zero-dimensional numpy arrays, effectively scalars
940-
not (util.is_array(obj) and obj.ndim == 0)
941-
and
938+
and not (util.is_array(obj) and obj.ndim == 0)
942939
# exclude sets if allow_sets is False
943-
not (allow_sets is False and isinstance(obj, abc.Set))
940+
and not (allow_sets is False and isinstance(obj, abc.Set))
944941
)
945942

946943

pandas/core/frame.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import itertools
1616
import sys
1717
from textwrap import dedent
18-
from typing import FrozenSet, Iterable, List, Optional, Set, Type, Union
18+
from typing import FrozenSet, List, Optional, Set, Type, Union
1919
import warnings
2020

2121
import numpy as np
@@ -6239,7 +6239,8 @@ def stack(self, level=-1, dropna=True):
62396239

62406240
def explode(self, column: str) -> "DataFrame":
62416241
"""
6242-
Create new DataFrame expanding a specified list-like column.
6242+
Transforms each element of a list-like to a row, replicating the
6243+
index values.
62436244
62446245
.. versionadded:: 0.25.0
62456246
@@ -6268,10 +6269,9 @@ def explode(self, column: str) -> "DataFrame":
62686269
Notes
62696270
-----
62706271
This routine will explode list-likes including lists, tuples,
6271-
Series, and np.ndarray.
6272-
The result dtype of the subset rows will be object.
6273-
Scalars will be returned unchanged.
6274-
Empty list-likes will result in a np.nan for that row.
6272+
Series, and np.ndarray. The result dtype of the subset rows will
6273+
be object. Scalars will be returned unchanged. Empty list-likes will
6274+
result in a np.nan for that row.
62756275
62766276
Examples
62776277
--------
@@ -6292,7 +6292,6 @@ def explode(self, column: str) -> "DataFrame":
62926292
2 NaN 1
62936293
3 3 1
62946294
3 4 1
6295-
62966295
"""
62976296

62986297
if not is_scalar(column):

pandas/core/series.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3638,7 +3638,8 @@ def reorder_levels(self, order):
36383638

36393639
def explode(self) -> "Series":
36403640
"""
3641-
Create new Series expanding a list-like column.
3641+
Transforms each element of a list-like to a row, replicating the
3642+
index values.
36423643
36433644
.. versionadded:: 0.25.0
36443645
@@ -3659,10 +3660,9 @@ def explode(self) -> "Series":
36593660
Notes
36603661
-----
36613662
This routine will explode list-likes including lists, tuples,
3662-
Series, and np.ndarray.
3663-
The result dtype of the returned Series will always be object.
3664-
Scalars will be returned unchanged.
3665-
Empty list-likes will result in a np.nan for that row.
3663+
Series, and np.ndarray. The result dtype of the subset rows will
3664+
be object. Scalars will be returned unchanged. Empty list-likes will
3665+
result in a np.nan for that row.
36663666
36673667
Examples
36683668
--------
@@ -3683,7 +3683,6 @@ def explode(self) -> "Series":
36833683
3 3
36843684
3 4
36853685
dtype: object
3686-
36873686
"""
36883687
if not len(self) or not is_object_dtype(self):
36893688
return self.copy()

0 commit comments

Comments
 (0)