Skip to content

[SPARK-52592][PS] Prevent error when creating ps.Series from ps.Series #51300

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 8 additions & 3 deletions python/pyspark/pandas/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,14 +398,19 @@ def __init__( # type: ignore[no-untyped-def]

self._anchor: DataFrame # type: ignore[annotation-unchecked]
self._col_label: Label # type: ignore[annotation-unchecked]
if isinstance(data, DataFrame):
if isinstance(data, (DataFrame, Series)):
assert dtype is None
assert name is None
assert not copy
assert not fastpath

self._anchor = data
self._col_label = index
if isinstance(data, Series):
assert index is None
self._anchor = DataFrame(data)
self._col_label = self._anchor._internal.column_labels[0]
else:
self._anchor = data
self._col_label = index
else:
if isinstance(data, pd.Series):
assert index is None
Expand Down
5 changes: 5 additions & 0 deletions python/pyspark/pandas/tests/series/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ def test_empty_series(self):

self.assertTrue(pser_a.empty)

def test_series_from_series(self):
pser = ps.Series([1, 2, 3, 4, 5, 6, 7], name="x")

self.assert_eq(ps.Series(pser), pser)

def test_all_null_series(self):
pser_a = pd.Series([None, None, None], dtype="float64")
pser_b = pd.Series([None, None, None], dtype="str")
Expand Down