Skip to content

Commit

Permalink
Returns DataFrame When Concating Along Axis 1 (rapidsai#11263)
Browse files Browse the repository at this point in the history
fixes rapidsai#11244 

When concatenating along axis 1, pandas always return a dataframe even though there are only 1 column involved. This PR conforms cuDF to that behavior.

Authors:
  - Michael Wang (https://github.com/isVoid)

Approvers:
  - GALI PREM SAGAR (https://github.com/galipremsagar)

URL: rapidsai#11263
  • Loading branch information
isVoid authored Jul 14, 2022
1 parent 29918e3 commit 9034b1b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion python/cudf/cudf/core/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,14 @@ def concat(objs, axis=0, join="outer", ignore_index=False, sort=None):
index=cudf.RangeIndex(len(obj)),
)
else:
result = obj.copy()
if axis == 0:
result = obj.copy()
else:
data = obj._data.copy(deep=True)
if isinstance(obj, cudf.Series) and obj.name is None:
# If the Series has no name, pandas renames it to 0.
data[0] = data.pop(None)
result = cudf.DataFrame._from_data(data)

return result.sort_index(axis=axis) if sort else result

Expand Down
10 changes: 10 additions & 0 deletions python/cudf/cudf/tests/test_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,16 @@ def test_pandas_concat_compatibility_axis1_eq_index():
)


@pytest.mark.parametrize("name", [None, "a"])
def test_pandas_concat_compatibility_axis1_single_column(name):
# Pandas renames series name `None` to 0
# and preserves anything else
s = gd.Series([1, 2, 3], name=name)
got = gd.concat([s], axis=1)
expected = pd.concat([s.to_pandas()], axis=1)
assert_eq(expected, got)


def test_concat_duplicate_columns():
cdf = gd.DataFrame(
{
Expand Down

0 comments on commit 9034b1b

Please sign in to comment.