File tree 2 files changed +18
-4
lines changed
2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -944,12 +944,17 @@ def is_in_obj(gpr) -> bool:
944
944
if not hasattr (gpr , "name" ):
945
945
return False
946
946
if using_copy_on_write ():
947
- # For the CoW case, we need an equality check as the identity check
948
- # no longer works (each Series from column access is a new object)
947
+ # For the CoW case, we check the references to determine if the
948
+ # series is part of the object
949
949
try :
950
- return gpr . equals ( obj [gpr .name ])
951
- except (AttributeError , KeyError , IndexError , InvalidIndexError ):
950
+ obj_gpr_column = obj [gpr .name ]
951
+ except (KeyError , IndexError , InvalidIndexError ):
952
952
return False
953
+ if isinstance (gpr , Series ) and isinstance (obj_gpr_column , Series ):
954
+ return gpr ._mgr .references_same_values ( # type: ignore[union-attr]
955
+ obj_gpr_column ._mgr , 0 # type: ignore[arg-type]
956
+ )
957
+ return False
953
958
try :
954
959
return gpr is obj [gpr .name ]
955
960
except (KeyError , IndexError , InvalidIndexError ):
Original file line number Diff line number Diff line change 11
11
cast ,
12
12
)
13
13
import warnings
14
+ import weakref
14
15
15
16
import numpy as np
16
17
@@ -258,6 +259,14 @@ def add_references(self, mgr: BaseBlockManager) -> None:
258
259
# "Block"; expected "SharedBlock"
259
260
blk .refs .add_reference (blk ) # type: ignore[arg-type]
260
261
262
+ def references_same_values (self , mgr : BaseBlockManager , blkno : int ) -> bool :
263
+ """
264
+ Checks if two blocks from two different block managers reference the
265
+ same underlying values.
266
+ """
267
+ ref = weakref .ref (self .blocks [blkno ])
268
+ return ref in mgr .blocks [blkno ].refs .referenced_blocks
269
+
261
270
def get_dtypes (self ):
262
271
dtypes = np .array ([blk .dtype for blk in self .blocks ])
263
272
return dtypes .take (self .blknos )
You can’t perform that action at this time.
0 commit comments