Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-16297: (take 2) Remove PropertyList hack #32

Merged
merged 1 commit into from
Sep 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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