From 491121757467e33413bf79c03f6d064f5a0ad645 Mon Sep 17 00:00:00 2001 From: Fabien Casenave Date: Wed, 25 Jun 2025 09:33:11 +0200 Subject: [PATCH 1/4] feat(tests) add scalar named 'a/b' in sample tests --- tests/containers/test_sample.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/containers/test_sample.py b/tests/containers/test_sample.py index ca50ed3..cea2a57 100644 --- a/tests/containers/test_sample.py +++ b/tests/containers/test_sample.py @@ -105,6 +105,7 @@ def sample_with_tree_and_scalar_and_time_series( sample_with_tree, ): sample_with_tree.add_scalar("r", np.random.randn()) + sample_with_tree.add_scalar("a/b", np.random.randn()) sample_with_tree.add_scalar("test_scalar_1", np.random.randn()) sample_with_tree.add_time_series( "test_time_series_1", np.arange(111, dtype=float), np.random.randn(111) From 531c452984b6e745848c8a19b1f687b1273e9ea4 Mon Sep 17 00:00:00 2001 From: Xavier Roynard Date: Wed, 25 Jun 2025 09:44:23 +0000 Subject: [PATCH 2/4] add test for time_series with name containing / --- tests/containers/test_sample.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/containers/test_sample.py b/tests/containers/test_sample.py index cea2a57..a36119f 100644 --- a/tests/containers/test_sample.py +++ b/tests/containers/test_sample.py @@ -110,6 +110,9 @@ def sample_with_tree_and_scalar_and_time_series( sample_with_tree.add_time_series( "test_time_series_1", np.arange(111, dtype=float), np.random.randn(111) ) + sample_with_tree.add_time_series( + "a/b", np.arange(113, dtype=float), np.random.randn(113) + ) return sample_with_tree From 6cc878945a957bb8a62c43db4b8a353a2ed2928d Mon Sep 17 00:00:00 2001 From: Xavier Roynard Date: Wed, 16 Jul 2025 15:27:59 +0000 Subject: [PATCH 3/4] (.gitignore) add venv/ dir --- .gitignore | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index d77e9c7..16706bd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,9 @@ tests/post/*.yaml tests/problem_definition/*.csv examples/**/*.png tests/problem_definition/split.csv +# Heavy data +*.cgns +!notebooks/ex_rotor37_pv.cgns # Byte-compiled / optimized / DLL files __pycache__/ @@ -13,6 +16,7 @@ __pycache__/ # Distribution / packaging .Python +venv/ build/ develop-eggs/ dist/ @@ -32,6 +36,7 @@ share/python-wheels/ *.egg MANIFEST _version.py +oryx-build-commands.txt # Unit test / coverage reports htmlcov/ @@ -69,10 +74,6 @@ docs/_extra/ docs/source/notebooks/*.png docs/source/notebooks/*.yaml -# Heavy data -*.cgns -!notebooks/ex_rotor37_pv.cgns - ############################################################################### # .gitignore PATTERN FORMAT: # - A blank line matches no files, so it can serve as a separator for readability. @@ -106,4 +107,4 @@ docs/source/notebooks/*.yaml # For example, "abc/**" matches all files inside directory "abc", relative to the location of the .gitignore file, with infinite depth. # - A slash followed by two consecutive asterisks then a slash matches zero or more directories. # For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on. -# - Other consecutive asterisks are considered regular asterisks and will match according to the previous rules. \ No newline at end of file +# - Other consecutive asterisks are considered regular asterisks and will match according to the previous rules. From 705793711131bf62acd3a5b4ac5b29f865d1b47e Mon Sep 17 00:00:00 2001 From: Xavier Roynard Date: Wed, 16 Jul 2025 15:48:41 +0000 Subject: [PATCH 4/4] (sample.py) add check that names does not contain / --- src/plaid/containers/sample.py | 11 +++++++++++ tests/containers/test_sample.py | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/src/plaid/containers/sample.py b/src/plaid/containers/sample.py index d644831..6123937 100644 --- a/src/plaid/containers/sample.py +++ b/src/plaid/containers/sample.py @@ -119,6 +119,10 @@ """A TimeSeriesType is a tuple[TimeSequenceType,FieldType] """ +def check_names(names:list[str]): + for name in names: + if '/' in name: + raise ValueError(f"feature_names containing `/` are not allowed, but {name=}, you should first replace any occurence of `/` with something else, for example: `name.replace('/',' ')`") def read_index(pyTree: list, dim: list[int]): """Read Index Array or Index Range from CGNS. @@ -872,6 +876,8 @@ def init_base( Returns: CGNSNode: The created Base node. """ + check_names([base_name]) + time = self.get_time_assignment(time) if base_name is None: @@ -1014,6 +1020,8 @@ def init_zone( Returns: CGLNode: The newly initialized zone node within the CGNS tree. """ + check_names([zone_name]) + # init_tree will look for default time self.init_tree(time) # get_base will look for default base_name and time @@ -1201,6 +1209,7 @@ def add_scalar(self, name: str, value: ScalarType) -> None: name (str): The name of the scalar value. value (ScalarType): The scalar value to add or update in the dictionary. """ + check_names([name]) if self._scalars is None: self._scalars = {name: value} else: @@ -1274,6 +1283,7 @@ def add_time_series( Raises: TypeError: Raised if the length of `time_sequence` is not equal to the length of `values`. """ + check_names([name]) assert len(time_sequence) == len(values), ( "time sequence and values do not have the same size" ) @@ -1633,6 +1643,7 @@ def add_field( Raises: KeyError: Raised if the specified zone does not exist in the given base. """ + check_names([name]) # init_tree will look for default time self.init_tree(time) # get_zone will look for default zone_name, base_name and time diff --git a/tests/containers/test_sample.py b/tests/containers/test_sample.py index a36119f..94016f0 100644 --- a/tests/containers/test_sample.py +++ b/tests/containers/test_sample.py @@ -119,6 +119,15 @@ def sample_with_tree_and_scalar_and_time_series( # %% Test +def test_check_names(): + check_names('test name') + check_names(['test name', 'test_name_2']) + with pytest.raises(ValueError): + check_names(['test/name']) + with pytest.raises(ValueError): + check_names(['test\/name']) + + def test_read_index(tree, physical_dim): read_index(tree, physical_dim)