You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/03/08 06:10:14 UTC

[GitHub] [spark] xinrong-databricks commented on a change in pull request #35747: Support string and bool `regex` in `Series.replace`

xinrong-databricks commented on a change in pull request #35747:
URL: https://github.com/apache/spark/pull/35747#discussion_r821350474



##########
File path: python/pyspark/pandas/series.py
##########
@@ -4283,17 +4283,20 @@ def keys(self) -> "ps.Index":
         """
         return self.index
 
-    # TODO: 'regex', 'method' parameter
+    # TODO: introduce 'method', 'limit', 'in_place'; fully support 'regex'
     def replace(
         self,
         to_replace: Optional[Union[Any, List, Tuple, Dict]] = None,
         value: Optional[Union[List, Tuple]] = None,
-        regex: bool = False,
+        regex: Union[str, bool] = False,
     ) -> "Series":
         """
         Replace values given in to_replace with value.
         Values of the Series are replaced with other values dynamically.
 
+        .. note:: The API supports pattern matching (and replacement) on the whole string only,

Review comment:
       ```py
   >>> psser = ps.Series(['bat', 'foo', 'bait', 'abc', 'bar', 'zoo'])
   >>> psser.replace('ba', 'xx', regex=True)
   0     xx
   1    foo
   2     xx
   3    abc
   4     xx
   5    zoo
   dtype: object
   ```
   vs.
   ```py
   >>> pser = pd.Series(['bat', 'foo', 'bait', 'abc', 'bar', 'zoo'])
   >>> pser.replace('ba', 'xx', regex=True)
   0     xxt
   1     foo
   2    xxit
   3     abc
   4     xxr
   5     zoo
   dtype: object
   ```




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org