Skip to content

Commit

Permalink
Backport PR #51732 on branch 2.0.x (CoW: Add property for references …
Browse files Browse the repository at this point in the history
…to series class) (#51755)

Backport PR #51732: CoW: Add property for references to series class

Co-authored-by: Patrick Hoefler <61934744+phofl@users.noreply.github.com>
  • Loading branch information
meeseeksmachine and phofl committed Mar 3, 2023
1 parent 984390d commit a255a00
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 1 addition & 4 deletions pandas/core/internals/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,10 +567,7 @@ def _homogenize(
# Forces alignment. No need to copy data since we
# are putting it into an ndarray later
val = val.reindex(index, copy=False)
if isinstance(val._mgr, SingleBlockManager):
refs.append(val._mgr._block.refs)
else:
refs.append(None)
refs.append(val._references)
val = val._values
else:
if isinstance(val, dict):
Expand Down
7 changes: 7 additions & 0 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
properties,
reshape,
)
from pandas._libs.internals import BlockValuesRefs
from pandas._libs.lib import (
is_range_indexer,
no_default,
Expand Down Expand Up @@ -735,6 +736,12 @@ def _values(self):
"""
return self._mgr.internal_values()

@property
def _references(self) -> BlockValuesRefs | None:
if isinstance(self._mgr, SingleArrayManager):
return None
return self._mgr._block.refs

# error: Decorated property not supported
@Appender(base.IndexOpsMixin.array.__doc__) # type: ignore[misc]
@property
Expand Down

0 comments on commit a255a00

Please sign in to comment.