def add_last_time_indexes(self, updated_entities=None):
    '\n        Calculates the last time index values for each entity (the last time\n        an instance or children of that instance were observed).  Used when\n        calculating features using training windows\n        Args:\n            updated_entities (list[str]): List of entity ids to update last_time_index for\n                (will update all parents of those entities as well)\n        '
    children = defaultdict(list)
    child_vars = defaultdict(dict)
    for r in self.relationships:
        children[r.parent_entity.id].append(r.child_entity)
        child_vars[r.parent_entity.id][r.child_entity.id] = r.child_variable
    updated_entities = (updated_entities or [])
    if updated_entities:
        parent_queue = updated_entities[:]
        parents = set()
        while len(parent_queue):
            e = parent_queue.pop(0)
            if (e in parents):
                continue
            parents.add(e)
            for (parent_id, _) in self.get_forward_entities(e):
                parent_queue.append(parent_id)
        queue = [self[p] for p in parents]
        to_explore = parents
    else:
        to_explore = set([e.id for e in self.entities[:]])
        queue = self.entities[:]
    explored = set()
    for e in queue:
        e.last_time_index = None
    while (not to_explore.issubset(explored)):
        entity = queue.pop(0)
        if (entity.last_time_index is None):
            if (entity.time_index is not None):
                lti = entity.df[entity.time_index].copy()
                if isinstance(entity.df, dd.DataFrame):
                    lti.index = entity.df[entity.index].copy()
            else:
                lti = entity.df[entity.index].copy()
                if isinstance(entity.df, dd.DataFrame):
                    lti.index = entity.df[entity.index].copy()
                    lti = lti.apply((lambda x: None))
                else:
                    lti[:] = None
            entity.last_time_index = lti
        if (entity.id in children):
            child_entities = children[entity.id]
            if (not set([e.id for e in child_entities]).issubset(explored)):
                for e in child_entities:
                    if ((e.id not in explored) and (e.id not in [q.id for q in queue])):
                        queue.append(e)
                queue.append(entity)
                continue
            for child_e in child_entities:
                if (child_e.last_time_index is None):
                    continue
                link_var = child_vars[entity.id][child_e.id].id
                if isinstance(child_e.last_time_index, dd.Series):
                    to_join = child_e.df[link_var]
                    to_join.index = child_e.df[child_e.index]
                    lti_df = child_e.last_time_index.to_frame(name='last_time').join(to_join.to_frame(name=entity.index))
                    new_index = lti_df.index.copy()
                    new_index.name = None
                    lti_df.index = new_index
                    lti_df = lti_df.groupby(lti_df[entity.index]).agg('max')
                    lti_df = entity.last_time_index.to_frame(name='last_time_old').join(lti_df)
                else:
                    lti_df = pd.DataFrame({'last_time': child_e.last_time_index, entity.index: child_e.df[link_var]})
                    lti_df.sort_values(['last_time', entity.index], kind='mergesort', inplace=True)
                    lti_df.drop_duplicates(entity.index, keep='last', inplace=True)
                    lti_df.set_index(entity.index, inplace=True)
                    lti_df = lti_df.reindex(entity.last_time_index.index)
                    lti_df['last_time_old'] = entity.last_time_index
                if ((not isinstance(lti_df, dd.DataFrame)) and lti_df.empty):
                    lti_df = pd.Series()
                else:
                    lti_df['last_time'] = lti_df['last_time'].astype('datetime64[ns]')
                    lti_df['last_time_old'] = lti_df['last_time_old'].astype('datetime64[ns]')
                    lti_df = lti_df.fillna(pd.to_datetime('1800-01-01 00:00')).max(axis=1)
                    lti_df = lti_df.replace(pd.to_datetime('1800-01-01 00:00'), pd.NaT)
                entity.last_time_index = lti_df
                entity.last_time_index.name = 'last_time'
        explored.add(entity.id)
    self.reset_data_description()
