@@ -356,23 +356,23 @@ def str_replace(arr, pat, repl, n=-1, case=None, flags=0, regex=True):
356356
357357 Examples
358358 --------
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:
362363
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 )
364365 0 bao
365- 1 fuz
366+ 1 baz
366367 2 NaN
367368 dtype: object
368369
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`:
372372
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 )
374374 0 bao
375- 1 baz
375+ 1 fuz
376376 2 NaN
377377 dtype: object
378378
@@ -414,6 +414,13 @@ def str_replace(arr, pat, repl, n=-1, case=None, flags=0, regex=True):
414414 1 bar
415415 2 NaN
416416 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
417424 """
418425
419426 # Check whether repl is valid (GH 13438, GH 15055)
0 commit comments