diff options
author | Takanori H <takanori17h@gmail.com> | 2020-06-10 00:26:15 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-09 18:26:15 +0300 |
commit | ad30b31af0bb3fbfdc0f11486807edc76cec2680 (patch) | |
tree | bc0cba5148bc1b1abb275cd7ac784629d4a552fe | |
parent | e73c8e5479297f235b37fba91d6d0e8464be66a6 (diff) | |
download | numpy-ad30b31af0bb3fbfdc0f11486807edc76cec2680.tar.gz |
DOC: Fix ``np.ma.core.doc_note`` (#16311)
* fix np.ma.core.doc_note
-rw-r--r-- | numpy/ma/core.py | 12 | ||||
-rw-r--r-- | numpy/ma/tests/test_core.py | 34 |
2 files changed, 35 insertions, 11 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py index 8d612b8ed..b5371f51a 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -21,6 +21,7 @@ Released for unlimited redistribution. """ # pylint: disable-msg=E1002 import builtins +import inspect import operator import warnings import textwrap @@ -122,15 +123,8 @@ def doc_note(initialdoc, note): if note is None: return initialdoc - notesplit = re.split(r'\n\s*?Notes\n\s*?-----', initialdoc) - - notedoc = """\ -Notes - ----- - %s""" % note - - if len(notesplit) > 1: - notedoc = '\n\n ' + notedoc + '\n' + notesplit = re.split(r'\n\s*?Notes\n\s*?-----', inspect.cleandoc(initialdoc)) + notedoc = "\n\nNotes\n-----\n%s\n" % inspect.cleandoc(note) return ''.join(notesplit[:1] + [notedoc] + notesplit[1:]) diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index 6f34144bb..76a92f5ca 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -34,8 +34,8 @@ from numpy.ma.core import ( MAError, MaskError, MaskType, MaskedArray, abs, absolute, add, all, allclose, allequal, alltrue, angle, anom, arange, arccos, arccosh, arctan2, arcsin, arctan, argsort, array, asarray, choose, concatenate, - conjugate, cos, cosh, count, default_fill_value, diag, divide, empty, - empty_like, equal, exp, flatten_mask, filled, fix_invalid, + conjugate, cos, cosh, count, default_fill_value, diag, divide, doc_note, + empty, empty_like, equal, exp, flatten_mask, filled, fix_invalid, flatten_structured_array, fromflex, getmask, getmaskarray, greater, greater_equal, identity, inner, isMaskedArray, less, less_equal, log, log10, make_mask, make_mask_descr, mask_or, masked, masked_array, @@ -5283,3 +5283,33 @@ def test_mask_shape_assignment_does_not_break_masked(): b = np.ma.array(1, mask=a.mask) b.shape = (1,) assert_equal(a.mask.shape, ()) + +@pytest.mark.skipif(sys.flags.optimize > 1, + reason="no docstrings present to inspect when PYTHONOPTIMIZE/Py_OptimizeFlag > 1") +def test_doc_note(): + def method(self): + """This docstring + + Has multiple lines + + And notes + + Notes + ----- + original note + """ + pass + + expected_doc = """This docstring + +Has multiple lines + +And notes + +Notes +----- +note + +original note""" + + assert_equal(np.ma.core.doc_note(method.__doc__, "note"), expected_doc) |