How to use the pymer4.utils._df_meta_to_arr function in pymer4

To help you get started, we’ve selected a few pymer4 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ejolly / pymer4 / pymer4 / io.py View on Github external
data_atts_separated = {}
        for k, v in data_atts.items():
            if k != 'model_obj':
                # Deconstruct pandas dataframes
                if isinstance(v, pd.DataFrame):
                    cols, idx = _df_meta_to_arr(v)
                    vals = v.values
                    dtypes = v.dtypes.to_dict()
                    data_atts_separated[f"df_cols__{k}"] = cols
                    data_atts_separated[f"df_idx__{k}"] = idx
                    data_atts_separated[f"df_vals__{k}"] = vals
                    data_atts_separated[f"df_dtypes__{k}"] = dtypes
                elif isinstance(v, list):
                    for i, elem in enumerate(v):
                        if isinstance(elem, pd.DataFrame):
                            cols, idx = _df_meta_to_arr(elem)
                            vals = elem.values
                            dtypes = elem.dtypes.to_dict()
                            data_atts_separated[f"list_{i}_cols__{k}"] = cols
                            data_atts_separated[f"list_{i}_idx__{k}"] = idx
                            data_atts_separated[f"list_{i}_vals__{k}"] = vals
                            data_atts_separated[f"list_{i}_dtypes__{k}"] = dtypes
                        else:
                            raise TypeError(f"Value is list but list item is {type(elem)} not pd.DataFrame")
        
        # Combine all attributes into a single dict and save with dd
        model_atts = {}
        model_atts['simple_atts'] = simple_atts
        model_atts['data_atts'] = data_atts_separated
        with warnings.catch_warnings():
            warnings.simplefilter("ignore", category=FutureWarning)
            warnings.simplefilter("ignore", category=NaturalNameWarning)
github ejolly / pymer4 / pymer4 / io.py View on Github external
elif isinstance(v, list):
                if any([isinstance(elem, pd.DataFrame) for elem in v]):
                    skip = True
            if not skip:
                simple_atts[k] = v
            else:
                data_atts[k] = v
        simple_atts['model_class'] = model.__class__.__name__

        # Now deal with other attributes
        data_atts_separated = {}
        for k, v in data_atts.items():
            if k != 'model_obj':
                # Deconstruct pandas dataframes
                if isinstance(v, pd.DataFrame):
                    cols, idx = _df_meta_to_arr(v)
                    vals = v.values
                    dtypes = v.dtypes.to_dict()
                    data_atts_separated[f"df_cols__{k}"] = cols
                    data_atts_separated[f"df_idx__{k}"] = idx
                    data_atts_separated[f"df_vals__{k}"] = vals
                    data_atts_separated[f"df_dtypes__{k}"] = dtypes
                elif isinstance(v, list):
                    for i, elem in enumerate(v):
                        if isinstance(elem, pd.DataFrame):
                            cols, idx = _df_meta_to_arr(elem)
                            vals = elem.values
                            dtypes = elem.dtypes.to_dict()
                            data_atts_separated[f"list_{i}_cols__{k}"] = cols
                            data_atts_separated[f"list_{i}_idx__{k}"] = idx
                            data_atts_separated[f"list_{i}_vals__{k}"] = vals
                            data_atts_separated[f"list_{i}_dtypes__{k}"] = dtypes