Calculates the last time index values for each entity (the last time
an instance or children of that instance were observed).  Used when
calculating features using training windows
Args:
    updated_entities (list[str]): List of entity ids to update last_time_index for
        (will update all parents of those entities as well)
def add_last_time_indexes(self, updated_entities=None):
    '\n        Calculates the last time index values for each entity (the last time\n        an instance or children of that instance were observed).  Used when\n        calculating features using training windows\n        Args:\n            updated_entities (list[str]): List of entity ids to update last_time_index for\n                (will update all parents of those entities as well)\n        '
    children = defaultdict(list)
    child_vars = defaultdict(dict)
    for r in self.relationships:
        children[r.parent_entity.id].append(r.child_entity)
        child_vars[r.parent_entity.id][r.child_entity.id] = r.child_variable
    updated_entities = (updated_entities or [])
    if updated_entities:
        parent_queue = updated_entities[:]
        parents = set()
        while len(parent_queue):
            e = parent_queue.pop(0)
            if (e in parents):
                continue
            parents.add(e)
            for (parent_id, _) in self.get_forward_entities(e):
                parent_queue.append(parent_id)
        queue = [self[p] for p in parents]
        to_explore = parents
    else:
        to_explore = set([e.id for e in self.entities[:]])
        queue = self.entities[:]
    explored = set()
    for e in queue:
        e.last_time_index = None
    while (not to_explore.issubset(explored)):
        entity = queue.pop(0)
        if (entity.last_time_index is None):
            if (entity.time_index is not None):
                lti = entity.df[entity.time_index].copy()
                if isinstance(entity.df, dd.DataFrame):
                    lti.index = entity.df[entity.index].copy()
            else:
                lti = entity.df[entity.index].copy()
                if isinstance(entity.df, dd.DataFrame):
                    lti.index = entity.df[entity.index].copy()
                    lti = lti.apply((lambda x: None))
                else:
                    lti[:] = None
            entity.last_time_index = lti
        if (entity.id in children):
            child_entities = children[entity.id]
            if (not set([e.id for e in child_entities]).issubset(explored)):
                for e in child_entities:
                    if ((e.id not in explored) and (e.id not in [q.id for q in queue])):
                        queue.append(e)
                queue.append(entity)
                continue
            for child_e in child_entities:
                if (child_e.last_time_index is None):
                    continue
                link_var = child_vars[entity.id][child_e.id].id
                if isinstance(child_e.last_time_index, dd.Series):
                    to_join = child_e.df[link_var]
                    to_join.index = child_e.df[child_e.index]
                    lti_df = child_e.last_time_index.to_frame(name='last_time').join(to_join.to_frame(name=entity.index))
                    new_index = lti_df.index.copy()
                    new_index.name = None
                    lti_df.index = new_index
                    lti_df = lti_df.groupby(lti_df[entity.index]).agg('max')
                    lti_df = entity.last_time_index.to_frame(name='last_time_old').join(lti_df)
                else:
                    lti_df = pd.DataFrame({'last_time': child_e.last_time_index, entity.index: child_e.df[link_var]})
                    lti_df.sort_values(['last_time', entity.index], kind='mergesort', inplace=True)
                    lti_df.drop_duplicates(entity.index, keep='last', inplace=True)
                    lti_df.set_index(entity.index, inplace=True)
                    lti_df = lti_df.reindex(entity.last_time_index.index)
                    lti_df['last_time_old'] = entity.last_time_index
                if ((not isinstance(lti_df, dd.DataFrame)) and lti_df.empty):
                    lti_df = pd.Series()
                else:
                    lti_df['last_time'] = lti_df['last_time'].astype('datetime64[ns]')
                    lti_df['last_time_old'] = lti_df['last_time_old'].astype('datetime64[ns]')
                    lti_df = lti_df.fillna(pd.to_datetime('1800-01-01 00:00')).max(axis=1)
                    lti_df = lti_df.replace(pd.to_datetime('1800-01-01 00:00'), pd.NaT)
                entity.last_time_index = lti_df
                entity.last_time_index.name = 'last_time'
        explored.add(entity.id)
    self.reset_data_description()