chainmap.py 715 B

12345678910111213141516171819202122232425262728
  1. try:
  2. from collections import ChainMap
  3. except ImportError:
  4. from pandas.compat.chainmap_impl import ChainMap
  5. class DeepChainMap(ChainMap):
  6. def __setitem__(self, key, value):
  7. for mapping in self.maps:
  8. if key in mapping:
  9. mapping[key] = value
  10. return
  11. self.maps[0][key] = value
  12. def __delitem__(self, key):
  13. for mapping in self.maps:
  14. if key in mapping:
  15. del mapping[key]
  16. return
  17. raise KeyError(key)
  18. # override because the m parameter is introduced in Python 3.4
  19. def new_child(self, m=None):
  20. if m is None:
  21. m = {}
  22. return self.__class__(m, *self.maps)