Skip to content

Commit 9207e79

Browse files
committed
fix(loop_link): drop a referenced property with an unmapped code
The real viewer sends text columns of an imported drillhole as referenced data with an empty value map. A fetch of such a hole failed. The fetch now drops the property and warns. M3 manual check results added to the record. Claude-Session: https://claude.ai/code/session_01XADRvLYYZrrcx9Nu8e5tgs
1 parent 61cbffa commit 9207e79

3 files changed

Lines changed: 43 additions & 11 deletions

File tree

‎packages/loop_link/src/loop_link/fetch.py‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ def _decode_text(desc: Mapping[str, Any], arrays: Mapping[str, np.ndarray]) -> n
115115
return np.array(items, dtype=str)
116116

117117

118+
class _UnmappedCodeError(Exception):
119+
"""A code of a referenced property is not in its value map."""
120+
121+
118122
def _decode_referenced(
119123
desc: Mapping[str, Any], arrays: Mapping[str, np.ndarray], object_id: str
120124
) -> Categorical:
@@ -134,10 +138,7 @@ def _decode_referenced(
134138
positions = np.searchsorted(ids, raw)
135139
safe = np.minimum(positions, max(len(ids) - 1, 0))
136140
if raw.size and (len(ids) == 0 or not np.all(ids[safe] == raw)):
137-
raise InvalidInputError(
138-
f"The property '{desc['name']}' of object '{object_id}' has a code that is not "
139-
"in its value map. Check the object in the viewer."
140-
)
141+
raise _UnmappedCodeError
141142
return Categorical(positions, names, colours)
142143

143144

@@ -236,13 +237,12 @@ def decode_object(
236237
------
237238
UnsupportedObjectError
238239
If the object type is not supported, or a cell property is on a Points object.
239-
InvalidInputError
240-
If a code of a referenced property is not in its value map.
241240
242241
Warns
243242
-----
244243
UserWarning
245-
One time for each property that the function drops.
244+
One time for each property that the function drops. This includes a
245+
referenced property that has a code that is not in its value map.
246246
"""
247247
object_id = str(header.get("id"))
248248
object_type = str(header.get("object_type"))
@@ -279,7 +279,14 @@ def geo(role: str) -> np.ndarray:
279279
continue
280280
target = _route(desc, object_type, object_id, interval_set)
281281
if target is not None:
282-
targets[target][str(desc["name"])] = _decode_values(desc, arrays, object_id)
282+
try:
283+
targets[target][str(desc["name"])] = _decode_values(desc, arrays, object_id)
284+
except _UnmappedCodeError:
285+
_warn_dropped(
286+
str(desc["name"]),
287+
object_id,
288+
"a code is not in its value map",
289+
)
283290

284291
if object_type == "Drillhole":
285292
end_of_hole = params.get("end_of_hole")

‎packages/loop_link/tests/manual_checks.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,17 @@ Pass: all 8 steps give the expected result.
119119
- Tetra mesh `grade` works through the isosurface. The viewer has no Data button for a tetra mesh.
120120
- Vectors were too small to see on a 1 unit triangle (glyph size default is 1 percent of the object). They work on a 100 unit triangle.
121121
- Open viewer issue: the vector glyphs and the drillhole tubes look pixelated (geoviewer issue 181).
122+
- M3: partly passed on 2026-11-07, window viewer `ui-fixes-build`, token from the user. A person did steps 2 and 7. The scripts did the other steps.
123+
- Step 1 pass: select cells 12, 13 and 14 and `selection()` returns them. The first try failed. The scene had objects at map coordinates (origin 500000, 7000000) and the test block was at (0, 0, 0). The viewer showed rendering artefacts and `selection.get` returned nothing. After a fresh scene (`clear`), it worked. Put a test object near the scene origin, or use a fresh scene.
124+
- Step 2 pass: the user selected 11 rows with the mouse. `selection()` returned `m3-block`, revision 2, cells `[1, 2, 3, 4, 5, 6, 7, 8, 9, 45, 302]`.
125+
- Step 3 pass: index 5000 gives `InvalidInputError`. The selection does not change.
126+
- Step 4 pass: an old revision gives `StaleRevisionError`.
127+
- Step 5 pass: all seven types fetch with the `grade` property.
128+
- Step 6 partly passed: see the fix below. The warning for dropped properties works. The warning for dropped log sets was not seen, because the imported holes seem to have one log set.
129+
- Step 7 not decided: the callback ran 4 times, once for each different selection, with no repeats. The record does not say how many changes the user made.
130+
- Step 8 partly passed: the first program selected and fetched while a second program held the data connection. A real `BusyError` was not tested.
131+
- OP12: points and vectors take vertices only. Lines, surface, block model and tetra mesh take cells. A drillhole takes neither kind (no table tab).
132+
- OP13: one object has a selection at a time. A new selection on another object replaces the old one.
133+
- OP14: a fetch of 1,000,000 cells took 0.07 s and arrived complete. Several parts were not tested directly.
134+
- Fix: a viewer-imported drillhole (`import-1/0`) failed to fetch. Text columns such as `COMMENTS` come as `referenced` data with an empty `value_map`. `loop_link` now drops such a property and warns. A fetch takes about 1.8 s for a hole with about 100 properties.
135+
- Open viewer gap: a tool cannot select drillhole intervals or holes. A new geoviewer spec is needed.

‎packages/loop_link/tests/test_fetch.py‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,22 @@ def test_referenced_three_value_colours_get_alpha_255():
389389
assert value.colours == ((40, 50, 60, 70), (10, 20, 30, 255), (80, 90, 100, 255))
390390

391391

392-
def test_referenced_code_not_in_value_map_raises():
392+
def test_referenced_code_not_in_value_map_is_dropped_with_warning():
393393
header, arrays = _sparse_referenced()
394394
arrays["data/c"] = np.array([9, 5, 7], dtype=np.uint32)
395-
with pytest.raises(InvalidInputError):
396-
decode_object(header, arrays, ORIGIN)
395+
with pytest.warns(UserWarning, match="'c'.*value map"):
396+
result = decode_object(header, arrays, ORIGIN)
397+
assert "c" not in result.properties
398+
399+
400+
def test_referenced_with_empty_value_map_is_dropped():
401+
"""The real viewer sends an all blank text column as codes 0 and an empty value map."""
402+
header, arrays = _sparse_referenced()
403+
_datum(header, "c")["value_map"] = []
404+
arrays["data/c"] = np.array([0, 0, 0], dtype=np.uint32)
405+
with pytest.warns(UserWarning, match="'c'.*value map"):
406+
result = decode_object(header, arrays, ORIGIN)
407+
assert "c" not in result.properties
397408

398409

399410
def test_referenced_on_drillhole_interval():

0 commit comments

Comments
 (0)