Skip to content

Commit 8e584a4

Browse files
use mask
1 parent c700144 commit 8e584a4

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

pandas/core/strings/accessor.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -277,19 +277,13 @@ def _wrap_result(
277277
# required when expand=True is explicitly specified
278278
# not needed when inferred
279279

280-
def cons_row(x):
281-
if is_list_like(x):
282-
return x
283-
else:
284-
return [x]
280+
mask = isna(result)
281+
result = [[x] if mask[i] else x for i, x in enumerate(result)]
285282

286-
result = [cons_row(x) for x in result]
287283
if result and not self._is_string:
288284
# propagate nan values to match longest sequence (GH 18450)
289285
max_len = max(len(x) for x in result)
290-
result = [
291-
x * max_len if len(x) == 0 or x[0] is np.nan else x for x in result
292-
]
286+
result = [x * max_len if mask[i] else x for i, x in enumerate(result)]
293287

294288
if not isinstance(expand, bool):
295289
raise ValueError("expand must be True or False")

0 commit comments

Comments
 (0)