Skip to content

Commit b1be33d

Browse files
committed
fix + test
1 parent cfd695b commit b1be33d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

python/pyspark/pandas/strings.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2031,7 +2031,13 @@ def pudf(s: pd.Series) -> pd.Series:
20312031
if expand:
20322032
psdf = psser.to_frame()
20332033
scol = psdf._internal.data_spark_columns[0]
2034-
spark_columns = [scol[i].alias(str(i)) for i in range(n + 1)]
2034+
2035+
if ps.get_option("compute.ansi_mode_support"):
2036+
spark_columns = [
2037+
F.try_element_at(scol, F.lit(i + 1)).alias(str(i)) for i in range(n + 1)
2038+
]
2039+
else:
2040+
spark_columns = [scol[i].alias(str(i)) for i in range(n + 1)]
20352041
column_labels = [(i,) for i in range(n + 1)]
20362042
internal = psdf._internal.with_new_columns(
20372043
spark_columns,

python/pyspark/pandas/tests/series/test_string_ops_adv.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ def test_string_split(self):
185185
with self.assertRaises(NotImplementedError):
186186
self.check_func(lambda x: x.str.split(expand=True))
187187

188+
self.check_func_on_series(lambda x: repr(x.str.split("-", n=1, expand=True)), pser)
189+
188190
@unittest.skipIf(is_ansi_mode_test, ansi_mode_not_supported_message)
189191
def test_string_rsplit(self):
190192
self.check_func_on_series(lambda x: repr(x.str.rsplit()), self.pser[:-1])

0 commit comments

Comments
 (0)