Skip to content
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

[REVIEW] concat(): support sub-types and object wrappers #5879

Merged
merged 6 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
- PR #5853 Disable `fixed_point` for use in `copy_if`
- PR #5854 Raise informative error in `DataFrame.iterrows` and `DataFrame.itertuples`
- PR #5863 Explicitly require `ucx-py` on CI
- PR #5879 Added support of sub-types and object wrappers in concat()

## Bug Fixes

Expand Down
26 changes: 20 additions & 6 deletions python/cudf/cudf/core/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,26 @@ def concat(objs, axis=0, ignore_index=False, sort=None):
if len(objs) == 0:
raise ValueError("All objects passed were None")

typs = set(type(o) for o in objs)
# Retrieve the base types of `objs`. In order to support sub-types
# and object wrappers, we use `isinstance()` instead of comparing
# types directly
typs = set()
for o in objs:
if isinstance(o, DataFrame):
typs.add(DataFrame)
elif isinstance(o, Series):
typs.add(Series)
elif isinstance(o, cudf.MultiIndex):
typs.add(cudf.MultiIndex)
elif issubclass(type(o), Index):
typs.add(Index)
else:
raise ValueError(
"`concat` cannot concatenate object of type: {0!r}".format(
type(o)
)
)

allowed_typs = {Series, DataFrame}

param_axis = _axis_map.get(axis, None)
Expand Down Expand Up @@ -247,11 +266,6 @@ def concat(objs, axis=0, ignore_index=False, sort=None):
# both Series & DataFrame kind of inputs.
_normalize_series_and_dataframe(objs, axis=axis)
typ = DataFrame
else:
raise ValueError(
"`concat` cannot concatenate objects of "
"types: %r." % sorted([t.__name__ for t in typs])
)

if typ is DataFrame:
objs = [obj for obj in objs if obj.shape != (0, 0)]
Expand Down