data_algebra/pandas_base.py
def columns_to_frame_(self, cols, *, target_rows=0):
        """
        Convert a dictionary of column names to series-like objects and scalars into a Pandas data frame.

        :param cols: dictionary mapping column names to columns
        :param target_rows: number of rows we are shooting for
        :return: Pandas data frame.
        """
        # noinspection PyUnresolvedReferences
        assert isinstance(cols, dict)
        if len(cols) < 1:
            return self.pd.DataFrame(cols)
        for k, v in cols.items():
            try:
                target_rows = max(target_rows, len(v))
            except TypeError:
                target_rows = max(target_rows, 1)  # scalar
        if target_rows < 1:
            return self.pd.DataFrame(cols)

        # agg can return scalars, which then can't be made into a self.pd.DataFrame
        def promote_scalar(vi, *, target_len):
            # noinspection PyBroadException
            try:
                len_v = len(vi)
                if len_v != target_len:
                    if len_v == 0:
                        return [None] * target_len
                    elif len_v == 1:
                        return [vi[0]] * target_len
                    else:
                        raise ValueError("incompatible column lengths")
            except Exception:
                return [vi] * target_len  # scalar
            return vi

        cols = {k: promote_scalar(v, target_len=target_rows) for (k, v) in cols.items()}
        return self.pd.DataFrame(cols)

        Convert a dictionary of column names to series-like objects and scalars into a Pandas data frame.

        :param cols: dictionary mapping column names to columns
        :param target_rows: number of rows we are shooting for
        :return: Pandas data frame.
        
Convert a dictionary of column names to series-like objects and scalars into a Pandas data frame.
Convert a dictionary of column names to series - like objects and scalars into a Pandas data frame .
def columns_to_frame_(self, cols, *, target_rows=0):
        assert isinstance(cols, dict)
        if len(cols) < 1:
            return self.pd.DataFrame(cols)
        for k, v in cols.items():
            try:
                target_rows = max(target_rows, len(v))
            except TypeError:
                target_rows = max(target_rows, 1)  
        if target_rows < 1:
            return self.pd.DataFrame(cols)
        def promote_scalar(vi, *, target_len):
            try:
                len_v = len(vi)
                if len_v != target_len:
                    if len_v == 0:
                        return [None] * target_len
                    elif len_v == 1:
                        return [vi[0]] * target_len
                    else:
                        raise ValueError("incompatible column lengths")
            except Exception:
                return [vi] * target_len  
            return vi
        cols = {k: promote_scalar(v, target_len=target_rows) for (k, v) in cols.items()}
        return self.pd.DataFrame(cols)
def columns_to_frame_ ( self , cols , * , target_rows = 0 ) : assert isinstance ( cols , dict ) if len ( cols ) < 1 : return self . pd . DataFrame ( cols ) for k , v in cols . items ( ) : try : target_rows = max ( target_rows , len ( v ) ) except TypeError : target_rows = max ( target_rows , 1 ) if target_rows < 1 : return self . pd . DataFrame ( cols ) def promote_scalar ( vi , * , target_len ) : try : len_v = len ( vi ) if len_v != target_len : if len_v == 0 : return [ None ] * target_len elif len_v == 1 : return [ vi [ 0 ] ] * target_len else : raise ValueError ( "incompatible column lengths" ) except Exception : return [ vi ] * target_len return vi cols = { k : promote_scalar ( v , target_len = target_rows ) for ( k , v ) in cols . items ( ) } return self . pd . DataFrame ( cols )
Convert a dictionary of column names to series-like objects and scalars into a Pandas data frame.
Convert a dictionary of column names to series - like objects and scalars into a Pandas data frame .
"""
        Convert a dictionary of column names to series-like objects and scalars into a Pandas data frame.

        :param cols: dictionary mapping column names to columns
        :param target_rows: number of rows we are shooting for
        :return: Pandas data frame.
        """ # noinspection PyUnresolvedReferences # scalar # agg can return scalars, which then can't be made into a self.pd.DataFrame # noinspection PyBroadException # scalar
Pandas data frame.
Pandas data frame .
self
cols
dictionary mapping column names to columns
dictionary mapping column names to columns
target_rows
number of rows we are shooting for
number of rows we are shooting for