8000 DOC: Fix ``np.ma.core.doc_note`` (#16311) · numpy/numpy@ad30b31 · GitHub
[go: up one dir, main page]

Skip to content

Commit ad30b31

Browse files
DOC: Fix np.ma.core.doc_note (#16311)
* fix np.ma.core.doc_note
1 parent e73c8e5 commit ad30b31

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

numpy/ma/core.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"""
2222
# pylint: disable-msg=E1002
2323
import builtins
24+
import inspect
2425
import operator
2526
import warnings
2627
import textwrap
@@ -122,15 +123,8 @@ def doc_note(initialdoc, note):
122123
if note is None:
123124
return initialdoc
124125

125-
notesplit = re.split(r'\n\s*?Notes\n\s*?-----', initialdoc)
126-
127-
notedoc = """\
128-
Notes
129-
-----
130-
%s""" % note
131-
132-
if len(notesplit) > 1:
133-
notedoc = '\n\n ' + notedoc + '\n'
126+
notesplit = re.split(r'\n\s*?Notes\n\s*?-----', inspect.cleandoc(initialdoc))
127+
notedoc = "\n\nNotes\n-----\n%s\n" % inspect.cleandoc(note)
134128

135129
return ''.join(notesplit[:1] + [notedoc] + notesplit[1:])
136130

numpy/ma/tests/test_core.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
MAError, MaskError, MaskType, MaskedArray, abs, absolute, add, all,
3535
allclose, allequal, alltrue, angle, anom, arange, arccos, arccosh, arctan2,
3636
arcsin, arctan, argsort, array, asarray, choose, concatenate,
37-
conjugate, cos, cosh, count, default_fill_value, diag, divide, empty,
38-
empty_like, equal, exp, flatten_mask, filled, fix_invalid,
37+
conjugate, cos, cosh, count, default_fill_value, diag, divide, doc_note,
38+
empty, empty_like, equal, exp, flatten_mask, filled, fix_invalid,
3939
flatten_structured_array, fromflex, getmask, getmaskarray, greater,
4040
greater_equal, identity, inner, isMaskedArray, less, less_equal, log,
4141
log10, make_mask, make_mask_descr, mask_or, masked, masked_array,
@@ -5283,3 +5283,33 @@ def test_mask_shape_assignment_does_not_break_masked():
52835283
b = np.ma.array(1, mask=a.mask)
52845284
b.shape = (1,)
52855285
assert_equal(a.mask.shape, ())
5286+
5287+
@pytest.mark.skipif(sys.flags.optimize > 1,
5288+
reason="no docstrings present to inspect when PYTHONOPTIMIZE/Py_OptimizeFlag > 1")
5289+
def test_doc_note():
5290+
def method(self):
5291+
"""This docstring
5292+
5293+
Has multiple lines
5294+
5295+
And notes
5296+
5297+
Notes
5298+
-----
5299+
original note
5300+
"""
5301+
pass
5302+
5303+
expected_doc = """This docstring
5304+
5305+
Has multiple lines
5306+
5307+
And notes
5308+
5309+
Notes
5310+
-----
5311+
note
5312+
5313+
original note"""
5314+
5315+
assert_equal(np.ma.core.doc_note(method.__doc__, "note"), expected_doc)

0 commit comments

Comments
 (0)
0