import pickle
from shapely import wkt


def from_p_file(name):
    g = pickle.load(open(f'{name}.p', "rb"))
    return g


def dataframe_converter(df):
    for col in df.columns:
        if col in ['tags', 'members', 'nodes']:
            df[col] = df[col].apply(eval)  # convert lists as lists and dicts as dicts
        elif col in ['geom', 'proj_geom']:
            df[col] = df[col].apply(wkt.loads)  # convert string of shapes to shapely WKT
        else:
            continue
    return df