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

don't store empty columns in HDRTAB #8958

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/8958.general.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
When blending metadata don't store columns containing all missing value (nans).
12 changes: 10 additions & 2 deletions jwst/model_blender/_tablebuilder.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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)
6 changes: 6 additions & 0 deletions jwst/model_blender/tests/test_blend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
Loading