@@ -356,23 +356,23 @@ def str_replace(arr, pat, repl, n=-1, case=None, flags=0, regex=True):
356
356
357
357
Examples
358
358
--------
359
- When `pat` is a string and `regex` is False, every `pat` is replaced with
360
- `repl` as with :meth:`str.replace`. NaN value(s) in the Series are left as
361
- is.
359
+ When `pat` is a string and `regex` is True (the default), the given `pat`
360
+ is compiled as a regex. When `repl` is a string, it replaces matching
361
+ regex patterns as with :meth:`re.sub`. NaN value(s) in the Series are
362
+ left as is:
362
363
363
- >>> pd.Series(['f.o ', 'fuz', np.nan]).str.replace('f.', 'ba', regex=False )
364
+ >>> pd.Series(['foo ', 'fuz', np.nan]).str.replace('f.', 'ba', regex=True )
364
365
0 bao
365
- 1 fuz
366
+ 1 baz
366
367
2 NaN
367
368
dtype: object
368
369
369
- When `pat` is a string and `regex` is True, the given `pat` is compiled
370
- as a regex. When `repl` is a string, it replaces matching regex patterns
371
- as with :meth:`re.sub`:
370
+ When `pat` is a string and `regex` is False, every `pat` is replaced with
371
+ `repl` as with :meth:`str.replace`:
372
372
373
- >>> pd.Series(['foo ', 'fuz', np.nan]).str.replace('f.', 'ba', regex=True )
373
+ >>> pd.Series(['f.o ', 'fuz', np.nan]).str.replace('f.', 'ba', regex=False )
374
374
0 bao
375
- 1 baz
375
+ 1 fuz
376
376
2 NaN
377
377
dtype: object
378
378
@@ -414,6 +414,13 @@ def str_replace(arr, pat, repl, n=-1, case=None, flags=0, regex=True):
414
414
1 bar
415
415
2 NaN
416
416
dtype: object
417
+
418
+ Raises
419
+ ------
420
+ ValueError
421
+ * if `regex` is False and `repl` is a callable or `pat` is a compiled
422
+ regex
423
+ * if `pat` is a compiled regex and `case` or `flags` is set
417
424
"""
418
425
419
426
# Check whether repl is valid (GH 13438, GH 15055)
0 commit comments