summaryrefslogtreecommitdiff
path: root/numpy/core/tests
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2020-02-04 14:35:09 +0000
committerEric Wieser <wieser.eric@gmail.com>2020-02-08 21:23:35 +0000
commitd0b7b6638fe7496d25a488a179d79879748075fa (patch)
tree69333c89bd5181ba680b15caf66ae96e3084b029 /numpy/core/tests
parent48c0b1426ff81c8da3832fd6fb162dfbc1aa4601 (diff)
downloadnumpy-d0b7b6638fe7496d25a488a179d79879748075fa.tar.gz
ENH: Implement the buffer protocol on numpy str_ scalars
This eliminates the need for special casing in `np.generic.__reduce__`
Diffstat (limited to 'numpy/core/tests')
-rw-r--r--numpy/core/tests/test_scalarbuffer.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/numpy/core/tests/test_scalarbuffer.py b/numpy/core/tests/test_scalarbuffer.py
index 15226d10b..b1c1bbbb1 100644
--- a/numpy/core/tests/test_scalarbuffer.py
+++ b/numpy/core/tests/test_scalarbuffer.py
@@ -99,3 +99,21 @@ class TestScalarPEP3118:
# Fails to create a PEP 3118 valid buffer
assert_raises((ValueError, BufferError), memoryview, a[0])
+ @pytest.mark.parametrize('s', [
+ pytest.param("\x32\x32", id="ascii"),
+ pytest.param("\uFE0F\uFE0F", id="basic multilingual"),
+ pytest.param("\U0001f4bb\U0001f4bb", id="non-BMP"),
+ ])
+ def test_str_ucs4(self, s):
+ s = np.str_(s) # only our subclass implements the buffer protocol
+
+ # all the same, characters always encode as ucs4
+ expected = dict(strides=(), itemsize=8, ndim=0, shape=(), format='2w')
+
+ v = memoryview(s)
+ assert self._as_dict(v) == expected
+
+ # integers of the paltform-appropriate endianness
+ code_points = np.frombuffer(v, dtype='i4')
+
+ assert_equal(code_points, [ord(c) for c in s])