in awswrangler/_data_types.py [0:0]
def cast_pandas_with_athena_types(df: pd.DataFrame, dtype: Dict[str, str]) -> pd.DataFrame:
"""Cast columns in a Pandas DataFrame."""
mutability_ensured: bool = False
for col, athena_type in dtype.items():
if (
(col in df.columns)
and (athena_type.startswith("array") is False)
and (athena_type.startswith("struct") is False)
and (athena_type.startswith("map") is False)
):
desired_type: str = athena2pandas(dtype=athena_type)
current_type: str = _normalize_pandas_dtype_name(dtype=str(df[col].dtypes))
if desired_type != current_type: # Needs conversion
_logger.debug("current_type: %s -> desired_type: %s", current_type, desired_type)
if mutability_ensured is False:
df = _utils.ensure_df_is_mutable(df=df)
mutability_ensured = True
_cast_pandas_column(df=df, col=col, current_type=current_type, desired_type=desired_type)
return df