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

Ensure cudf.Series(cudf.Series(...)) creates a reference to the same index #15845

Merged
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
4 changes: 3 additions & 1 deletion python/cudf/cudf/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,10 @@ def __init__(
data = data.copy(deep=True)
name_from_data = data.name
column = as_column(data, nan_as_null=nan_as_null, dtype=dtype)
if isinstance(data, (pd.Series, Series)):
if isinstance(data, pd.Series):
index_from_data = as_index(data.index)
elif isinstance(data, Series):
index_from_data = data.index
elif isinstance(data, ColumnAccessor):
raise TypeError(
"Use cudf.Series._from_data for constructing a Series from "
Expand Down
6 changes: 6 additions & 0 deletions python/cudf/cudf/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2835,3 +2835,9 @@ def test_timedelta_series_init(data):
actual = cudf.Series(scalar)

assert_eq(expected, actual)


def test_series_from_series_index_no_shallow_copy():
ser1 = cudf.Series(range(3), index=list("abc"))
ser2 = cudf.Series(ser1)
assert ser1.index is ser2.index
Loading