diff --git a/changes/8958.general.rst b/changes/8958.general.rst new file mode 100644 index 0000000000..a84befe1ff --- /dev/null +++ b/changes/8958.general.rst @@ -0,0 +1 @@ +When blending metadata don't store columns containing all missing value (nans). diff --git a/jwst/model_blender/_tablebuilder.py b/jwst/model_blender/_tablebuilder.py index e677d0699e..7bfd2b4efb 100644 --- a/jwst/model_blender/_tablebuilder.py +++ b/jwst/model_blender/_tablebuilder.py @@ -1,6 +1,12 @@ import numpy as np +class _MissingValueType: + pass + +_MISSING_VALUE = _MissingValueType() + + def _convert_dtype(value): """Convert numarray column dtype into YAML-compatible format description""" if 'U' in value: @@ -99,7 +105,7 @@ def header_to_row(self, header): def _add_row(self, row): for attr, col in self.attr_to_column.items(): - self.columns[col].append(row[attr] if attr in row else np.nan) + self.columns[col].append(row[attr] if attr in row else _MISSING_VALUE) def build_table(self): """ @@ -113,6 +119,8 @@ def build_table(self): arrays = [] table_dtype = [] for col, items in self.columns.items(): - arrays.append(np.array(items)) + if all((i is _MISSING_VALUE for i in items)): + continue + arrays.append(np.array([np.nan if i is _MISSING_VALUE else i for i in items])) table_dtype.append((col, arrays[-1].dtype)) return np.rec.fromarrays(arrays, dtype=table_dtype) diff --git a/jwst/model_blender/tests/test_blend.py b/jwst/model_blender/tests/test_blend.py index 37c9d705dc..48f0fbd891 100644 --- a/jwst/model_blender/tests/test_blend.py +++ b/jwst/model_blender/tests/test_blend.py @@ -37,6 +37,11 @@ # even if the metadata is defined in the schema KNOWN_MISSING_FIRSTS = [None, '1', '2'] +# None of the below test data defines this attribute. +# It is expected to be missing from the resulting +# table (as is checked below). +MISSING_COLUMN = "TIME-OBS" + def _make_data(): """Create a set of input models to blendmeta @@ -195,6 +200,7 @@ def test_blendtab(blend): # Ensure all the expected FITS keywords are in the table. colnames = set(newtab.dtype.fields) assert not fits_expected.difference(colnames) + assert MISSING_COLUMN not in colnames for col in colnames: if col in input_values: assert newtab[col] == input_values[col]