diff --git a/src/xtgeo/well/well1.py b/src/xtgeo/well/well1.py index fe16d8a95..0688589cd 100644 --- a/src/xtgeo/well/well1.py +++ b/src/xtgeo/well/well1.py @@ -169,8 +169,6 @@ class Well: defaults to None. """ - VALID_LOGTYPES = {"DISC", "CONT"} - @_well_aux.allow_deprecated_init def __init__( self, @@ -706,7 +704,7 @@ def get_wlogs(self) -> dict: wtype = "CONT" wrecord = None if key in self._wdata.attr_types: - wtype = self._wdata.attr_types[key] + wtype = self._wdata.attr_types[key].name if key in self._wdata.attr_records: wrecord = self._wdata.attr_records[key] @@ -734,28 +732,31 @@ def set_wlogs(self, wlogs: dict): for key in self.get_lognames(): if key in wlogs.keys(): typ, rec = wlogs[key] - - if typ in Well.VALID_LOGTYPES: - # self._wlogtypes[key] = deepcopy(typ) - self._wdata.set_attr_type(key, deepcopy(typ)) - else: - raise ValueError(f"Invalid log type found in input: {typ}") - - if isinstance(rec, dict): - self._wdata.set_attr_record(key, deepcopy(rec)) - # self._wlogrecords[key] = deepcopy(rec) - elif not rec: - self._wdata.set_attr_record(key, ("", "")) - # self._wlogrecords[key] = "" - else: - raise ValueError(f"Invalid log record found in input: {rec}") - - else: - raise ValueError(f"Key for column not found in input: {key}") - - for key in wlogs.keys(): - if key not in self.get_lognames(): - raise ValueError(f"Invalid input key found: {key}") + self._wdata.set_attr_type(key, typ) + self._wdata.set_attr_record(key, deepcopy(rec)) + + # if typ in ("DISC", "CONT"): + # self._wdata.set_attr_type(key, typ) + # else: + # raise ValueError(f"Invalid log type found in input: {typ}") + + # if isinstance(rec, dict) and typ == "CONT": + # self._wdata.set_attr_record(key, deepcopy(rec)) + # # self._wlogrecords[key] = deepcopy(rec) + # elif isinstance(rec, (list, tuple)) and typ == "DISC": + # self._wdata.set_attr_record(key, deepcopy(rec)) + # elif not rec: + # self._wdata.set_attr_record(key, ("", "")) + # # self._wlogrecords[key] = "" + # else: + # raise ValueError(f"Invalid log record found in input: {rec}") + + # else: + # raise ValueError(f"Key for column not found in input: {key}") + + # for key in wlogs.keys(): + # if key not in self.get_lognames(): + # raise ValueError(f"Invalid input key found: {key}") self._ensure_consistency() diff --git a/src/xtgeo/xyz_common/_xyz_data.py b/src/xtgeo/xyz_common/_xyz_data.py index 2061ab156..e81f19d19 100644 --- a/src/xtgeo/xyz_common/_xyz_data.py +++ b/src/xtgeo/xyz_common/_xyz_data.py @@ -312,13 +312,16 @@ def get_attr_record(self, name: str): """Get a record for a named attribute.""" return self._attr_records[name] - def set_attr_record(self, name: str, record: dict) -> None: + def set_attr_record(self, name: str, record: Optional[dict]) -> None: """Set a record for a named log.""" if name not in self._attr_types: raise ValueError(f"No such attr_name: {name}") - print("XXXXXXX", self._attr_types[name]) + if record is None and self._attr_types[name] == _AttrType.DISC: + record = {} + elif record is None and self._attr_types[name] == _AttrType.CONT: + record = CONT_DEFAULT_RECORD if self._attr_types[name] == _AttrType.CONT and isinstance( record, (list, tuple) diff --git a/tests/test_well/test_well.py b/tests/test_well/test_well.py index 58ff74f32..a86e5bb75 100644 --- a/tests/test_well/test_well.py +++ b/tests/test_well/test_well.py @@ -342,6 +342,18 @@ def test_create_and_delete_logs_implicit(loadwell3): # assert ndeleted == 2 +def test_wlogtypes(loadwell3): + mywell = loadwell3 + wlogtypes = mywell.wlogtypes + assert wlogtypes == { + "X_UTME": "CONT", + "Y_UTMN": "CONT", + "Z_TVDSS": "CONT", + "GR": "CONT", + "ZONELOG": "DISC", + } + + def test_get_set_wlogs(loadwell3): """Test on getting ans setting a dictionary with some log attributes.""" mywell = loadwell3 @@ -364,8 +376,7 @@ def test_get_set_wlogs(loadwell3): assert mydict2["ZONELOG"][1][24] == "ZONE_24_EDITED" mydict2["EXTRA"] = None - with pytest.raises(ValueError): - mywell.set_wlogs(mydict2) + mywell.set_wlogs(mydict2) def test_make_hlen(loadwell1):