Skip to content

[ENH] Raise a descriptive error for unknown structural element names - #1110

Open
manduinca wants to merge 1 commit into
gempy-project:mainfrom
manduinca:fix-904-unknown-element-names
Open

manduinca wants to merge 1 commit into
gempy-project:mainfrom
manduinca:fix-904-unknown-element-names

Conversation

@manduinca

Copy link
Copy Markdown

Description

create_geomodel reads the orientations with the name_id_map built from the surface points, so a formation name that only appears in the orientations file (a typo, or a translated name as in the report) fails with a bare KeyError: 'Shael' from the id lookup. Nothing says which names were expected or that the two files have to agree.

The lookups in SurfacePointsTable.from_arrays, OrientationsTable.from_arrays and generate_ids_from_names (also used by MicroPointsTable) now go through one helper that raises:

ValueError: Unknown structural element name(s) ['Shael']. Available names: ['Sandstone', 'Shale']. Names must match exactly between surface points, orientations and name_id_map.

Valid input takes the same path as before: the comprehension runs inside a try, and the names are only scanned again after the KeyError, so there is no extra work, memory or state on the normal path.

Tests go in test_community_bugs.py: one runs create_geomodel on two CSVs that reproduce the report, the other calls from_arrays directly with a user name_id_map. Both fail on main with the KeyError.

Locally, test_core, test_api, test_modules, test_model_types and test_community_bugs give 122 passed and 3 skipped: the same 120 that pass on main, plus the two new tests.

Fixes #904

Checklist

  • My code uses type hinting for function and method arguments and return values.
  • I have created tests which cover my code.
  • The test code either 1. demonstrates at least one valuable use case (e.g. integration tests)
    or 2. verifies that outputs are as expected for given inputs (e.g. unit tests).
  • New tests pass locally with my changes.

A formation name missing from name_id_map (for instance a typo in the
orientations file read by create_geomodel) used to surface as a bare
KeyError with just the name. The id lookups now raise a ValueError that
lists the unknown names and the available ones. Valid input follows the
same path as before.

This branch has not been deployed

No deployments
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.

[ENH] Improve Error Handling when formation names are not identical

1 participant