8000 DOC: Fix records doctests by improving docstrings · numpy/numpy@f3bde7c · GitHub
[go: up one dir, main page]

Skip to content

Commit f3bde7c

Browse files
committed
DOC: Fix records doctests by improving docstrings
1 parent 1843401 commit f3bde7c

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

numpy/core/records.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ def fromstring(datastring, dtype=None, shape=None, offset=0, formats=None,
816816
817817
>>> s = '\x01\x02\x03abc'
818818
>>> np.core.records.fromstring(s, dtype='u1,u1,u1,S3')
819-
Traceback (most recent call last)
819+
Traceback (most recent call last):
820820
...
821821
TypeError: a bytes-like object is required, not 'str'
822822
"""
@@ -881,18 +881,21 @@ def fromfile(fd, dtype=None, shape=None, offset=0, formats=None,
881881
>>> from tempfile import TemporaryFile
882882
>>> a = np.empty(10,dtype='f8,i4,a5')
883883
>>> a[5] = (0.5,10,'abcde')
884-
>>>
885-
>>> fd=TemporaryFile()
886-
>>> a = a.newbyteorder('<')
887-
>>> a.tofile(fd)
888-
>>>
889-
>>> _ = fd.seek(0)
890-
>>> r=np.core.records.fromfile(fd, formats='f8,i4,a5', shape=10,
891-
... byteorder='<')
884+
885+
Save and load from a temporary file enforcing a little endian byte-order.
886+
887+
>>> with TemporaryFile() as fd:
888+
... a = a.newbyteorder('<')
889+
... a.tofile(fd)
890+
...
891+
... _ = fd.seek(0)
892+
... r = np.core.records.fromfile(fd, formats='f8,i4,a5', shape=10,
893+
... byteorder='<')
892894
>>> print(r[5])
893895
(0.5, 10, 'abcde')
894896
>>> r.shape
895897
(10,)
898+
896899
"""
897900

898901
if dtype is None and formats is None:

0 commit comments

Comments
 (0)
0