@@ -193,22 +193,24 @@ def eventstable(self) -> pd.DataFrame:
193193
194194 # Check the parser's data structure
195195 if not self .isvalid :
196- return pd . DataFrame ()
196+ pass
197197
198198 df = copy .deepcopy (self .logtable )
199199
200200 # Convert the timing values to seconds (with maximally 4 digits after the decimal point)
201- df [self .time ['cols' ]] = (df [self .time ['cols' ]].apply (pd .to_numeric , errors = 'coerce' ) / self .time ['unit' ]).round (4 )
201+ timecols = [col for col in self .time .get ('cols' ,[]) if col in df .columns ]
202+ df [timecols ] = (df [timecols ].apply (pd .to_numeric , errors = 'coerce' ) / self .time ['unit' ]).round (4 )
202203
203204 # Take the logtable columns of interest and from now on use the BIDS column names
204- df = df .loc [:, [sourcecol for item in self .columns for sourcecol in item .values () if sourcecol ]]
205- df .columns = [eventscol for item in self .columns for eventscol , sourcecol in item .items () if sourcecol ]
205+ df = df .loc [:, [sourcecol for item in self .columns for sourcecol in item .values () if sourcecol in df . columns ]]
206+ df .columns = [eventscol for item in self .columns for eventscol , sourcecol in item .items () if sourcecol in df . columns ]
206207
207208 # Set the clock at zero at the start of the experiment
208209 if self .time .get ('start' ):
209210 start = pd .Series ([True ] * len (df ))
210211 for column , value in self .time ['start' ].items ():
211- start &= (self .logtable [column ].astype (str ) == str (value )).values
212+ if column in self .logtable .columns :
213+ start &= (self .logtable [column ].astype (str ) == str (value )).values
212214 if start .any ():
213215 LOGGER .bcdebug (f"Resetting clock offset: { df ['onset' ][start .values ].iloc [0 ]} " )
214216 df ['onset' ] -= df ['onset' ][start .values ].iloc [0 ] # Take the time of the first occurrence as zero
@@ -219,6 +221,9 @@ def eventstable(self) -> pd.DataFrame:
219221
220222 for column , regex in group ['condition' ].items ():
221223
224+ if column not in self .logtable .columns :
225+ continue
226+
222227 # Get the rows that match the expression, i.e. make them True
223228 rowgroup = self .logtable [column ].astype (str ).str .fullmatch (str (regex ))
224229
@@ -294,7 +299,7 @@ def is_float(s):
294299 for name in set ([name for item in self .columns for name in item .values ()] + [name for item in self .rows for name in item ['condition' ].keys ()] +
295300 [* self .time .get ('start' , {}).keys ()] + self .time .get ('cols' , [])):
296301 if name and name not in columns :
297- LOGGER .warning (f"Column '{ name } ' not found in the event table of { self } " )
302+ LOGGER .warning (f"Column '{ name } ' not found in the input table parsed from { self } " )
298303 valid = False
299304 if columns .duplicated ().any ():
300305 LOGGER .warning (f"Duplicate columns found: { columns } \n { self } " )
0 commit comments