Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fixups from code review
  • Loading branch information
olivhoenen committed Mar 31, 2026
commit a1a873f1e6378d08dfcc260f9ae28a552f087aaf
9 changes: 1 addition & 8 deletions imas/ids_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -1157,14 +1157,7 @@ def _circuit_connections_4to3(node: IDSPrimitive) -> None:


def _name_identifier_3to4(source_name: IDSBase, target_description: IDSBase) -> None:
"""Handle DD3to4 name→description rename, preserving name when identifier is empty.

GH#114: The ``name→description`` rename moves DD3 ``name`` to DD4 ``description``.
Normally DD4 ``name`` is filled by the ``identifier→name`` rename. However, when
the DD3 ``identifier`` is empty/unset, ``iter_nonempty_`` never visits it, leaving
DD4 ``name`` blank. This handler copies DD3 ``name`` to *both* DD4 ``description``
and DD4 ``name`` when the DD3 ``identifier`` is absent.
"""
"""Preserve name when identifier is empty, see GH#114."""
# Always copy DD3 name -> DD4 description
target_description.value = source_name.value

Expand Down
30 changes: 6 additions & 24 deletions imas/test/test_ids_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,37 +583,19 @@ def test_3to4_name_identifier_empty_identifier():
src.ids_properties.homogeneous_time = IDS_TIME_MODE_HOMOGENEOUS
src.coil.resize(2)
# Case 1: name populated, identifier empty
src.coil[0].name = "CS3U"
src.coil[0].name = "TEST_NAME"
src.coil[0].identifier = ""
# Case 2: name populated, identifier not set at all
src.coil[1].name = "PF1"
src.coil[1].name = "TEST_NAME2"

dst = convert_ids(src, "4.0.0")

# name must be preserved in DD4 name (not overwritten by empty identifier)
assert dst.coil[0].name == "CS3U"
assert dst.coil[0].description == "CS3U"
assert dst.coil[0].name == "TEST_NAME"
assert dst.coil[0].description == "TEST_NAME"

assert dst.coil[1].name == "PF1"
assert dst.coil[1].description == "PF1"


def test_3to4_name_identifier_both_populated():
"""GH#114: when both name and identifier are populated, identifier wins."""
factory = IDSFactory("3.40.1")

src = factory.pf_active()
src.ids_properties.homogeneous_time = IDS_TIME_MODE_HOMOGENEOUS
src.coil.resize(1)
src.coil[0].name = "CS3U"
src.coil[0].identifier = "COIL_ID"

dst = convert_ids(src, "4.0.0")

# DD3 identifier -> DD4 name
assert dst.coil[0].name == "COIL_ID"
# DD3 name -> DD4 description
assert dst.coil[0].description == "CS3U"
assert dst.coil[1].name == "TEST_NAME2"
assert dst.coil[1].description == "TEST_NAME2"


def test_3to4_cocos_hardcoded_paths():
Expand Down
Loading