Issue 32617: dict.update does not concat/replace if same key (original) (raw)

The dict does not seem to work as one would expect a dictionary or a hashtable to work.

dict.update(otherdict) just replaces the entries as per otherdict, removing items which were extra in dict too and just keeping items as per new data in otherdict only. Shouldn't this be actually about updating the dict with new/updated entries and not touching those entries which pre-existed?

Sample program below: import pandas as pd

x = {'name': ['A', 'B', 'C'], 'col2': [3, 4,6]} y = {'name': ['B', 'C', 'D', 'E'], 'col2': [1,2, 9, 10]}

print ("X = \n" + str(x))

print ("Y = \n" + str(y))

x.update(y)

print ("updated dict = \n" + str(x) + "\n")

Output:

X = {'name': ['A', 'B', 'C'], 'col2': [3, 4, 6]} Y = {'name': ['B', 'C', 'D', 'E'], 'col2': [1, 2, 9, 10]} updated dict = {'name': ['B', 'C', 'D', 'E'], 'col2': [1, 2, 9, 10]}

Expected value: updated dict = {'name': ['A','B', 'C', 'D', 'E'], 'col2': [3, 1, 2, 9, 10]}

Somehow to do this basic hashtable or dictionary update kind of operation is too complex in python and update() should have actually functioned as expected above IMO.