@@ -95,13 +95,22 @@ def apply_mapping(flattened_data, mapping_dict, accession, must_exist_in_mapping
9595
9696
9797class Table :
98- def __init__ (self , data , name , accession , description = None , preamble = None , footnotes = None , postamble = None ):
99- self .data = data
100- if data != []:
98+ def __init__ (self , data_raw , name , accession , description = None , preamble = None , footnotes = None , postamble = None ):
99+ self .data_raw = data_raw
100+
101+ # Clean the data - strip dict wrappers and keep just table content
102+ if data_raw != []:
101103 try :
102- self .columns = data [0 ].keys () # handle xml tables
104+ # Handle xml tables - already list of dicts
105+ self .columns = data_raw [0 ].keys ()
106+ self .data = data_raw
103107 except :
104- self .columns = data [0 ] # handle html tables
108+ # Handle html tables - already list of lists
109+ self .columns = data_raw [0 ]
110+ self .data = data_raw
111+ else :
112+ self .columns = []
113+ self .data = []
105114
106115 self .name = name
107116 self .accession = accession
@@ -122,8 +131,7 @@ def __str__(self):
122131
123132 # Preamble
124133 if self .preamble :
125- preamble_texts = [item .get ('text' ) or item .get ('textsmall' , '' ) for item in self .preamble ]
126- parts .append (f"\n Preamble: { ' ' .join (preamble_texts )} " )
134+ parts .append (f"\n Preamble: { self .preamble } " )
127135
128136 # The actual table
129137 formatted_table = _format_table (self .data )
@@ -135,15 +143,11 @@ def __str__(self):
135143
136144 # Footnotes
137145 if self .footnotes :
138- parts .append ("\n Footnotes:" )
139- for footnote in self .footnotes :
140- footnote_text = footnote .get ('text' ) or footnote .get ('textsmall' , '' )
141- parts .append (f" { footnote ['footnote_id' ]} : { footnote_text } " )
146+ parts .append (f"\n Footnotes: { self .footnotes } " )
142147
143148 # Postamble
144149 if self .postamble :
145- postamble_texts = [item .get ('text' ) or item .get ('textsmall' , '' ) for item in self .postamble ]
146- parts .append (f"\n Postamble: { ' ' .join (postamble_texts )} " )
150+ parts .append (f"\n Postamble: { self .postamble } " )
147151
148152 return '\n ' .join (parts )
149153
@@ -176,7 +180,7 @@ def parse_tables(self, data, must_exist_in_mapping=True):
176180 def add_table (self , data , name , description = None , preamble = None , footnotes = None , postamble = None ):
177181 """Add a table with optional metadata components"""
178182 self .tables .append (Table (
179- data = data ,
183+ data_raw = data ,
180184 name = name ,
181185 accession = self .accession ,
182186 description = description ,
0 commit comments