Skip to content

Commit 694e453

Browse files
committed
lint and docs
1 parent cf48c83 commit 694e453

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
@@ -6235,7 +6235,8 @@ def stack(self, level=-1, dropna=True):
62356235

62366236
def explode(self, column: str) -> "DataFrame":
62376237
"""
6238-
Create new DataFrame expanding a specified list-like column.
6238+
Transforms each element of a list-like to a row, replicating the
6239+
index values.
62396240
62406241
.. versionadded:: 0.25.0
62416242
@@ -6264,10 +6265,9 @@ def explode(self, column: str) -> "DataFrame":
62646265
Notes
62656266
-----
62666267
This routine will explode list-likes including lists, tuples,
6267-
Series, and np.ndarray.
6268-
The result dtype of the subset rows will be object.
6269-
Scalars will be returned unchanged.
6270-
Empty list-likes will result in a np.nan for that row.
6268+
Series, and np.ndarray. The result dtype of the subset rows will
6269+
be object. Scalars will be returned unchanged. Empty list-likes will
6270+
result in a np.nan for that row.
62716271
62726272
Examples
62736273
--------
@@ -6288,7 +6288,6 @@ def explode(self, column: str) -> "DataFrame":
62886288
2 NaN 1
62896289
3 3 1
62906290
3 4 1
6291-
62926291
"""
62936292

62946293
if not is_scalar(column):

pandas/core/series.py

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

36353635
def explode(self) -> "Series":
36363636
"""
3637-
Create new Series expanding a list-like column.
3637+
Transforms each element of a list-like to a row, replicating the
3638+
index values.
36383639
36393640
.. versionadded:: 0.25.0
36403641
@@ -3655,10 +3656,9 @@ def explode(self) -> "Series":
36553656
Notes
36563657
-----
36573658
This routine will explode list-likes including lists, tuples,
3658-
Series, and np.ndarray.
3659-
The result dtype of the returned Series will always be object.
3660-
Scalars will be returned unchanged.
3661-
Empty list-likes will result in a np.nan for that row.
3659+
Series, and np.ndarray. The result dtype of the subset rows will
3660+
be object. Scalars will be returned unchanged. Empty list-likes will
3661+
result in a np.nan for that row.
36623662
36633663
Examples
36643664
--------
@@ -3679,7 +3679,6 @@ def explode(self) -> "Series":
36793679
3 3
36803680
3 4
36813681
dtype: object
3682-
36833682
"""
36843683
if not len(self) or not is_object_dtype(self):
36853684
return self.copy()

0 commit comments

Comments
 (0)