Skip to content

fix: concat with union categories #3127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion awswrangler/s3/_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ def _extract_partitions_dtypes_from_table_details(response: "GetTableResponseTyp
return dtypes


def _union(dfs: list[pd.DataFrame], ignore_index: bool) -> pd.DataFrame:
def _concat_union_categoricals(dfs: list[pd.DataFrame], ignore_index: bool) -> pd.DataFrame:
"""Concatenate dataframes with union of categorical columns."""
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])
Expand Down
3 changes: 2 additions & 1 deletion awswrangler/s3/_read_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from awswrangler.s3._read import (
_apply_partition_filter,
_check_version_id,
_concat_union_categoricals,
_extract_partitions_dtypes_from_table_details,
_get_num_output_blocks,
_get_path_ignore_suffix,
Expand Down Expand Up @@ -264,7 +265,7 @@ def _read_parquet_chunked(
yield df
else:
if next_slice is not None:
df = pd.concat(objs=[next_slice, df], sort=False, copy=False)
df = _concat_union_categoricals(dfs=[next_slice, df], ignore_index=False)
while len(df.index) >= chunked:
yield df.iloc[:chunked, :].copy()
df = df.iloc[chunked:, :]
Expand Down
4 changes: 2 additions & 2 deletions awswrangler/s3/_read_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
from awswrangler.s3._read import (
_apply_partition_filter,
_check_version_id,
_concat_union_categoricals,
_get_num_output_blocks,
_get_path_ignore_suffix,
_get_path_root,
_union,
)
from awswrangler.s3._read_text_core import _read_text_file, _read_text_files_chunked
from awswrangler.typing import RaySettings
Expand Down Expand Up @@ -70,7 +70,7 @@ def _read_text(
itertools.repeat(s3_additional_kwargs),
itertools.repeat(dataset),
)
return _union(dfs=tables, ignore_index=ignore_index)
return _concat_union_categoricals(dfs=tables, ignore_index=ignore_index)


def _read_text_format(
Expand Down