Skip to content

openavmkit.utilities._utils

to_parquet_safe

to_parquet_safe(df, path, geometry_col=None)

Writes the dataframe to parquet, performing a bunch of safety checks so you don't have to

Parameters:

Name Type Description Default
df DataFrame

Pandas dataframe or geopandas geodataframe

required
path str

The path you want to write the parquet to

required
geometry_col str

The name of the geometry column. Default is None

None
Source code in openavmkit/utilities/_utils.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def to_parquet_safe(df : pd.DataFrame, path: str, geometry_col : str | None = None):
    """
    Writes the dataframe to parquet, performing a bunch of safety checks so you don't have to

    Parameters
    ----------
    df : pd.DataFrame
        Pandas dataframe or geopandas geodataframe
    path : str
        The path you want to write the parquet to
    geometry_col : str
        The name of the geometry column. Default is None
    """
    df_san = sanitize_df(df, geometry_col = geometry_col)
    if hasattr(df_san, 'to_numpy'):
        if hasattr(df_san, 'geometry'):  # GeoDataFrame-like
            df_san.to_parquet(path, engine="pyarrow")
        else:  # DataFrame-like
            df_san.to_parquet(path)
    else:
        raise TypeError("df must be a DataFrame.")