<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _cast_empty_df_dtypes(schema_fields, df):
 """Cast any columns in an empty dataframe to correct type. In an empty dataframe, pandas cannot choose a dtype unless one is explicitly provided. The _bqschema_to_nullsafe_dtypes() function only provides dtypes when the dtype safely handles null values. This means that empty int64 and boolean columns are incorrectly classified as ``object``. """

    if not df.empty:
        raise ValueError(
            "DataFrame must be empty in order to cast non-nullsafe dtypes"
        )

    dtype_map = {"BOOLEAN": bool, "INTEGER": np.int64}

    for field in schema_fields:
        column = str(field["name"])
        if field["mode"].upper() == "REPEATED":
            continue

        dtype = dtype_map.get(field["type"].upper())
        if dtype:
            df[column] = df[column].astype(dtype)

    return df