From e7160f6a848e8bf7629a6ec8bf89b35065f54010 Mon Sep 17 00:00:00 2001 From: benjamink Date: Tue, 6 Aug 2024 12:15:26 -0700 Subject: [PATCH 1/2] Handle and test numeric well names --- las_geoh5/import_las.py | 2 ++ tests/import_las_test.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/las_geoh5/import_las.py b/las_geoh5/import_las.py index 550213e..a54ade5 100644 --- a/las_geoh5/import_las.py +++ b/las_geoh5/import_las.py @@ -309,6 +309,8 @@ def create_or_append_drillhole( translator = LASTranslator(NameOptions()) name = translator.retrieve("well_name", lasfile) + if not isinstance(name, str): + name = str(name) if not name and logger is not None: logger.warning( "No well name provided for LAS file. " diff --git a/tests/import_las_test.py b/tests/import_las_test.py index 6bed4e5..87a6672 100644 --- a/tests/import_las_test.py +++ b/tests/import_las_test.py @@ -415,3 +415,35 @@ def test_warning_no_well_name(tmp_path: Path, caplog): ) assert match in caplog.text + + +def test_handle_numeric_well_name(tmp_path: Path): + with Workspace.create(tmp_path / "test.geoh5") as workspace: + dh_group = DrillholeGroup.create(workspace, name="dh_group") + + lasfile = generate_lasfile( + "123", + {"UTMX": 0.0, "UTMY": 0.0, "ELEV": 10.0}, + np.arange(0, 11, 1), + {"my_property": np.zeros(11)}, + ) + lasfile = write_lasfile(tmp_path, lasfile) + + filepath = write_import_params_file( + tmp_path / "import_las_files.ui.json", + dh_group, + "my_property_group", + [lasfile], + ( + "UTMX", + "UTMY", + "ELEV", + ), + ) + + module = importlib.import_module("las_geoh5.import_files.driver") + module.run(filepath) + + with workspace.open(): + dh_group = workspace.get_entity("dh_group")[0] + assert "123" in [k.name for k in dh_group.children] From 3e377652512d404797488649dd5ac229bb764380 Mon Sep 17 00:00:00 2001 From: benjamink Date: Tue, 6 Aug 2024 14:54:49 -0700 Subject: [PATCH 2/2] pylint --- tests/script_las_to_geoh5_test.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/script_las_to_geoh5_test.py b/tests/script_las_to_geoh5_test.py index e7a1d1f..13a7f0a 100644 --- a/tests/script_las_to_geoh5_test.py +++ b/tests/script_las_to_geoh5_test.py @@ -19,6 +19,7 @@ from .helpers import generate_lasfile, write_import_params_file, write_lasfile +# pylint: disable=duplicate-code @pytest.fixture(scope="module", name="lasfile") def lasfile_fixture(tmp_path_factory) -> Path: input_dir = tmp_path_factory.mktemp("input") @@ -75,6 +76,7 @@ def test_las_to_geoh5_without_output_name( """Test the las_to_geoh5 script.""" workspace_file = input_workspace.h5file + assert isinstance(workspace_file, Path) modified_date = workspace_file.stat().st_mtime with patch("sys.argv", ["las_to_geoh5", str(params_filepath)]): @@ -93,6 +95,7 @@ def test_las_to_geoh5_with_monitoring_folder( """Test the las_to_geoh5 script.""" workspace_file = input_workspace.h5file + assert isinstance(workspace_file, Path) modified_date = workspace_file.stat().st_mtime monitoring_folder = tmp_path / "monitored here" @@ -124,6 +127,7 @@ def test_las_to_geoh5_with_output_name( """Test the las_to_geoh5 script.""" workspace_file = input_workspace.h5file + assert isinstance(workspace_file, Path) modified_date = workspace_file.stat().st_mtime working_dir = tmp_path / "working" @@ -150,6 +154,7 @@ def test_las_to_geoh5_with_absolute_output_path( """Test the las_to_geoh5 script.""" workspace_file = input_workspace.h5file + assert isinstance(workspace_file, Path) modified_date = workspace_file.stat().st_mtime output_dir = tmp_path / "output"