Skip to content
Snippets Groups Projects
Commit 7b3e4ca8 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

BF: makeWriteable will make a copy of an array if its base is a bytes object.

Works around older numpy versions
parent d6ba364b
No related branches found
No related tags found
No related merge requests found
......@@ -84,7 +84,19 @@ def makeWriteable(array):
is not possible, a copy is created and returned.
"""
try:
# Versions of numpy prior to 1.16 will
# happily mutate a bytes array, whcih
# is supposed to be immutable. So if
# is the case, let's force a copy.
if isinstance(array.base, bytes):
raise ValueError()
# In versions of numpy 1.16 and newer,
# setting the WRITEABLE flag on an
# immutable array will cause a
# ValueError to be raised
array.flags['WRITEABLE'] = True
except ValueError:
array = np.array(array)
return array
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment