Skip to content

Commit d33c2df

Browse files
committed
fix: two small bugs of the thickness and basal contacts tools
- extract_basal_contacts had a mutable default (ignore_units=[]) and added None to it, so the list grew at each call. It also changed the list of the caller. Use None and a new list. - The thickness algorithm read MAX_LINE_LENGTH with parameterAsSource, so StructuralPoint always got None. Use parameterAsDouble.
1 parent 5cd2a60 commit d33c2df

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

‎loopstructural/main/m2l_api.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def extract_basal_contacts(
249249
geology,
250250
stratigraphic_order,
251251
faults=None,
252-
ignore_units=[],
252+
ignore_units=None,
253253
unit_name_field=None,
254254
all_contacts=False,
255255
updater=None,
@@ -320,7 +320,8 @@ def extract_basal_contacts(
320320
geology = geology.drop(columns=['UNITNAME'])
321321
geology = geology.rename(columns={unit_name_field: 'UNITNAME'})
322322
# Log parameters via DebugManager if provided
323-
ignore_units += [None]
323+
# a new list: do not change the list of the caller
324+
ignore_units = list(ignore_units or []) + [None]
324325

325326
# Units in the geology layer that are not in the stratigraphic column are
326327
# kept in the geology (so they still bound the other units and appear in

‎loopstructural/processing/algorithms/thickness_calculator.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def processAlgorithm(
260260
thickness_type = ['InterpolatedStructure', 'StructuralPoint'][thickness_type_index]
261261
dtm_data = self.parameterAsRasterLayer(parameters, self.INPUT_DTM, context)
262262
bounding_box_type = self.parameterAsEnum(parameters, self.INPUT_BOUNDING_BOX_TYPE, context)
263-
max_line_length = self.parameterAsSource(parameters, self.INPUT_MAX_LINE_LENGTH, context)
263+
max_line_length = self.parameterAsDouble(parameters, self.INPUT_MAX_LINE_LENGTH, context)
264264
basal_contacts = self.parameterAsSource(parameters, self.INPUT_BASAL_CONTACTS, context)
265265
geology_source = self.parameterAsSource(parameters, self.INPUT_GEOLOGY, context)
266266
if geology_source is None:

‎tests/qgis/test_basal_contacts.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import inspect
12
import unittest
23
from pathlib import Path
34
from unittest.mock import patch
@@ -222,6 +223,20 @@ def test_extraction_error_is_raised(self):
222223
with self.assertRaisesRegex(RuntimeError, 'bad geology'):
223224
self._extract(['A', 'B', 'C'])
224225

226+
def test_the_list_of_ignored_units_does_not_change(self):
227+
ignore_units = ['D']
228+
for _ in range(2):
229+
extract_basal_contacts(
230+
geology=self._geology(),
231+
stratigraphic_order=['A', 'B', 'C'],
232+
ignore_units=ignore_units,
233+
unit_name_field='unitname',
234+
)
235+
self.assertEqual(ignore_units, ['D'])
236+
# the default is not a shared list that grows at each call
237+
default = inspect.signature(extract_basal_contacts).parameters['ignore_units'].default
238+
self.assertIsNone(default)
239+
225240

226241
if __name__ == '__main__':
227242
unittest.main()

0 commit comments

Comments
 (0)