From 53cf4862a1eaf0031c5a178f50043e71be17c8ee Mon Sep 17 00:00:00 2001 From: Helene Lachambre Date: Mon, 19 May 2025 12:13:51 +0200 Subject: [PATCH 01/12] feat: allow giving a name to a dimensionless unit (eg: sones) --- src/ansys/dpf/core/field.py | 23 +++++++++++++++++++++++ src/ansys/dpf/core/field_definition.py | 11 +++++++++++ tests/test_field.py | 19 ++++++++++++++++++- 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/ansys/dpf/core/field.py b/src/ansys/dpf/core/field.py index c4a05dc9411..e5669a8e8d4 100644 --- a/src/ansys/dpf/core/field.py +++ b/src/ansys/dpf/core/field.py @@ -640,6 +640,29 @@ def unit(self, value): fielddef.unit = value self.field_definition = fielddef + def set_named_dimensionless_unit(self, value): + """Set a named dimensionless unit for the field. + + Parameters + ---------- + value : str + Units for the field. This unit must be homogeneous to no physical quantity + + Examples + -------- + Units for a psychoacoustics field. + + >>> from ansys.dpf import core as dpf + >>> my_field = dpf.Field(10) + >>> my_field.set_named_dimensionless_unit("sones") + >>> print(my_field.unit) + sones + + """ + fielddef = self.field_definition + fielddef.set_named_dimensionless_unit(value) + self.field_definition = fielddef + @property def dimensionality(self): """Dimensionality represents the shape of the elementary data contained in the field. diff --git a/src/ansys/dpf/core/field_definition.py b/src/ansys/dpf/core/field_definition.py index 2271c469f13..aa5defffef9 100644 --- a/src/ansys/dpf/core/field_definition.py +++ b/src/ansys/dpf/core/field_definition.py @@ -207,6 +207,17 @@ def is_of_quantity_type(self, quantity_type): def unit(self, value): self._api.csfield_definition_set_unit(self, value, None, 0, 0, 0) + def set_named_dimensionless_unit(self, value): + """Set a named dimensionless unit for the field. + + Parameters + ---------- + value : str + Units for the field. This unit must be homogeneous to no physical quantity + """ + # 117 corresponds to dimensionless + self._api.csfield_definition_set_unit(self, value, None, 117, 0, 0) + @location.setter def location(self, value): self._api.csfield_definition_set_location(self, value) diff --git a/tests/test_field.py b/tests/test_field.py index fa77deec0b9..ee56db2bb37 100644 --- a/tests/test_field.py +++ b/tests/test_field.py @@ -32,7 +32,11 @@ from ansys.dpf.core.check_version import server_meet_version from ansys.dpf.core.common import locations, shell_layers import conftest -from conftest import SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0, running_docker +from conftest import ( + SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0, + SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_10_0, + running_docker, +) @pytest.fixture() @@ -1417,3 +1421,16 @@ def test_deep_copy_big_field_remote(server_type, server_type_remote_process): out = dpf.core.core._deep_copy(field_a, server_type_remote_process) assert np.allclose(out.data, data) + + +@pytest.mark.skipif( + not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_10_0, reason="Available for servers >=10.0" +) +def test_set_named_dimensionless_units(): + data = np.random.random(100) + field = dpf.core.field_from_array(data) + field.unit = "m" + assert field.unit == "m" + + field.set_named_dimensionless_unit("sones") + assert field.unit == "sones" From ea3a85632eecb5c9ad3d87b332c18a0f17d64a8c Mon Sep 17 00:00:00 2001 From: Helene Lachambre Date: Wed, 21 May 2025 15:14:55 +0200 Subject: [PATCH 02/12] feat: remove set_named_dimensionless_unit. Replace it by an extension of unit setter to allow tuple as parameter --- src/ansys/dpf/core/field.py | 30 ++++++++++---------------- src/ansys/dpf/core/field_definition.py | 22 +++++++++---------- tests/entry/conftest.py | 3 +++ tests/test_field.py | 7 ++++-- 4 files changed, 29 insertions(+), 33 deletions(-) diff --git a/src/ansys/dpf/core/field.py b/src/ansys/dpf/core/field.py index e5669a8e8d4..bbf45c18f6f 100644 --- a/src/ansys/dpf/core/field.py +++ b/src/ansys/dpf/core/field.py @@ -620,9 +620,15 @@ def unit(self): def unit(self, value): """Change the unit for the field. + If the value is a single string, then it will be interpreted to a physical meaning (homogeneity). + + If the value is a tuple, then it must contain an homogeneity and a string. + If homogeneity is "dimensionless", then the unit string is kept as is. + Otherwise, homogeneity is ignored, and unit string is interpreted to a physical meaning. + Parameters ---------- - value : str + value : str | tuple(str, str) Units for the field. Examples @@ -635,32 +641,18 @@ def unit(self, value): >>> my_field.unit 'm' - """ - fielddef = self.field_definition - fielddef.unit = value - self.field_definition = fielddef - def set_named_dimensionless_unit(self, value): - """Set a named dimensionless unit for the field. - - Parameters - ---------- - value : str - Units for the field. This unit must be homogeneous to no physical quantity - - Examples - -------- - Units for a psychoacoustics field. + Named dimensionless unit. >>> from ansys.dpf import core as dpf >>> my_field = dpf.Field(10) - >>> my_field.set_named_dimensionless_unit("sones") + >>> my_field.unit = ("dimensionless", "dollars") >>> print(my_field.unit) - sones + 'dollars' """ fielddef = self.field_definition - fielddef.set_named_dimensionless_unit(value) + fielddef.unit = value self.field_definition = fielddef @property diff --git a/src/ansys/dpf/core/field_definition.py b/src/ansys/dpf/core/field_definition.py index aa5defffef9..276be9d472a 100644 --- a/src/ansys/dpf/core/field_definition.py +++ b/src/ansys/dpf/core/field_definition.py @@ -205,18 +205,16 @@ def is_of_quantity_type(self, quantity_type): @unit.setter def unit(self, value): - self._api.csfield_definition_set_unit(self, value, None, 0, 0, 0) - - def set_named_dimensionless_unit(self, value): - """Set a named dimensionless unit for the field. - - Parameters - ---------- - value : str - Units for the field. This unit must be homogeneous to no physical quantity - """ - # 117 corresponds to dimensionless - self._api.csfield_definition_set_unit(self, value, None, 117, 0, 0) + # setter with explicit homogeneity: homogeneity is taken into account if it is dimensionless + if isinstance(value, tuple): + if value[0] == "dimensionless": + # 117 corresponds to dimensionless + self._api.csfield_definition_set_unit(self, value[1], None, 117, 0, 0) + else: + self._api.csfield_definition_set_unit(self, value[1], None, 0, 0, 0) + # standard unit setter, using string interpreter + else: + self._api.csfield_definition_set_unit(self, value, None, 0, 0, 0) @location.setter def location(self, value): diff --git a/tests/entry/conftest.py b/tests/entry/conftest.py index 01e1a0bf70a..5409d3df9f5 100644 --- a/tests/entry/conftest.py +++ b/tests/entry/conftest.py @@ -71,6 +71,9 @@ def _get_test_files_directory(): "/tmp/test_files" ) +SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_10_0 = meets_version( + get_server_version(core._global_server()), "10.0" +) SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_1 = meets_version( get_server_version(core._global_server()), "8.1" ) diff --git a/tests/test_field.py b/tests/test_field.py index ee56db2bb37..43b50141907 100644 --- a/tests/test_field.py +++ b/tests/test_field.py @@ -1426,11 +1426,14 @@ def test_deep_copy_big_field_remote(server_type, server_type_remote_process): @pytest.mark.skipif( not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_10_0, reason="Available for servers >=10.0" ) -def test_set_named_dimensionless_units(): +def test_set_units(): data = np.random.random(100) field = dpf.core.field_from_array(data) field.unit = "m" assert field.unit == "m" - field.set_named_dimensionless_unit("sones") + field.unit = ("dimensionless", "sones") assert field.unit == "sones" + + with pytest.raises(Exception): + field.unit = "sones" From 7cb7a462dd13921b09ea8f5f2e750d8d20adadc3 Mon Sep 17 00:00:00 2001 From: Helene Lachambre Date: Thu, 22 May 2025 11:19:04 +0200 Subject: [PATCH 03/12] feat: use Homogeneity enum. Rework documentation --- src/ansys/dpf/core/field.py | 13 +++++++------ src/ansys/dpf/core/field_definition.py | 22 +++++++++++++++------- tests/test_field.py | 14 ++++++++++++-- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/ansys/dpf/core/field.py b/src/ansys/dpf/core/field.py index bbf45c18f6f..5eb59ca65dd 100644 --- a/src/ansys/dpf/core/field.py +++ b/src/ansys/dpf/core/field.py @@ -620,15 +620,15 @@ def unit(self): def unit(self, value): """Change the unit for the field. - If the value is a single string, then it will be interpreted to a physical meaning (homogeneity). + A single string is interpreted as a known physical unit with an associated homogeneity. - If the value is a tuple, then it must contain an homogeneity and a string. - If homogeneity is "dimensionless", then the unit string is kept as is. - Otherwise, homogeneity is ignored, and unit string is interpreted to a physical meaning. + A tuple of two strings is interpreted as a homogeneity and a unit name. + If the homogeneity is Homogeneity.dimensionless, then the unit string is kept as a name. + Otherwise, the homogeneity is ignored, and the unit string is interpreted as a known physical unit with an associated homogeneity. Parameters ---------- - value : str | tuple(str, str) + value : str | tuple(Homogeneity, str) Units for the field. Examples @@ -645,8 +645,9 @@ def unit(self, value): Named dimensionless unit. >>> from ansys.dpf import core as dpf + >>> from ansys.dpf.core.available_result import Homogeneity >>> my_field = dpf.Field(10) - >>> my_field.unit = ("dimensionless", "dollars") + >>> my_field.unit = (Homogeneity.dimensionless, "dollars") >>> print(my_field.unit) 'dollars' diff --git a/src/ansys/dpf/core/field_definition.py b/src/ansys/dpf/core/field_definition.py index 276be9d472a..e8c4ed6382f 100644 --- a/src/ansys/dpf/core/field_definition.py +++ b/src/ansys/dpf/core/field_definition.py @@ -22,10 +22,12 @@ """FieldDefinition.""" +from argparse import ArgumentError import traceback import warnings from ansys.dpf.core import server as server_module +from ansys.dpf.core.available_result import Homogeneity from ansys.dpf.core.check_version import version_requires from ansys.dpf.core.common import natures, shell_layers from ansys.dpf.core.dimensionality import Dimensionality @@ -206,15 +208,21 @@ def is_of_quantity_type(self, quantity_type): @unit.setter def unit(self, value): # setter with explicit homogeneity: homogeneity is taken into account if it is dimensionless - if isinstance(value, tuple): - if value[0] == "dimensionless": - # 117 corresponds to dimensionless - self._api.csfield_definition_set_unit(self, value[1], None, 117, 0, 0) - else: - self._api.csfield_definition_set_unit(self, value[1], None, 0, 0, 0) + if ( + isinstance(value, tuple) + and len(value) == 2 + and isinstance(value[0], Homogeneity) + and isinstance(value[1], str) + ): + # csfield_definition_set_unit will ignore the homogeneity if it is not dimensionless + self._api.csfield_definition_set_unit(self, value[1], None, value[0].value, 0, 0) # standard unit setter, using string interpreter - else: + elif isinstance(value, str): self._api.csfield_definition_set_unit(self, value, None, 0, 0, 0) + else: + raise ArgumentError( + None, message="Unit setter supports either string or tuple(Homogeneity, str)" + ) @location.setter def location(self, value): diff --git a/tests/test_field.py b/tests/test_field.py index 43b50141907..c679c2523d3 100644 --- a/tests/test_field.py +++ b/tests/test_field.py @@ -20,6 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +from argparse import ArgumentError import copy import gc @@ -29,8 +30,10 @@ from ansys import dpf from ansys.dpf import core from ansys.dpf.core import FieldDefinition, operators as ops +from ansys.dpf.core.available_result import Homogeneity from ansys.dpf.core.check_version import server_meet_version from ansys.dpf.core.common import locations, shell_layers +from ansys.dpf.gate.errors import DPFServerException import conftest from conftest import ( SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0, @@ -1429,11 +1432,18 @@ def test_deep_copy_big_field_remote(server_type, server_type_remote_process): def test_set_units(): data = np.random.random(100) field = dpf.core.field_from_array(data) + # use string setter with recognized string field.unit = "m" assert field.unit == "m" - field.unit = ("dimensionless", "sones") + # use tuple(Homogeneity, string) setter + field.unit = (Homogeneity.dimensionless, "sones") assert field.unit == "sones" - with pytest.raises(Exception): + # use unrecognized string + with pytest.raises(DPFServerException): field.unit = "sones" + + # use wrong type of arguments + with pytest.raises(ArgumentError): + field.unit = 1.0 From 7043f9cfd9478dc7fce3a71b6955e37dde324085 Mon Sep 17 00:00:00 2001 From: Paul Profizi <100710998+PProfizi@users.noreply.github.com> Date: Fri, 23 May 2025 15:35:28 +0200 Subject: [PATCH 04/12] Fix version criterion for test and feature --- tests/entry/conftest.py | 4 ++-- tests/test_field.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/entry/conftest.py b/tests/entry/conftest.py index 5409d3df9f5..f5e7f9e49cf 100644 --- a/tests/entry/conftest.py +++ b/tests/entry/conftest.py @@ -71,8 +71,8 @@ def _get_test_files_directory(): "/tmp/test_files" ) -SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_10_0 = meets_version( - get_server_version(core._global_server()), "10.0" +SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_11_0 = meets_version( + get_server_version(core._global_server()), "11.0" ) SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_1 = meets_version( get_server_version(core._global_server()), "8.1" diff --git a/tests/test_field.py b/tests/test_field.py index c679c2523d3..cc1d1ddf4d2 100644 --- a/tests/test_field.py +++ b/tests/test_field.py @@ -37,7 +37,7 @@ import conftest from conftest import ( SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0, - SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_10_0, + SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_11_0, running_docker, ) @@ -1427,7 +1427,7 @@ def test_deep_copy_big_field_remote(server_type, server_type_remote_process): @pytest.mark.skipif( - not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_10_0, reason="Available for servers >=10.0" + not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_11_0, reason="Available for servers >=11.0" ) def test_set_units(): data = np.random.random(100) From cc2500935aa91e48f619ec49b67fbd5b23a5714f Mon Sep 17 00:00:00 2001 From: PProfizi Date: Wed, 28 May 2025 15:11:16 +0200 Subject: [PATCH 05/12] Raise for version too low --- src/ansys/dpf/core/field.py | 21 ++++++++++++------- src/ansys/dpf/core/field_definition.py | 29 ++++++++++++++++++++++++-- tests/conftest.py | 3 +++ tests/entry/conftest.py | 3 --- tests/test_field.py | 19 ++++++++++------- 5 files changed, 54 insertions(+), 21 deletions(-) diff --git a/src/ansys/dpf/core/field.py b/src/ansys/dpf/core/field.py index 5eb59ca65dd..e65d2af6e47 100644 --- a/src/ansys/dpf/core/field.py +++ b/src/ansys/dpf/core/field.py @@ -30,6 +30,7 @@ from ansys import dpf from ansys.dpf.core import dimensionality, errors, meshed_region, scoping, time_freq_support +from ansys.dpf.core.available_result import Homogeneity from ansys.dpf.core.common import ( _get_size_of_list, locations, @@ -617,18 +618,18 @@ def unit(self): return self.field_definition.unit @unit.setter - def unit(self, value): + def unit(self, value: str | tuple[Homogeneity, str]): """Change the unit for the field. A single string is interpreted as a known physical unit with an associated homogeneity. - A tuple of two strings is interpreted as a homogeneity and a unit name. - If the homogeneity is Homogeneity.dimensionless, then the unit string is kept as a name. - Otherwise, the homogeneity is ignored, and the unit string is interpreted as a known physical unit with an associated homogeneity. + For DPF 11.0 (2026 R1) and above: A tuple of two strings is interpreted as a homogeneity and a unit name. + If the homogeneity is :py:attr:`Homogeneity.dimensionless`, then the unit string is kept as a name. + Otherwise, the homogeneity is ignored, and the unit string interpreted as a known physical unit with an associated homogeneity. Parameters ---------- - value : str | tuple(Homogeneity, str) + value: Units for the field. Examples @@ -651,10 +652,14 @@ def unit(self, value): >>> print(my_field.unit) 'dollars' + Notes + ----- + Setting a named dimensionless unit requires DPF 11.0 (2026 R1) or above. + """ - fielddef = self.field_definition - fielddef.unit = value - self.field_definition = fielddef + field_def = self.field_definition + field_def.unit = value + self.field_definition = field_def @property def dimensionality(self): diff --git a/src/ansys/dpf/core/field_definition.py b/src/ansys/dpf/core/field_definition.py index e8c4ed6382f..78c0fe18dfa 100644 --- a/src/ansys/dpf/core/field_definition.py +++ b/src/ansys/dpf/core/field_definition.py @@ -22,13 +22,15 @@ """FieldDefinition.""" +from __future__ import annotations + from argparse import ArgumentError import traceback import warnings from ansys.dpf.core import server as server_module from ansys.dpf.core.available_result import Homogeneity -from ansys.dpf.core.check_version import version_requires +from ansys.dpf.core.check_version import server_meet_version_and_raise, version_requires from ansys.dpf.core.common import natures, shell_layers from ansys.dpf.core.dimensionality import Dimensionality from ansys.dpf.gate import ( @@ -206,7 +208,25 @@ def is_of_quantity_type(self, quantity_type): return is_of_quantity_type @unit.setter - def unit(self, value): + def unit(self, value: str | tuple[Homogeneity, str]): + """Change the unit for the field definition. + + A single string is interpreted as a known physical unit with an associated homogeneity. + + For DPF 11.0 (2026 R1) and above: A tuple of two strings is interpreted as a homogeneity and a unit name. + If the homogeneity is :py:attr:`Homogeneity.dimensionless`, then the unit string is kept as a name. + Otherwise, the homogeneity is ignored, and the unit string interpreted as a known physical unit with an associated homogeneity. + + Parameters + ---------- + value: + Units for the field. + + Notes + ----- + Setting a named dimensionless unit requires DPF 11.0 (2026 R1) or above. + + """ # setter with explicit homogeneity: homogeneity is taken into account if it is dimensionless if ( isinstance(value, tuple) @@ -214,6 +234,11 @@ def unit(self, value): and isinstance(value[0], Homogeneity) and isinstance(value[1], str) ): + server_meet_version_and_raise( + required_version="11.0", + server=self._server, + msg="Setting a named dimensionless unit requires DPF 11.0 (2026 R1) or above.", + ) # csfield_definition_set_unit will ignore the homogeneity if it is not dimensionless self._api.csfield_definition_set_unit(self, value[1], None, value[0].value, 0, 0) # standard unit setter, using string interpreter diff --git a/tests/conftest.py b/tests/conftest.py index 634396aee91..f241ee23aa4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -329,6 +329,9 @@ def return_ds(server=None): return return_ds +SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_11_0 = meets_version( + get_server_version(core._global_server()), "11.0" +) SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_10_0 = meets_version( get_server_version(core._global_server()), "10.0" ) diff --git a/tests/entry/conftest.py b/tests/entry/conftest.py index f5e7f9e49cf..01e1a0bf70a 100644 --- a/tests/entry/conftest.py +++ b/tests/entry/conftest.py @@ -71,9 +71,6 @@ def _get_test_files_directory(): "/tmp/test_files" ) -SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_11_0 = meets_version( - get_server_version(core._global_server()), "11.0" -) SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_1 = meets_version( get_server_version(core._global_server()), "8.1" ) diff --git a/tests/test_field.py b/tests/test_field.py index cc1d1ddf4d2..e6984067bdf 100644 --- a/tests/test_field.py +++ b/tests/test_field.py @@ -33,11 +33,12 @@ from ansys.dpf.core.available_result import Homogeneity from ansys.dpf.core.check_version import server_meet_version from ansys.dpf.core.common import locations, shell_layers -from ansys.dpf.gate.errors import DPFServerException +from ansys.dpf.gate.errors import DPFServerException, DpfVersionNotSupported import conftest from conftest import ( SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0, SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_11_0, + raises_for_servers_version_under, running_docker, ) @@ -1426,19 +1427,21 @@ def test_deep_copy_big_field_remote(server_type, server_type_remote_process): assert np.allclose(out.data, data) -@pytest.mark.skipif( - not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_11_0, reason="Available for servers >=11.0" -) -def test_set_units(): +def test_set_units(server_type): data = np.random.random(100) field = dpf.core.field_from_array(data) # use string setter with recognized string field.unit = "m" assert field.unit == "m" - # use tuple(Homogeneity, string) setter - field.unit = (Homogeneity.dimensionless, "sones") - assert field.unit == "sones" + if server_meet_version("11.0", server_type): + # use tuple(Homogeneity, string) setter + field.unit = (Homogeneity.dimensionless, "sones") + assert field.unit == "sones" + else: + with pytest.raises(DpfVersionNotSupported): + # use tuple(Homogeneity, string) setter + field.unit = (Homogeneity.dimensionless, "sones") # use unrecognized string with pytest.raises(DPFServerException): From 82f68adeccd5687f74d051fbd12b8c36675be821 Mon Sep 17 00:00:00 2001 From: Paul Profizi <100710998+PProfizi@users.noreply.github.com> Date: Mon, 2 Jun 2025 09:48:50 +0200 Subject: [PATCH 06/12] Fix QA --- tests/conftest.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index f241ee23aa4..634396aee91 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -329,9 +329,6 @@ def return_ds(server=None): return return_ds -SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_11_0 = meets_version( - get_server_version(core._global_server()), "11.0" -) SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_10_0 = meets_version( get_server_version(core._global_server()), "10.0" ) From 512f48b2cc1f6969965628c596a5ba6709b76ae9 Mon Sep 17 00:00:00 2001 From: Paul Profizi <100710998+PProfizi@users.noreply.github.com> Date: Mon, 2 Jun 2025 10:13:29 +0200 Subject: [PATCH 07/12] Fix QA --- tests/test_field.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_field.py b/tests/test_field.py index e6984067bdf..8576e94f41a 100644 --- a/tests/test_field.py +++ b/tests/test_field.py @@ -37,7 +37,6 @@ import conftest from conftest import ( SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0, - SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_11_0, raises_for_servers_version_under, running_docker, ) From d1a2657aacf10d302d97e83ce020149e4bbb8a62 Mon Sep 17 00:00:00 2001 From: Paul Profizi <100710998+PProfizi@users.noreply.github.com> Date: Mon, 2 Jun 2025 11:07:12 +0200 Subject: [PATCH 08/12] Use builtin ValueError --- src/ansys/dpf/core/field_definition.py | 3 +-- tests/test_field.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ansys/dpf/core/field_definition.py b/src/ansys/dpf/core/field_definition.py index 78c0fe18dfa..8c986846c59 100644 --- a/src/ansys/dpf/core/field_definition.py +++ b/src/ansys/dpf/core/field_definition.py @@ -24,7 +24,6 @@ from __future__ import annotations -from argparse import ArgumentError import traceback import warnings @@ -245,7 +244,7 @@ def unit(self, value: str | tuple[Homogeneity, str]): elif isinstance(value, str): self._api.csfield_definition_set_unit(self, value, None, 0, 0, 0) else: - raise ArgumentError( + raise ValueError( None, message="Unit setter supports either string or tuple(Homogeneity, str)" ) diff --git a/tests/test_field.py b/tests/test_field.py index 8576e94f41a..87dd7b8a5f7 100644 --- a/tests/test_field.py +++ b/tests/test_field.py @@ -20,7 +20,6 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from argparse import ArgumentError import copy import gc @@ -1447,5 +1446,5 @@ def test_set_units(server_type): field.unit = "sones" # use wrong type of arguments - with pytest.raises(ArgumentError): + with pytest.raises(ValueError): field.unit = 1.0 From 1f41c7d9e95a2f5d7238d577b51003f466c7b4c5 Mon Sep 17 00:00:00 2001 From: Paul Profizi <100710998+PProfizi@users.noreply.github.com> Date: Mon, 2 Jun 2025 11:28:59 +0200 Subject: [PATCH 09/12] Fix call to ValueError --- src/ansys/dpf/core/field_definition.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/dpf/core/field_definition.py b/src/ansys/dpf/core/field_definition.py index 8c986846c59..00415c1bb14 100644 --- a/src/ansys/dpf/core/field_definition.py +++ b/src/ansys/dpf/core/field_definition.py @@ -245,7 +245,7 @@ def unit(self, value: str | tuple[Homogeneity, str]): self._api.csfield_definition_set_unit(self, value, None, 0, 0, 0) else: raise ValueError( - None, message="Unit setter supports either string or tuple(Homogeneity, str)" + "Unit setter supports either string or tuple(Homogeneity, str)" ) @location.setter From 2fdf822b27f22a96e8569fa045dea95c7663f19a Mon Sep 17 00:00:00 2001 From: Paul Profizi <100710998+PProfizi@users.noreply.github.com> Date: Mon, 2 Jun 2025 11:51:13 +0200 Subject: [PATCH 10/12] Fix Style check --- src/ansys/dpf/core/field_definition.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ansys/dpf/core/field_definition.py b/src/ansys/dpf/core/field_definition.py index 00415c1bb14..fb87d249812 100644 --- a/src/ansys/dpf/core/field_definition.py +++ b/src/ansys/dpf/core/field_definition.py @@ -244,9 +244,7 @@ def unit(self, value: str | tuple[Homogeneity, str]): elif isinstance(value, str): self._api.csfield_definition_set_unit(self, value, None, 0, 0, 0) else: - raise ValueError( - "Unit setter supports either string or tuple(Homogeneity, str)" - ) + raise ValueError("Unit setter supports either string or tuple(Homogeneity, str)") @location.setter def location(self, value): From e5719ac3961b20a7a14a5fd58bcddbd21f5694b7 Mon Sep 17 00:00:00 2001 From: Paul Profizi <100710998+PProfizi@users.noreply.github.com> Date: Mon, 2 Jun 2025 15:58:51 +0200 Subject: [PATCH 11/12] Fix QA --- tests/test_field.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/test_field.py b/tests/test_field.py index 87dd7b8a5f7..5d0493a2051 100644 --- a/tests/test_field.py +++ b/tests/test_field.py @@ -34,11 +34,7 @@ from ansys.dpf.core.common import locations, shell_layers from ansys.dpf.gate.errors import DPFServerException, DpfVersionNotSupported import conftest -from conftest import ( - SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0, - raises_for_servers_version_under, - running_docker, -) +from conftest import SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0, running_docker``` @pytest.fixture() From af643b2fac623c70a9c9318b4e573ec7d6050c60 Mon Sep 17 00:00:00 2001 From: Paul Profizi <100710998+PProfizi@users.noreply.github.com> Date: Mon, 2 Jun 2025 15:59:33 +0200 Subject: [PATCH 12/12] Fix QA --- tests/test_field.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_field.py b/tests/test_field.py index 5d0493a2051..5ef760ee711 100644 --- a/tests/test_field.py +++ b/tests/test_field.py @@ -34,7 +34,7 @@ from ansys.dpf.core.common import locations, shell_layers from ansys.dpf.gate.errors import DPFServerException, DpfVersionNotSupported import conftest -from conftest import SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0, running_docker``` +from conftest import SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0, running_docker @pytest.fixture()