diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2017-07-28 20:59:45 +0100 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2017-10-19 00:26:44 -0700 |
commit | 6bc01b4e6187c8689e9e82e020a47b765e4f8fb3 (patch) | |
tree | 3680ab354d11faad7f5b1720c58cbc351563215a /numpy/add_newdocs.py | |
parent | e657629bbc2bfb880a1b2fa24a39c5921c1f965e (diff) | |
download | numpy-6bc01b4e6187c8689e9e82e020a47b765e4f8fb3.tar.gz |
DEP: Letting fromstring pretend to be frombuffer is a bad idea
Interpreting a unicode string as raw binary data is a terrible idea, especially if the encoding is determined by the system (python 2)
Diffstat (limited to 'numpy/add_newdocs.py')
-rw-r--r-- | numpy/add_newdocs.py | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/numpy/add_newdocs.py b/numpy/add_newdocs.py index ce2f1c6ec..7175a0e0b 100644 --- a/numpy/add_newdocs.py +++ b/numpy/add_newdocs.py @@ -961,7 +961,7 @@ add_newdoc('numpy.core.multiarray', 'fromstring', """ fromstring(string, dtype=float, count=-1, sep='') - A new 1-D array initialized from raw binary or text data in a string. + A new 1-D array initialized from text data in a string. Parameters ---------- @@ -975,11 +975,13 @@ add_newdoc('numpy.core.multiarray', 'fromstring', negative (the default), the count will be determined from the length of the data. sep : str, optional - If not provided or, equivalently, the empty string, the data will - be interpreted as binary data; otherwise, as ASCII text with - decimal numbers. Also in this latter case, this argument is - interpreted as the string separating numbers in the data; extra - whitespace between elements is also ignored. + The string separating numbers in the data; extra whitespace between + elements is also ignored. + + .. deprecated:: 1.14 + If this argument is not provided `fromstring` falls back on the + behaviour of `frombuffer`, after encoding unicode string inputs as + either utf-8 (python 3), or the default encoding (python 2). Returns ------- @@ -998,14 +1000,10 @@ add_newdoc('numpy.core.multiarray', 'fromstring', Examples -------- - >>> np.fromstring('\\x01\\x02', dtype=np.uint8) - array([1, 2], dtype=uint8) >>> np.fromstring('1 2', dtype=int, sep=' ') array([1, 2]) >>> np.fromstring('1, 2', dtype=int, sep=',') array([1, 2]) - >>> np.fromstring('\\x01\\x02\\x03\\x04\\x05', dtype=np.uint8, count=3) - array([1, 2, 3], dtype=uint8) """) @@ -1154,6 +1152,11 @@ add_newdoc('numpy.core.multiarray', 'frombuffer', array(['w', 'o', 'r', 'l', 'd'], dtype='|S1') + >>> np.frombuffer(b'\\x01\\x02', dtype=np.uint8) + array([1, 2], dtype=uint8) + >>> np.frombuffer(b'\\x01\\x02\\x03\\x04\\x05', dtype=np.uint8, count=3) + array([1, 2, 3], dtype=uint8) + """) add_newdoc('numpy.core.multiarray', 'concatenate', |