Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion python/pyspark/pandas/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,16 @@ def __setitem__(self, key: Any, value: Any) -> None:
from pyspark.pandas.series import Series, first_series

if self._is_series:
if LooseVersion(pd.__version__) >= "3.0.0":
# pandas 3 CoW: mutating a Series view should not mutate the parent DataFrame.
self._psdf_or_psser._update_anchor(
DataFrame(
self._psdf_or_psser._psdf._internal.select_column(
self._psdf_or_psser._column_label
)
)
)

if (
isinstance(key, Series)
and (isinstance(self, iLocIndexer) or not same_anchor(key, self._psdf_or_psser))
Expand Down Expand Up @@ -811,7 +821,11 @@ def __setitem__(self, key: Any, value: Any) -> None:
internal = self._internal.with_new_columns(
new_data_spark_columns, column_labels=column_labels, data_fields=new_fields
)
self._psdf_or_psser._update_internal_frame(internal, check_same_anchor=False)
self._psdf_or_psser._update_internal_frame(
internal,
check_same_anchor=False,
anchor_force_disconnect=LooseVersion(pd.__version__) >= "3.0.0",
)


class LocIndexer(LocIndexerLike):
Expand Down
5 changes: 1 addition & 4 deletions python/pyspark/pandas/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,7 @@ def __init__( # type: ignore[no-untyped-def]
assert not copy
assert fastpath is no_default

if LooseVersion(pd.__version__) < "3.0.0":
self._anchor = data
else:
self._anchor = DataFrame(data)
self._anchor = data
self._col_label = index

elif isinstance(data, Series):
Expand Down