Skip to content

Commit

Permalink
FIX: Support unit input as None (#665)
Browse files Browse the repository at this point in the history
  • Loading branch information
tnatt authored May 28, 2024
1 parent 1dcc274 commit 0c2d040
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/fmu/dataio/dataio.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ class ExportData:
subfolder: str = ""
tagname: str = ""
timedata: Optional[List[list]] = None
unit: str = ""
unit: Optional[str] = ""
verbosity: str = "DEPRECATED" # remove in version 2
vertical_domain: dict = field(default_factory=dict)
workflow: Optional[Union[str, Dict[str, str]]] = None
Expand Down
2 changes: 1 addition & 1 deletion src/fmu/dataio/providers/objectdata/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def __post_init__(self) -> None:
self.metadata["tagname"] = self.dataio.tagname
self.metadata["format"] = objres.fmt
self.metadata["layout"] = objres.layout
self.metadata["unit"] = self.dataio.unit
self.metadata["unit"] = self.dataio.unit or ""
self.metadata["vertical_domain"] = list(self.dataio.vertical_domain.keys())[0]
self.metadata["depth_reference"] = list(self.dataio.vertical_domain.values())[0]
self.metadata["spec"] = objres.spec
Expand Down
7 changes: 7 additions & 0 deletions tests/test_units/test_dataio.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,13 @@ def test_rep_include(globalconfig1, regsurf):
assert mymeta["access"]["ssdl"]["rep_include"] is False


def test_unit_is_none(globalconfig1, regsurf):
"""Test that unit=None works and is translated into an enpty string"""
eobj = ExportData(config=globalconfig1, unit=None)
meta = eobj.generate_metadata(regsurf)
assert meta["data"]["unit"] == ""


def test_content_not_given(globalconfig1, regsurf):
"""When content is not explicitly given, warning shall be issued."""
eobj = ExportData(config=globalconfig1)
Expand Down

0 comments on commit 0c2d040

Please sign in to comment.