Skip to content

Commit

Permalink
Fix pivoted import mappings using column headers (#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
soininen authored Nov 4, 2024
2 parents ff79412 + f2d831f commit 91b4979
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions spinedb_api/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ def is_effective_leaf(self):
Returns:
bool: True if mapping is effectively the last child, False otherwise
"""
return self._child is None or any(
child.position in (Position.hidden, Position.table_name) for child in self._child.flatten()
return self._child is None or all(
child.position in (Position.hidden, Position.table_name) for child in self._child.flatten()[:-1]
)

def is_pivoted(self):
Expand Down
16 changes: 16 additions & 0 deletions tests/import_mapping/test_import_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
ParameterValueTypeMapping,
check_validity,
default_import_mapping,
from_dict,
)
from spinedb_api.import_mapping.import_mapping_compat import (
import_mapping_from_dict,
Expand Down Expand Up @@ -198,6 +199,21 @@ def test_polish_mapping_name_mapping(self):
self.assertEqual(mapping.position, Position.mapping_name)
self.assertEqual(mapping.value, "some_mapping_name")

def test_polishing_pivoted_mapping_for_preview_with_column_headers_doesnt_break_it(self):
mapping_dicts = [
{"map_type": "EntityClass", "position": "table_name"},
{"map_type": "Dimension", "position": "header", "value": 0},
{"map_type": "Entity", "position": "hidden"},
{"map_type": "Element", "position": 0},
{"map_type": "Alternative", "position": "hidden", "value": "Base"},
{"map_type": "ParameterDefinition", "position": "header"},
{"map_type": "ParameterValue", "position": "hidden"},
]
root_mapping = from_dict(mapping_dicts)
self.assertEqual(root_mapping.child.value, 0)
root_mapping.polish("table name", ["entity class", "1st parameter"], "Test mapping", for_preview=True)
self.assertEqual(root_mapping.child.value, 0)


class TestImportMappingIO(unittest.TestCase):
def test_object_class_mapping(self):
Expand Down

0 comments on commit 91b4979

Please sign in to comment.