Skip to content

Commit

Permalink
Fix bug that was crashing method when attribute was an array. (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
mairanteodoro authored May 13, 2024
1 parent 52d2b96 commit 085b8c0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 34 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

- Separated TVAC and FPS into their own makers to freeze from from main development. [#347]

- Fix bug that prevented proper handling of ``np.NDArray``\s. [#350]


0.19.2 (2024-05-08)
===================
Expand Down
50 changes: 16 additions & 34 deletions src/roman_datamodels/datamodels/_datamodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,55 +77,37 @@ def append_individual_image_meta(self, meta):

# Keys that are themselves Dnodes (subdirectories)
# neccessitate a new table
if isinstance(value, (dict, asdf.tags.core.ndarray.NDArrayType, QTable)):
continue

if isinstance(value, stnode.DNode):
# Storage for keys and values
subtable_cols = []
subtable_vals = []

# Loop over items within the node
for subkey, subvalue in meta_dict[key].items():
# Skip ndarrays
if isinstance(subvalue, asdf.tags.core.ndarray.NDArrayType):
continue
# Skip QTables
if isinstance(subvalue, QTable):
# Skip ndarrays and QTables
if isinstance(subvalue, (asdf.tags.core.ndarray.NDArrayType, QTable)):
continue

subtable_cols.append(subkey)

if isinstance(subvalue, (list, dict)):
subtable_vals.append([str(subvalue)])
else:
subtable_vals.append([subvalue])
subtable_vals.append([str(subvalue)] if isinstance(subvalue, (list, dict)) else [subvalue])

# Skip this Table if it would be empty
if len(subtable_vals) == 0:
continue

# Make new Keyword Table if needed
if (key not in self.meta.individual_image_meta) or (self.meta.individual_image_meta[key].colnames == ["dummy"]):
self.meta.individual_image_meta[key] = QTable(names=subtable_cols, data=subtable_vals)
else:
# Append to existing table
self.meta.individual_image_meta[key].add_row(subtable_vals)
# Skip non-schema metas
elif isinstance(value, dict):
continue
# Skip ndarrays
elif isinstance(value.strip(), asdf.tags.core.ndarray.NDArrayType):
continue
# Skip QTables
elif isinstance(value, QTable):
continue
if subtable_vals:
# Make new Keyword Table if needed
if (key not in self.meta.individual_image_meta) or (
self.meta.individual_image_meta[key].colnames == ["dummy"]
):
self.meta.individual_image_meta[key] = QTable(names=subtable_cols, data=subtable_vals)
else:
# Append to existing table
self.meta.individual_image_meta[key].add_row(subtable_vals)
else:
# Store Basic keyword
basic_cols.append(key)

# Store value (lists converted to strings)
if isinstance(value.strip(), list):
basic_vals.append([str(value)])
else:
basic_vals.append([value])
basic_vals.append([str(value)] if isinstance(value, list) else [value])

# Make Basic Table if needed
if self.meta.individual_image_meta.basic.colnames == ["dummy"]:
Expand Down

0 comments on commit 085b8c0

Please sign in to comment.