Skip to content

Commit 085b8c0

Browse files
Fix bug that was crashing method when attribute was an array. (spacetelescope#350)
1 parent 52d2b96 commit 085b8c0

File tree

2 files changed

+18
-34
lines changed

2 files changed

+18
-34
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

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

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

79
0.19.2 (2024-05-08)
810
===================

src/roman_datamodels/datamodels/_datamodels.py

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -77,55 +77,37 @@ def append_individual_image_meta(self, meta):
7777

7878
# Keys that are themselves Dnodes (subdirectories)
7979
# neccessitate a new table
80+
if isinstance(value, (dict, asdf.tags.core.ndarray.NDArrayType, QTable)):
81+
continue
82+
8083
if isinstance(value, stnode.DNode):
8184
# Storage for keys and values
8285
subtable_cols = []
8386
subtable_vals = []
8487

8588
# Loop over items within the node
8689
for subkey, subvalue in meta_dict[key].items():
87-
# Skip ndarrays
88-
if isinstance(subvalue, asdf.tags.core.ndarray.NDArrayType):
89-
continue
90-
# Skip QTables
91-
if isinstance(subvalue, QTable):
90+
# Skip ndarrays and QTables
91+
if isinstance(subvalue, (asdf.tags.core.ndarray.NDArrayType, QTable)):
9292
continue
9393

9494
subtable_cols.append(subkey)
95-
96-
if isinstance(subvalue, (list, dict)):
97-
subtable_vals.append([str(subvalue)])
98-
else:
99-
subtable_vals.append([subvalue])
95+
subtable_vals.append([str(subvalue)] if isinstance(subvalue, (list, dict)) else [subvalue])
10096

10197
# Skip this Table if it would be empty
102-
if len(subtable_vals) == 0:
103-
continue
104-
105-
# Make new Keyword Table if needed
106-
if (key not in self.meta.individual_image_meta) or (self.meta.individual_image_meta[key].colnames == ["dummy"]):
107-
self.meta.individual_image_meta[key] = QTable(names=subtable_cols, data=subtable_vals)
108-
else:
109-
# Append to existing table
110-
self.meta.individual_image_meta[key].add_row(subtable_vals)
111-
# Skip non-schema metas
112-
elif isinstance(value, dict):
113-
continue
114-
# Skip ndarrays
115-
elif isinstance(value.strip(), asdf.tags.core.ndarray.NDArrayType):
116-
continue
117-
# Skip QTables
118-
elif isinstance(value, QTable):
119-
continue
98+
if subtable_vals:
99+
# Make new Keyword Table if needed
100+
if (key not in self.meta.individual_image_meta) or (
101+
self.meta.individual_image_meta[key].colnames == ["dummy"]
102+
):
103+
self.meta.individual_image_meta[key] = QTable(names=subtable_cols, data=subtable_vals)
104+
else:
105+
# Append to existing table
106+
self.meta.individual_image_meta[key].add_row(subtable_vals)
120107
else:
121108
# Store Basic keyword
122109
basic_cols.append(key)
123-
124-
# Store value (lists converted to strings)
125-
if isinstance(value.strip(), list):
126-
basic_vals.append([str(value)])
127-
else:
128-
basic_vals.append([value])
110+
basic_vals.append([str(value)] if isinstance(value, list) else [value])
129111

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

0 commit comments

Comments
 (0)