From 5414fb3874537e15e42a92b302c8020752176d29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Morais?= <146729917+SMoraisAnsys@users.noreply.github.com> Date: Fri, 17 Jan 2025 17:43:20 +0100 Subject: [PATCH] FIX: Load numpy lazily (#5673) --- src/ansys/aedt/core/q3d.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/ansys/aedt/core/q3d.py b/src/ansys/aedt/core/q3d.py index 07179efffd2..8db17adf34d 100644 --- a/src/ansys/aedt/core/q3d.py +++ b/src/ansys/aedt/core/q3d.py @@ -42,15 +42,6 @@ from ansys.aedt.core.modules.boundary.q3d_boundary import Matrix from ansys.aedt.core.modules.setup_templates import SetupKeys -try: - import numpy as np -except ImportError: # pragma: no cover - warnings.warn( - "The NumPy module is required to use functionalities provided by the module ansys.edt.core.q3d.\n" - "Install with \n\npip install numpy" - ) - np = None - class QExtractor(FieldAnalysis3D, object): """Extracts a 2D or 3D field analysis. @@ -1944,6 +1935,8 @@ def set_material_thresholds( ``True`` when successful, ``False`` when failed. """ try: + import numpy as np + if not insulator_threshold: insulator_threshold = 10000 if not perfect_conductor_threshold: @@ -1962,6 +1955,11 @@ def set_material_thresholds( self.oboundary.SetMaterialThresholds(insulator_threshold, perfect_conductor_threshold, magnetic_threshold) return True + except ImportError: # pragma: no cover + warnings.warn( + "The NumPy module is required to use functionalities provided by the module ansys.edt.core.q3d.\n" + "Install with \n\npip install numpy" + ) except Exception: return False