[docs]defconcat(objs,sort=True):"""Concatenates multiple time series objects into a single object. Args: objs (List[Union[IrregularTimeSeries, RegularTimeSeries]]): List of time series objects to concatenate. sort (bool, optional): Whether to sort the resulting time series by timestamps. Only applies to IrregularTimeSeries. Defaults to True. Returns: Union[IrregularTimeSeries, RegularTimeSeries]: The concatenated time series object. Raises: ValueError: If objects are not all of the same type or don't have matching keys. NotImplementedError: If concatenation is not implemented for the given object type. Example :: >>> import numpy as np >>> from temporaldata import IrregularTimeSeries, Interval, concat >>> ts1 = IrregularTimeSeries( ... timestamps=np.array([0.0, 1.0]), ... values=np.array([1.0, 2.0]), ... domain="auto", ... ) >>> ts2 = IrregularTimeSeries( ... timestamps=np.array([2.0, 3.0]), ... values=np.array([3.0, 4.0]), ... domain="auto", ... ) >>> ts_concat = concat([ts1, ts2]) >>> ts_concat IrregularTimeSeries( timestamps=[4], values=[4] ) >>> ts_concat.timestamps array([0., 1., 2., 3.]) """# check if all objects are of the same typeobj_type=type(objs[0])ifany(notisinstance(obj,obj_type)forobjinobjs):raiseValueError("All objects must be of the same type, got: {}".format([type(obj)forobjinobjs]))ifobj_type==IrregularTimeSeries:domain=reduce(lambdax,y:x|y,[obj.domainforobjinobjs])keys=objs[0].keys()timekeys=objs[0].timekeys()forobjinobjs:ifset(obj.keys())!=set(keys):raiseValueError("All objects must have the same keys, got {} and {}".format(keys,obj.keys()))ifset(obj.timekeys())!=set(timekeys):raiseValueError("All objects must have the same timekeys, got {} and {}".format(timekeys,obj.timekeys()))obj_concat_dict={}forkinkeys:obj_concat_dict[k]=np.concatenate([getattr(obj,k)forobjinobjs])obj_concat=IrregularTimeSeries(**obj_concat_dict,timekeys=timekeys,domain=domain)ifsort:obj_concat.sort()else:raiseNotImplementedError("Concatenation not implemented for type: {}".format(obj_type))returnobj_concat