xinrong-databricks commented on a change in pull request #35747:
URL: https://github.com/apache/spark/pull/35747#discussion_r822528560
##########
File path: python/pyspark/pandas/series.py
##########
@@ -4440,13 +4449,45 @@ def replace(
weight 1.0
length 0.3
dtype: float64
+
+ Regular expression `to_replace`
+
+ >>> psser = ps.Series(['bat', 'foo', 'bait', 'abc', 'bar', 'zoo'])
+ >>> psser.replace(to_replace=r'^ba.$', value='new', regex=True)
+ 0 new
+ 1 foo
+ 2 bait
+ 3 abc
+ 4 new
+ 5 zoo
+ dtype: object
+
+ >>> psser.replace(value='new', regex=r'^.oo$')
+ 0 bat
+ 1 new
+ 2 bait
+ 3 abc
+ 4 bar
+ 5 new
+ dtype: object
"""
+ if isinstance(regex, str):
+ if to_replace is not None:
+ raise ValueError("'to_replace' must be 'None' if 'regex' is
not a bool")
+ to_replace = regex
+ regex = True
+ elif not isinstance(regex, bool):
+ raise NotImplementedError("regex of %s type is supported" %
type(regex).__name__)
Review comment:
Good catch! Thanks
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]