Skip to content

Commit

Permalink
Merge pull request #32 from lsst/tickets/DM-16297
Browse files Browse the repository at this point in the history
DM-16297: (take 2) Remove PropertyList hack
  • Loading branch information
timj committed Sep 19, 2019
2 parents 2e217c4 + d2fd0d1 commit 1039c3c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
16 changes: 4 additions & 12 deletions python/astro_metadata_translator/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ def merge_headers(headers, mode="overwrite", sort=False, first=None, last=None):
if not headers:
raise ValueError("No headers supplied.")

# Force PropertyList to OrderedDict
# In python 3.7 dicts are guaranteed to retain order
headers = [h.toOrderedDict() if hasattr(h, "toOrderedDict") else h for h in headers]
# Copy the input list because we will be reorganizing it
headers = list(headers)

# With a single header provided return a copy immediately
if len(headers) == 1:
Expand Down Expand Up @@ -246,16 +245,9 @@ class or else support automatic translation class determination.
The first file located in the search path is used for the correction.
"""

# PropertyList is not dict-like so force to a dict here to allow the
# translation classes to work. We update the original header though.
if hasattr(header, "toOrderedDict"):
header_to_translate = header.toOrderedDict()
else:
header_to_translate = header

if translator_class is None:
try:
translator_class = MetadataTranslator.determine_translator(header_to_translate,
translator_class = MetadataTranslator.determine_translator(header,
filename=filename)
except ValueError:
# if the header is not recognized, we should not complain
Expand All @@ -265,7 +257,7 @@ class or else support automatic translation class determination.
raise TypeError(f"Translator class must be a MetadataTranslator, not {translator_class}")

# Create an instance for this header
translator = translator_class(header_to_translate, filename=filename)
translator = translator_class(header, filename=filename)

# To determine the file look up we need the observation_id and instrument
try:
Expand Down
5 changes: 0 additions & 5 deletions python/astro_metadata_translator/observationInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,6 @@ def __init__(self, header, filename=None, translator_class=None, pedantic=False,
# Store the supplied header for later stripping
self._header = header

# PropertyList is not dict-like so force to a dict here to simplify
# the translation code.
if hasattr(header, "toOrderedDict"):
header = header.toOrderedDict()

if translator_class is None:
translator_class = MetadataTranslator.determine_translator(header, filename=filename)
elif not issubclass(translator_class, MetadataTranslator):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def test_one(self):

def test_merging_overwrite(self):
merged = merge_headers([self.h1, self.h2], mode="overwrite")
# The merged header should be the same type as the first header
self.assertIsInstance(merged, type(self.h1))

expected = {
"MJD-OBS": self.h2["MJD-OBS"],
Expand Down

0 comments on commit 1039c3c

Please sign in to comment.