def init_entity(self, entity = None, input_data_frame = None, period = None, simulation = None):
        """
        Initialize the simulation period with current input_data_frame
        """
        assert entity is not None
        assert input_data_frame is not None
        assert period is not None
        assert simulation is not None
        used_as_input_variables = self.used_as_input_variables_by_entity[entity]

        variables_mismatch = set(used_as_input_variables).difference(set(input_data_frame.columns)) if used_as_input_variables else None
        if variables_mismatch:
            log.info(
                'The following variables are used as input variables are not present in the input data frame: \n {}'.format(
                    sorted(variables_mismatch)))
        if variables_mismatch:
            log.debug('The following variables are used as input variables: \n {}'.format(
                sorted(used_as_input_variables)))
            log.debug('The input_data_frame contains the following variables: \n {}'.format(
                sorted(list(input_data_frame.columns))))

        entity = simulation.entities[entity]
        id_variables = [
            self.id_variable_by_entity_key[_entity.key] for _entity in simulation.entities.values()
            if not _entity.is_person]
        role_variables = [
            self.role_variable_by_entity_key[_entity.key] for _entity in simulation.entities.values()
            if not _entity.is_person]

        if entity.is_person:
            for id_variable in id_variables + role_variables:
                assert id_variable in input_data_frame.columns, \
                    "Variable {} is not present in input dataframe".format(id_variable)

        input_data_frame = self.filter_input_variables(input_data_frame = input_data_frame, simulation = simulation)

        if entity.is_person:
            entity.count = entity.step_size = len(input_data_frame)
            for collective_entity in simulation.entities.values():
                if collective_entity.is_person:
                    continue
                _key = collective_entity.key
                _id_variable = self.id_variable_by_entity_key[_key]
                _role_variable = self.role_variable_by_entity_key[_key]

                collective_entity.count = len(input_data_frame[_id_variable].unique())
                collective_entity.members_entity_id = input_data_frame[_id_variable].astype('int').values
                # TODO remove legacy use
                collective_entity.members_legacy_role = input_data_frame[_role_variable].astype('int').values

                for (legacy_role, flattened_role) in enumerate(collective_entity.flattened_roles):
                    if legacy_role < len(collective_entity.flattened_roles):
                        collective_entity.members_role = np.where(
                            collective_entity.members_legacy_role == legacy_role,
                            flattened_role,
                            collective_entity.members_role,
                            )
                    else:
                        collective_entity.members_role = np.where(
                            collective_entity.members_legacy_role >= len(collective_entity.flattened_roles),
                            collective_entity.flattened_roles[-1],
                            collective_entity.members_role,
                            )

        else:
            entity.count = entity.step_size = len(input_data_frame)

        for column_name, column_serie in input_data_frame.iteritems():
            if column_name in (id_variables + role_variables):
                continue

            variable_instance = self.tax_benefit_system.variables.get(column_name)
            if variable_instance.entity.key != entity.key:
                log.info("Ignoring variable {} which is not part of entity {} but {}".format(
                    column_name, entity.key, variable_instance.entity.key))
                continue

            init_variable_in_entity(
                entity = entity,
                variable_name = column_name,
                series = column_serie,
                period = period,
                )
def init_entity ( self , entity = None , input_data_frame = None , period = None , simulation = None ) : assert entity is not None assert input_data_frame is not None assert period is not None assert simulation is not None used_as_input_variables = self . used_as_input_variables_by_entity [ entity ] variables_mismatch = set ( used_as_input_variables ) . difference ( set ( input_data_frame . columns ) ) if used_as_input_variables else None if variables_mismatch : log . info ( 'The following variables are used as input variables are not present in the input data frame: \n {}' . format ( sorted ( variables_mismatch ) ) ) if variables_mismatch : log . debug ( 'The following variables are used as input variables: \n {}' . format ( sorted ( used_as_input_variables ) ) ) log . debug ( 'The input_data_frame contains the following variables: \n {}' . format ( sorted ( list ( input_data_frame . columns ) ) ) ) entity = simulation . entities [ entity ] id_variables = [ self . id_variable_by_entity_key [ _entity . key ] for _entity in simulation . entities . values ( ) if not _entity . is_person ] role_variables = [ self . role_variable_by_entity_key [ _entity . key ] for _entity in simulation . entities . values ( ) if not _entity . is_person ] if entity . is_person : for id_variable in id_variables + role_variables : assert id_variable in input_data_frame . columns , "Variable {} is not present in input dataframe" . format ( id_variable ) input_data_frame = self . filter_input_variables ( input_data_frame = input_data_frame , simulation = simulation ) if entity . is_person : entity . count = entity . step_size = len ( input_data_frame ) for collective_entity in simulation . entities . values ( ) : if collective_entity . is_person : continue _key = collective_entity . key _id_variable = self . id_variable_by_entity_key [ _key ] _role_variable = self . role_variable_by_entity_key [ _key ] collective_entity . count = len ( input_data_frame [ _id_variable ] . unique ( ) ) collective_entity . members_entity_id = input_data_frame [ _id_variable ] . astype ( 'int' ) . values collective_entity . members_legacy_role = input_data_frame [ _role_variable ] . astype ( 'int' ) . values for ( legacy_role , flattened_role ) in enumerate ( collective_entity . flattened_roles ) : if legacy_role < len ( collective_entity . flattened_roles ) : collective_entity . members_role = np . where ( collective_entity . members_legacy_role == legacy_role , flattened_role , collective_entity . members_role , ) else : collective_entity . members_role = np . where ( collective_entity . members_legacy_role >= len ( collective_entity . flattened_roles ) , collective_entity . flattened_roles [ - 1 ] , collective_entity . members_role , ) else : entity . count = entity . step_size = len ( input_data_frame ) for column_name , column_serie in input_data_frame . iteritems ( ) : if column_name in ( id_variables + role_variables ) : continue variable_instance = self . tax_benefit_system . variables . get ( column_name ) if variable_instance . entity . key != entity . key : log . info ( "Ignoring variable {} which is not part of entity {} but {}" . format ( column_name , entity . key , variable_instance . entity . key ) ) continue init_variable_in_entity ( entity = entity , variable_name = column_name , series = column_serie , period = period , )
Initialize the simulation period with current input_data_frame