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] Fix .str.cat when objects with different index are passed #5844

Merged
merged 14 commits into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from 13 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 @@ -257,6 +257,7 @@
- PR #5820 Fix ListColumn.to_arrow for all null case
- PR #5837 Bash syntax error in prebuild.sh preventing `cudf_kafka` and `libcudf_kafka` from being uploaded to Anaconda
- PR #5841 Added custreamz functions that were missing in interface layer
- PR #5844 Fix `.str.cat` when objects with different index are passed
- PR #5849 Modify custreamz api to integrate seamlessly with python streamz


Expand Down
30 changes: 24 additions & 6 deletions python/cudf/cudf/core/column/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def cat(self, others=None, sep=None, na_rep=None, **kwargs):
self._column, as_scalar(sep), as_scalar(na_rep, "str")
)
else:
other_cols = _get_cols_list(others)
other_cols = _get_cols_list(self._parent, others)
all_cols = [self._column] + other_cols
data = cpp_concatenate(
cudf.DataFrame(
Expand All @@ -428,10 +428,10 @@ def cat(self, others=None, sep=None, na_rep=None, **kwargs):
data = [""]
out = self._return_or_inplace(data, **kwargs)
if len(out) == 1 and others is None:
if isinstance(out, StringColumn):
out = out[0]
else:
if isinstance(out, cudf.Series):
out = out.iloc[0]
else:
out = out[0]
return out

def join(self, sep):
Expand Down Expand Up @@ -4739,7 +4739,11 @@ def _string_column_binop(lhs, rhs, op, out_dtype):
return out


def _get_cols_list(others):
def _get_cols_list(parent_obj, others):

parent_index = (
parent_obj.index if isinstance(parent_obj, cudf.Series) else parent_obj
)
kkraus14 marked this conversation as resolved.
Show resolved Hide resolved

if (
can_convert_to_column(others)
Expand All @@ -4756,9 +4760,23 @@ def _get_cols_list(others):
If others is a list-like object (in our case lists & tuples)
just another Series/Index, great go ahead with concatenation.
"""
cols_list = [column.as_column(frame, dtype="str") for frame in others]
cols_list = [
column.as_column(frame.reindex(parent_index), dtype="str")
if (
isinstance(frame, cudf.Series)
and not frame.index.equals(parent_index)
)
else column.as_column(frame, dtype="str")
for frame in others
]

return cols_list
elif others is not None:
if isinstance(others, cudf.Series) and not others.index.equals(
parent_index
):
others = others.reindex(parent_index)

return [column.as_column(others, dtype="str")]
else:
raise TypeError(
Expand Down
Loading