Skip to content

ChainMap does not work with FitsDict #247

@ucapbba

Description

@ucapbba

collections.ChainMap allows to combine multiple dictionaries into a single view. It benefits over dict.update() by not creating a new dictionary. We use this in our pipeline for example when passing multiple fits file for different bins and fields.

The problem:
If the items in chain map throw an error that isn't a KeyError, the chain map getitem method will fail

ChainMap gets an item with this code

def getitem(self, key):
for mapping in self.maps:
try:
return mapping[key] # can't use 'key in mapping' with defaultdict
except KeyError:
pass
return self.missing(key) # support subclasses that define missing

Here, it loops through all of the keys until it finds the correct one. However when mapping[key] calls FitsDict with an incorrect key, it will throw a general exception which will not be handled by ChainMap and therefore no data will be returned.

The solution:
Ensure FitsDict returns raises a KeyError

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions