traffic/core/flight.py
def apply_time(
        self, freq: str = "1T", merge: bool = True, **kwargs,
    ) -> "Flight":
        """Apply features on time windows.

        The following is performed:

        - a new column `rounded` rounds the timestamp at the given rate;
        - the groupby/apply is operated with parameters passed in apply;
        - if merge is True, the new column in merged into the Flight,
          otherwise a pd.DataFrame is returned.

        For example:

        >>> f.agg_time("10T", straight=lambda df: Flight(df).distance())

        returns a Flight with a new column straight with the great circle
        distance between points sampled every 10 minutes.
        """

        if len(kwargs) == 0:
            raise RuntimeError("No feature provided for aggregation.")
        temp_flight = self.assign(
            rounded=lambda df: df.timestamp.dt.round(freq)
        )

        agg_data = None

        for label, fun in kwargs.items():
            agg_data = (
                agg_data.merge(  # type: ignore
                    temp_flight.groupby("rounded")
                    .apply(lambda df: fun(self.__class__(df)))
                    .rename(label),
                    left_index=True,
                    right_index=True,
                )
                if agg_data is not None
                else temp_flight.groupby("rounded")
                .apply(lambda df: fun(self.__class__(df)))
                .rename(label)
                .to_frame()
            )

        if not merge:  # mostly for debugging purposes
            return agg_data  # type: ignore

        return temp_flight.merge(agg_data, left_on="rounded", right_index=True)
Apply features on time windows.

        The following is performed:

        - a new column `rounded` rounds the timestamp at the given rate;
        - the groupby/apply is operated with parameters passed in apply;
        - if merge is True, the new column in merged into the Flight,
          otherwise a pd.DataFrame is returned.

        For example:

        >>> f.agg_time("10T", straight=lambda df: Flight(df).distance())

        returns a Flight with a new column straight with the great circle
        distance between points sampled every 10 minutes.
        
Apply features on time windows.
The following is performed.

a new column `rounded` rounds the timestamp at the given rate;
the groupby/apply is operated with parameters passed in apply;
if merge is True, the new column in merged into the Flight,
otherwise a pd.DataFrame is returned.

For example.



returns a Flight with a new column straight with the great circle
distance between points sampled every 10 minutes.
Apply features on time windows . The following is performed . a new column ` rounded ` rounds the timestamp at the given rate ; the groupby / apply is operated with parameters passed in apply ; if merge is True the new column in merged into the Flight otherwise a pd . DataFrame is returned . For example . returns a Flight with a new column straight with the great circle distance between points sampled every 10 minutes .
def apply_time(
        self, freq: str = "1T", merge: bool = True, **kwargs,
    ) -> "Flight":
        if len(kwargs) == 0:
            raise RuntimeError("No feature provided for aggregation.")
        temp_flight = self.assign(
            rounded=lambda df: df.timestamp.dt.round(freq)
        )
        agg_data = None
        for label, fun in kwargs.items():
            agg_data = (
                agg_data.merge(  
                    temp_flight.groupby("rounded")
                    .apply(lambda df: fun(self.__class__(df)))
                    .rename(label),
                    left_index=True,
                    right_index=True,
                )
                if agg_data is not None
                else temp_flight.groupby("rounded")
                .apply(lambda df: fun(self.__class__(df)))
                .rename(label)
                .to_frame()
            )
        if not merge:  
            return agg_data  
        return temp_flight.merge(agg_data, left_on="rounded", right_index=True)
def apply_time ( self , freq : str = "1T" , merge : bool = True , ** kwargs , ) -> "Flight" : if len ( kwargs ) == 0 : raise RuntimeError ( "No feature provided for aggregation." ) temp_flight = self . assign ( rounded = lambda df : df . timestamp . dt . round ( freq ) ) agg_data = None for label , fun in kwargs . items ( ) : agg_data = ( agg_data . merge ( temp_flight . groupby ( "rounded" ) . apply ( lambda df : fun ( self . __class__ ( df ) ) ) . rename ( label ) , left_index = True , right_index = True , ) if agg_data is not None else temp_flight . groupby ( "rounded" ) . apply ( lambda df : fun ( self . __class__ ( df ) ) ) . rename ( label ) . to_frame ( ) ) if not merge : return agg_data return temp_flight . merge ( agg_data , left_on = "rounded" , right_index = True )
Apply features on time windows.
Apply features on time windows .
"""Apply features on time windows.

        The following is performed:

        - a new column `rounded` rounds the timestamp at the given rate;
        - the groupby/apply is operated with parameters passed in apply;
        - if merge is True, the new column in merged into the Flight,
          otherwise a pd.DataFrame is returned.

        For example:

        >>> f.agg_time("10T", straight=lambda df: Flight(df).distance())

        returns a Flight with a new column straight with the great circle
        distance between points sampled every 10 minutes.
        """ # type: ignore # mostly for debugging purposes # type: ignore
self
freq
str
merge
bool