@@ -8858,23 +8858,27 @@ def update(
8858
8858
if not isinstance (other , DataFrame ):
8859
8859
other = DataFrame (other )
8860
8860
8861
- indexes_intersection = self .index .intersection (other .index )
8861
+ indexes_intersection = other .index .intersection (self .index ) # order is important
8862
8862
if not len (indexes_intersection ):
8863
8863
raise ValueError (
8864
- "Can't update dataframe when other has no element in common."
8864
+ "Can't update dataframe when other has no index in common with this dataframe."
8865
+ )
8866
+
8867
+ if other .index .is_unique :
8868
+ indexes_this = indexes_intersection
8869
+ if self .index .is_unique :
8870
+ indexes_that = indexes_intersection
8871
+ else :
8872
+ full_indexes_this = self .index .take (self .index .get_indexer_for (indexes_intersection ))
8873
+ indexes_that = indexes_intersection .reindex (full_indexes_this )[0 ]
8874
+ else :
8875
+ raise ValueError (
8876
+ "Update not allowed with duplicate indexes on other."
8865
8877
)
8866
8878
8867
8879
for col in self .columns .intersection (other .columns ):
8868
- this = self .loc [indexes_intersection , col ]
8869
- that = other .loc [indexes_intersection , col ]
8870
-
8871
- if this .index .has_duplicates or that .index .has_duplicates :
8872
- raise ValueError (
8873
- "Update not allowed with duplicate indexes on dataframe or other."
8874
- )
8875
-
8876
- this = this ._values
8877
- that = that ._values
8880
+ this = self .loc [indexes_this , col ]._values
8881
+ that = other .loc [indexes_that , col ]._values
8878
8882
8879
8883
if filter_func is not None :
8880
8884
mask = ~ filter_func (this ) | isna (that )
0 commit comments