66
77import re
88from datetime import datetime , timedelta , timezone
9- from typing import TYPE_CHECKING
109
1110import numpy as np
1211
@@ -56,6 +55,7 @@ def _parse_eyelink_ascii(
5655 # Process each block individually, then combine
5756 processed_blocks = _create_dataframes (data_blocks , apply_offsets )
5857 raw_extras ["dfs" ], ch_names = _combine_block_dataframes (processed_blocks )
58+ del processed_blocks # free memory
5959 for block in data_blocks :
6060 del block ["samples" ] # remove samples from block to save memory
6161
@@ -312,10 +312,6 @@ def _create_dataframes(data_blocks, apply_offsets):
312312 Processes each block individually with its own column structure,
313313 then returns a list of processed block dataframes.
314314 """
315- if TYPE_CHECKING :
316- import pandas as pd
317- else :
318- pd = _check_pandas_installed ()
319315 processed_blocks = []
320316
321317 for block_idx , block in enumerate (data_blocks ):
@@ -326,8 +322,8 @@ def _create_dataframes(data_blocks, apply_offsets):
326322 col_names , ch_names = _infer_col_names_for_block (block )
327323
328324 # Assign column names and set dtypes for this block
329- block_dfs : dict [ str , pd . DataFrame ] = _assign_col_names (col_names , block_dfs )
330- block_dfs : dict [ str , pd . DataFrame ] = _set_df_dtypes (block_dfs )
325+ block_dfs = _assign_col_names (col_names , block_dfs )
326+ block_dfs = _set_df_dtypes (block_dfs )
331327
332328 processed_blocks .append (
333329 {
@@ -456,9 +452,8 @@ def _infer_col_names_for_block(block: dict) -> tuple[dict[str, list], list]:
456452def _combine_block_dataframes (processed_blocks : list [dict ]):
457453 """Combine dataframes across acquisition blocks.
458454
459- Creates a unified column structure and fills missing columns with NaN
460- when blocks have different columns/data in them (e.g. binocular vs monocular
461- tracking, or switching between the left and right eye).
455+ Handles cases where blocks have different columns/data in them
456+ (e.g. binocular vs monocular tracking, or switching between the left and right eye).
462457 """
463458 pd = _check_pandas_installed ()
464459
@@ -475,7 +470,6 @@ def _combine_block_dataframes(processed_blocks: list[dict]):
475470 for ch_name in block ["ch_names" ]:
476471 if ch_name not in all_ch_names :
477472 all_ch_names .append (ch_name )
478- # all_ch_names.update(block["ch_names"])
479473 if "samples" in block ["dfs" ]:
480474 all_samples_cols .update (block ["dfs" ]["samples" ].columns )
481475 all_df_types .update (block ["dfs" ].keys ())
@@ -496,12 +490,11 @@ def _combine_block_dataframes(processed_blocks: list[dict]):
496490
497491 # For samples dataframes, ensure all have the same columns
498492 if df_type == "samples" :
499- # Add missing columns with NaN
500493 for col in all_samples_cols :
501494 if col not in block_df .columns :
502495 block_df [col ] = np .nan
503496
504- # Reorder columns to match unified structure
497+ # Reorder columns
505498 block_df = block_df [all_samples_cols ]
506499
507500 block_dfs .append (block_df )
0 commit comments