Source code for eegunity.utils.con_udatasets

from eegunity.unifieddataset import UnifiedDataset
import pandas as pd
[docs] def con_udatasets(datasets): """ Concatenates the locator DataFrames of the given UnifiedDataset objects, and returns a new UnifiedDataset with the concatenated locator. The function checks if all elements in the input list are instances of the 'UnifiedDataset' class. It then calls the `get_locator()` method of each dataset, concatenates them, and sets the new locator in a copied version of the first dataset using `set_locator()`. Parameters ---------- datasets : list of UnifiedDataset A list of UnifiedDataset instances to concatenate their locators. Returns ------- UnifiedDataset A new UnifiedDataset with the concatenated locator. Raises ------ ValueError If any element in the list is not an instance of 'UnifiedDataset'. """ if not all(isinstance(ds, UnifiedDataset) for ds in datasets): raise ValueError("All elements in the list must be instances of 'UnifiedDataset'.") # Concatenate the locators from all datasets locators = [ds.get_locator() for ds in datasets] con_locator = pd.concat(locators, ignore_index=True) # Create a copy of the first dataset new_dataset = datasets[0].copy() # Set the concatenated locator to the new dataset new_dataset.set_locator(con_locator) return new_dataset