File tree 1 file changed +15
-4
lines changed
1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -8764,11 +8764,22 @@ def update(
8764
8764
if not isinstance (other , DataFrame ):
8765
8765
other = DataFrame (other )
8766
8766
8767
- other = other .reindex (self .index )
8767
+ if other .index .has_duplicates :
8768
+ raise ValueError ("Update not allowed with duplicate indexes on other." )
8769
+
8770
+ rows = other .index .intersection (self .index )
8771
+ if rows .empty :
8772
+ raise ValueError (
8773
+ "Can't update dataframe when other has no index in common with "
8774
+ "this dataframe."
8775
+ )
8776
+
8777
+ other = other .reindex (rows )
8778
+ this_data = self .loc [rows ]
8768
8779
8769
8780
for col in self .columns .intersection (other .columns ):
8770
- this = self [col ]. _values
8771
- that = other [col ]. _values
8781
+ this = this_data [col ]
8782
+ that = other [col ]
8772
8783
8773
8784
if filter_func is not None :
8774
8785
mask = ~ filter_func (this ) | isna (that )
@@ -8788,7 +8799,7 @@ def update(
8788
8799
if mask .all ():
8789
8800
continue
8790
8801
8791
- self .loc [: , col ] = self [ col ] .where (mask , that )
8802
+ self .loc [rows , col ] = this .where (mask , that )
8792
8803
8793
8804
# ----------------------------------------------------------------------
8794
8805
# Data reshaping
You can’t perform that action at this time.
0 commit comments