Serialize a GeoPandas dataframe to a geojson format Python dictionary / file

def gdf_to_geojson(gdf, date_format='epoch', properties=None, filename=None):
    """Serialize a GeoPandas dataframe to a geojson format Python dictionary / file
    """

    # convert dates/datetimes to preferred string format if specified
    gdf = convert_date_columns(gdf, date_format)

    gdf_out = gdf[['geometry'] + properties or []]

    geojson_str = gdf_out.to_json()

    if filename:
        with codecs.open(filename, "w", "utf-8-sig") as f:
            f.write(geojson_str)
        return None
    else:
        return json.loads(geojson_str)