Skip to content

Implement import mappings for descriptions#614

Merged
soininen merged 9 commits intomasterfrom
toolbox_1892_import_descriptions
Mar 5, 2026
Merged

Implement import mappings for descriptions#614
soininen merged 9 commits intomasterfrom
toolbox_1892_import_descriptions

Conversation

@soininen
Copy link
Copy Markdown
Contributor

@soininen soininen commented Mar 4, 2026

This PR implements import mappings for entity class, entity, parameter value, scenario and alternative descriptions.

Re spine-tools/Spine-Toolbox#1892

Checklist before merging

  • Documentation (also in Toolbox repo) is up-to-date
  • Release notes have been updated
  • Unit tests have been added/updated accordingly
  • Code has been formatted by black & isort
  • Unit tests pass

Changed the logic on how entity (class) mappings work since adding
descriptions to the previous system turned out to be quite hacky.
We now collect the imported data into 'records'
(EntityClassRecord, EntityRecord) which we process into import
data for import_functions at the end of get_mapped_data().

Also, removed the raise KeyError()/raise KeyFix() system that
didn't make sense to do on every single imported row.
We should have some dedicated machinery that validates the
mappings without affecting the actual import process instead.

In any case, the changes seem to improve the performance by a lot:
unit tests on my system execute in 2:45 with these changes
while before this commit, they took 3:30.
Also a real-life Importer execution time is down to 5s from 9s.

Re spine-tools/Spine-Toolbox#1892
- ParameterValueListMapping cannot unconditionally require ParameterDefinitionMapping
  as parent. A smarter validation mechanism has been implemented to fix this.
- We should let KeyErrors in ImportMapping.import_row() to propagate.
  They are now always logic errors as we do not use KeyErrors for mapping validation
  anymore.
- Fixed a bug in EntityMapping where ND entities from the first entity class encountered
  on a table were imported but nothing else.

Re spine-tools/Spine-Toolbox#1892
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 5, 2026

Codecov Report

❌ Patch coverage is 87.98450% with 62 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.05%. Comparing base (35a1fb1) to head (e23dcc7).
⚠️ Report is 11 commits behind head on master.

Files with missing lines Patch % Lines
spinedb_api/import_mapping/import_mapping.py 89.38% 33 Missing and 10 partials ⚠️
spinedb_api/import_mapping/generator.py 84.53% 10 Missing and 5 partials ⚠️
spinedb_api/exception.py 50.00% 1 Missing and 1 partial ⚠️
spinedb_api/spine_io/importers/csv_reader.py 75.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #614      +/-   ##
==========================================
- Coverage   86.05%   86.05%   -0.01%     
==========================================
  Files          83       83              
  Lines       11225    11433     +208     
  Branches     1627     1635       +8     
==========================================
+ Hits         9660     9839     +179     
- Misses       1210     1241      +31     
+ Partials      355      353       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

New chardet breaks our unit tests; however, it seems to be much more
performant (it's a complete rewrite after all) and capable than the
previous versions. So, let's switch to the latest and creates
once and for all.
@soininen soininen force-pushed the toolbox_1892_import_descriptions branch from 7103200 to e23dcc7 Compare March 5, 2026 10:34
@soininen soininen merged commit a9b947c into master Mar 5, 2026
17 checks passed
@soininen soininen deleted the toolbox_1892_import_descriptions branch March 5, 2026 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant