Skip to content

Commit 058dae1

Browse files
authored
Merge pull request scipy#21853 from mdhaber/replace_doc_followup
DOC: replace only first paragraph of rng documentation
2 parents 8523a03 + b815850 commit 058dae1

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

scipy/_lib/_util.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,11 @@ def _transition_to_rng(old_name, *, position_num=None, end_version=None,
342342
Whether the decorator should replace the documentation for parameter `rng` with
343343
`_rng_desc` (defined above), which documents both new `rng` keyword behavior
344344
and typical legacy `random_state`/`seed` behavior. If True, manually replace
345-
the function's old `random_state`/`seed` documentation with the desired *final*
346-
`rng` documentation; this way, no changes to documentation are needed when the
347-
decorator is removed. Use False if the function's old `random_state`/`seed`
348-
behavior does not match that described by `_rng_desc`.
345+
the first paragraph of the function's old `random_state`/`seed` documentation
346+
with the desired *final* `rng` documentation; this way, no changes to
347+
documentation are needed when the decorator is removed. Documentation of `rng`
348+
after the first blank line is preserved. Use False if the function's old
349+
`random_state`/`seed` behavior does not match that described by `_rng_desc`.
349350
350351
"""
351352
NEW_NAME = "rng"
@@ -446,10 +447,13 @@ def wrapper(*args, **kwargs):
446447
if 'rng' in parameter_names:
447448
_type = "{None, int, `numpy.random.Generator`}, optional"
448449
_desc = _rng_desc.replace("{old_name}", old_name)
449-
_rng_parameter_doc = Parameter('rng', _type, [_desc])
450+
old_doc = doc['Parameters'][parameter_names.index('rng')].desc
451+
old_doc_keep = old_doc[old_doc.index("") + 1:] if "" in old_doc else []
452+
new_doc = [_desc] + old_doc_keep
453+
_rng_parameter_doc = Parameter('rng', _type, new_doc)
450454
doc['Parameters'][parameter_names.index('rng')] = _rng_parameter_doc
451-
doc = str(doc).split("\n", 1)[1] # remove signature
452-
wrapper.__doc__ = str(doc)
455+
doc = str(doc).split("\n", 1)[1] # remove signature
456+
wrapper.__doc__ = str(doc)
453457
return wrapper
454458

455459
return decorator

0 commit comments

Comments
 (0)