(self, source, destination)
Compute the conversion indices from the given `source` to `destination`
Compute the conversion indices from the given `source` to `destination`
Compute the conversion indices from the given source to destination
def __init__(self, source, destination):
        """
        Compute the conversion indices from the given `source` to `destination`
        """
        def match(var):
            if var in source:
                sourcevar = source[var]
                sourceindex = source.index(sourcevar)
                if var.is_discrete and var is not sourcevar:
                    mapping = var.get_mapper_from(sourcevar)
                    return lambda table: mapping(table.get_column_view(sourceindex)[0])
                return source.index(var)
            return var.compute_value  # , which may also be None

        self.source = source

        self.attributes = [match(var) for var in destination.attributes]
        self.class_vars = [match(var) for var in destination.class_vars]
        self.variables = self.attributes + self.class_vars
        self.metas = [match(var) for var in destination.metas]

        def should_be_sparse(feats):
            """
            For a matrix to be stored in sparse, more than 2/3 of columns
            should be marked as sparse and there should be no string columns
            since Scipy's sparse matrices don't support dtype=object.
            """
            fraction_sparse = sum(f.sparse for f in feats) / max(len(feats), 1)
            contain_strings = any(f.is_string for f in feats)
            return fraction_sparse > 2/3 and not contain_strings

        # check whether X, Y or metas should be sparse
        self.sparse_X = should_be_sparse(destination.attributes)
        self.sparse_Y = should_be_sparse(destination.class_vars)
        self.sparse_metas = should_be_sparse(destination.metas)
def __init__ ( self , source , destination ) : def match ( var ) : if var in source : sourcevar = source [ var ] sourceindex = source . index ( sourcevar ) if var . is_discrete and var is not sourcevar : mapping = var . get_mapper_from ( sourcevar ) return lambda table : mapping ( table . get_column_view ( sourceindex ) [ 0 ] ) return source . index ( var ) return var . compute_value # , which may also be None self . source = source self . attributes = [ match ( var ) for var in destination . attributes ] self . class_vars = [ match ( var ) for var in destination . class_vars ] self . variables = self . attributes + self . class_vars self . metas = [ match ( var ) for var in destination . metas ] def should_be_sparse ( feats ) : """
            For a matrix to be stored in sparse, more than 2/3 of columns
            should be marked as sparse and there should be no string columns
            since Scipy's sparse matrices don't support dtype=object.
            """ fraction_sparse = sum ( f . sparse for f in feats ) / max ( len ( feats ) , 1 ) contain_strings = any ( f . is_string for f in feats ) return fraction_sparse > 2 / 3 and not contain_strings # check whether X, Y or metas should be sparse self . sparse_X = should_be_sparse ( destination . attributes ) self . sparse_Y = should_be_sparse ( destination . class_vars ) self . sparse_metas = should_be_sparse ( destination . metas )