From fa1de1d92473e17f30cf2432925d033c684a4d44 Mon Sep 17 00:00:00 2001
From: Amir Golparvar <amir.golparvar@physik.hu-berlin.de>
Date: Wed, 19 Apr 2023 14:40:37 +0000
Subject: [PATCH] Changed the behavior of the row mode in tabular parser

Changelog: Fixed
---
 nomad/parsing/tabular.py      | 10 +--------
 tests/parsing/test_tabular.py | 41 ++++-------------------------------
 2 files changed, 5 insertions(+), 46 deletions(-)

diff --git a/nomad/parsing/tabular.py b/nomad/parsing/tabular.py
index 7e7033184c..cb80c5dfa0 100644
--- a/nomad/parsing/tabular.py
+++ b/nomad/parsing/tabular.py
@@ -65,14 +65,6 @@ def traverse_to_target_data_file(section, path_list: List[str]):
             raise MetainfoError(f'The path {temp} in path_to_data_file does not exist')
 
 
-def to_camel_case(snake_str: str):
-    '''Take as input a snake case variable and return a camel case one'''
-
-    components = snake_str.split('_')
-
-    return ''.join(f'{x[0].upper()}{x[1:].lower()}' for x in components)
-
-
 def extract_tabular_parser_annotation(archive):
     for quantity_def in archive.m_def.all_quantities.values():
         annotation = quantity_def.m_get_annotations('tabular_parser')
@@ -181,7 +173,7 @@ class TableData(ArchiveSection):
             for section_name in section_names:
                 section_name_list = section_name.split('/')
                 section_name_str = section_name_list[0]
-                section_def = getattr(self, to_camel_case(section_name_str)).m_def
+                section_def = self.m_def.all_properties[section_name_str].sub_section
 
                 if not list_of_visited_sections.count(section_name_str):
                     list_of_visited_sections.append(section_name_str)
diff --git a/tests/parsing/test_tabular.py b/tests/parsing/test_tabular.py
index dc1a7905a9..129513b4fd 100644
--- a/tests/parsing/test_tabular.py
+++ b/tests/parsing/test_tabular.py
@@ -632,11 +632,10 @@ data:
             Main_Class:
               base_sections:
                 - nomad.parsing.tabular.TableData
-                - nomad.datamodel.data.EntryData
               quantities:
                 csv_file:
                   type: str
-                  default: 'asghar'
+                  default: 'placeholder'
                   m_annotations:
                     tabular_parser:
                       mode: row
@@ -645,20 +644,10 @@ data:
               sub_sections:
                 subsection_1:
                   repeats: True
-                  section: '#/Base_Class'
+                  section: '#/Class_1'
             Class_1:
               base_sections:
               - '#/Base_Class'
-              -  nomad.parsing.tabular.TableData
-              quantities:
-                data_file_1:
-                  type: str
-                  default: '#data/csv_file'
-                  m_annotations:
-                    tabular_parser:
-                      mode: row
-                      target_sub_section:
-                      - subsection_1
               sub_sections:
                 subsection_1:
                   repeats: true
@@ -669,32 +658,11 @@ data:
                         m_annotations:
                           tabular:
                             name: header_0
-            Class_2:
-              base_sections:
-              -  nomad.parsing.tabular.TableData
-              quantities:
-                data_file_2:
-                  type: str
-                  default: '#data/csv_file'
-                  m_annotations:
-                    tabular_parser:
-                      mode: column
-              sub_sections:
-                subsection_1:
-                  section:
-                    quantities:
-                      header_1:
-                        type: str
-                        shape: ['*']
-                        m_annotations:
-                          tabular:
-                            name: header_1
         data:
           m_def: Main_Class
           csv_file: test.my_schema.archive.csv
           subsection_1:
           - m_def: Class_1
-          - m_def: Class_2
         '''),
         strip('''
             header_0,header_1
@@ -725,10 +693,9 @@ def test_tabular_csv(raw_files, monkeypatch, schema, content):
             assert isinstance(main_archive.data.MySubsection[instance].header_0, datetime.datetime)
     elif re.search('data file as reference', schema):
         assert len(main_archive.data.subsection_1) == 2
-        assert len(main_archive.data.subsection_1[0].subsection_1) == 2
+        assert len(main_archive.data.subsection_1[0].subsection_1) == 1
         assert main_archive.data.subsection_1[0].subsection_1[0].header_0 == '0_0'
-        assert main_archive.data.subsection_1[0].subsection_1[1].header_0 == '1_0'
-        assert main_archive.data.subsection_1[1].subsection_1.header_1 == ['0_1', '1_1']
+        assert main_archive.data.subsection_1[1].subsection_1[0].header_0 == '1_0'
 
 
 @pytest.mark.parametrize('schema,content,missing', [
-- 
GitLab