Skip to content

Commit 75aa992

Browse files
Fix PyArrow issue and preserve Series attrs metadata
1 parent db8af91 commit 75aa992

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pandas/core/strings/accessor.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2440,6 +2440,9 @@ def get_dummies(
24402440
input_series = (
24412441
Series(self._data) if isinstance(self._data, ABCIndex) else self._data
24422442
)
2443+
if isinstance(self._data.dtype, ArrowDtype):
2444+
import pyarrow as pa
2445+
dtype = ArrowDtype(pa.bool_())
24432446
string_series = input_series.apply(lambda x: str(x) if not isna(x) else x)
24442447
split_series = string_series.str.split(sep, expand=True).stack()
24452448
valid_split_series = split_series[
@@ -2486,9 +2489,13 @@ def get_dummies(
24862489
f"{prefix[i]}{prefix_sep}{col}"
24872490
for i, col in enumerate(result_df.columns)
24882491
]
2489-
2492+
24902493
if isinstance(self._data, ABCIndex):
24912494
return MultiIndex.from_frame(result_df)
2495+
2496+
result_df.attrs = self._data.attrs
2497+
if dtype is not None and not sparse:
2498+
return result_df.astype(dtype)
24922499
return result_df
24932500

24942501
@forbid_nonstring_types(["bytes"])

0 commit comments

Comments
 (0)