Skip to content

Commit

Permalink
remove null entries in alias and stratigraphic_alias
Browse files Browse the repository at this point in the history
  • Loading branch information
perolavsvendsen committed Nov 8, 2023
1 parent 5222792 commit a03b00c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/fmu/dataio/dataio.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ def _check_global_config(
f"stratigraphy.{key}: 'alias' items must be strings\n"
)

# After checking and warning, remove empty entries
item["alias"] = list(filter(lambda i: i is not None, item["alias"]))

if "stratigraphic_alias" in item:
if not isinstance(item["stratigraphic_alias"], list):
msg += f"stratigraphy.{key}: 'stratigraphic_alias' must be list.\n"
Expand All @@ -158,6 +161,11 @@ def _check_global_config(
msg += f"stratigraphy.{key}: 'stratigraphic_alias' items "
msg += "must be strings.\n"

# After checking and warning, remove empty entries
item["stratigraphic_alias"] = list(
filter(lambda i: i is not None, item["stratigraphic_alias"])
)

if msg:
if "err" in action:
raise ValueError(msg)
Expand Down
16 changes: 11 additions & 5 deletions tests/test_units/test_dataio.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,23 @@ def test_config_miss_required_fields(globalconfig1, regsurf):
read_metadata(out)


def test_config_stratigraphy_empty_entries_alias(globalconfig2):
"""Test that empty entries in 'alias' is detected and warned."""
def test_config_stratigraphy_empty_entries_alias(globalconfig2, regsurf):
"""Test that empty entries in 'alias' is detected and warned and removed."""
cfg = deepcopy(globalconfig2)
cfg["stratigraphy"]["TopVolantis"]["alias"] += [None]

with pytest.warns(PendingDeprecationWarning, match="'alias' items must be strings"):
ExportData(config=cfg, content="depth")
exp = ExportData(config=cfg, content="depth", name="TopVolantis")
metadata = exp.generate_metadata(regsurf)

assert None not in metadata["data"]["alias"]


def test_config_stratigraphy_empty_entries_stratigraphic_alias(globalconfig2, regsurf):
"""Test that empty entries in 'stratigraphic_alias' detected and warned."""

# Note! stratigraphic_alias is not implemented, but we still check consistency

def test_config_stratigraphy_empty_entries_stratigraphic_alias(globalconfig2):
"""Test that empty entries in 'stratigraphic_alias' is detected and warned."""
cfg = deepcopy(globalconfig2)
cfg["stratigraphy"]["TopVolantis"]["stratigraphic_alias"] += [None]

Expand Down

0 comments on commit a03b00c

Please sign in to comment.