File tree Expand file tree Collapse file tree 3 files changed +17
-0
lines changed Expand file tree Collapse file tree 3 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,9 @@ Release notes
4
4
5
5
* Drop support for 32-bit Windows. By :user: `Alistair Miles <alimanfoo> `, :issue: `97 `, :issue: `156 `.
6
6
7
+ * Raise a ``TypeError `` if an ``object `` array is passed to ``ensure_bytes ``.
8
+ By :user: `John Kirkham <jakirkham> `, :issue: `162 `.
9
+
7
10
8
11
.. _release_0.6.2 :
9
12
Original file line number Diff line number Diff line change @@ -152,6 +152,11 @@ def ensure_bytes(buf):
152
152
# go via numpy, for convenience
153
153
arr = ensure_ndarray (buf )
154
154
155
+ # check for object arrays, these are just memory pointers,
156
+ # actual memory holding item data is scattered elsewhere
157
+ if arr .dtype == object :
158
+ raise TypeError ('object arrays are not supported' )
159
+
155
160
# create bytes
156
161
buf = arr .tobytes (order = 'A' )
157
162
Original file line number Diff line number Diff line change @@ -51,6 +51,15 @@ def test_ensure_contiguous_ndarray_shares_memory():
51
51
assert np .shares_memory (a , memoryview (buf ))
52
52
53
53
54
+ def test_ensure_bytes_invalid_inputs ():
55
+
56
+ # object array not allowed
57
+ a = np .array ([u'Xin chào thế giới' ], dtype = object )
58
+ for e in [a , memoryview (a )]:
59
+ with pytest .raises (TypeError ):
60
+ ensure_bytes (e )
61
+
62
+
54
63
def test_ensure_contiguous_ndarray_invalid_inputs ():
55
64
56
65
# object array not allowed
You can’t perform that action at this time.
0 commit comments