Skip to content
Merged
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
2 changes: 1 addition & 1 deletion spinedb_api/import_mapping/import_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ class EntityMapping(ImportMapping):
MAP_TYPE = "Entity"

def _import_row(self, source_data, state, mapped_data):
if self.position == Position.hidden and isinstance(self._child, ElementMapping):
if isinstance(self._child, ElementMapping):
return
entity_class_name = state[ImportKey.ENTITY_CLASS_NAME]
entity_name = state[ImportKey.ENTITY_NAME] = str(source_data)
Expand Down
48 changes: 48 additions & 0 deletions tests/import_mapping/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1381,3 +1381,51 @@ def test_import_different_relationships_in_same_table(self):
],
},
)

def test_import_element_2_names_from_headers(self):
header = ["Food", "VitA", "VitC"]
data_source = iter(
[
["hamburger", 6.0, 2.0],
["orange juice", 2.0, 120.0],
]
)
mappings = [
[
{"map_type": "EntityClass", "position": "hidden", "value": "NutrientContent"},
{"map_type": "Dimension", "position": "hidden", "value": "Food"},
{"map_type": "Dimension", "position": "hidden", "value": "Nutrient"},
{"map_type": "Entity", "position": 0},
{"map_type": "Element", "position": 0},
{"map_type": "Element", "position": "header"},
{"map_type": "Alternative", "position": "hidden", "value": "Base"},
{"map_type": "ParameterDefinition", "position": "hidden", "value": "content"},
{"map_type": "ParameterValue", "position": "hidden"},
]
]
mapped_data, errors = get_mapped_data(data_source, mappings, header)
self.assertEqual(errors, [])
self.assertEqual(
mapped_data,
{
"alternatives": {"Base"},
"entity_classes": [
["NutrientContent", ["Food", "Nutrient"]],
],
"entities": [
["NutrientContent", ["hamburger", "VitA"]],
["NutrientContent", ["hamburger", "VitC"]],
["NutrientContent", ["orange juice", "VitA"]],
["NutrientContent", ["orange juice", "VitC"]],
],
"parameter_definitions": [
["NutrientContent", "content"],
],
"parameter_values": [
["NutrientContent", ("hamburger", "VitA"), "content", 6.0, "Base"],
["NutrientContent", ("hamburger", "VitC"), "content", 2.0, "Base"],
["NutrientContent", ("orange juice", "VitA"), "content", 2.0, "Base"],
["NutrientContent", ("orange juice", "VitC"), "content", 120.0, "Base"],
],
},
)
Loading