def _union()

in awswrangler/s3/_read.py [0:0]


def _union(dfs: List[pd.DataFrame], ignore_index: Optional[bool]) -> pd.DataFrame:
    if ignore_index is None:
        ignore_index = False
        for df in dfs:
            if hasattr(df, "_awswrangler_ignore_index"):
                if df._awswrangler_ignore_index is True:  # pylint: disable=protected-access
                    ignore_index = True
                    break
    cats: Tuple[Set[str], ...] = tuple(set(df.select_dtypes(include="category").columns) for df in dfs)
    for col in set.intersection(*cats):
        cat = union_categoricals([df[col] for df in dfs])
        for df in dfs:
            df[col] = pd.Categorical(df[col].values, categories=cat.categories)
    return pd.concat(objs=dfs, sort=False, copy=False, ignore_index=ignore_index)