Skip to content

Commit

Permalink
remove decoding of the numpy arrays for patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
CPrescher committed Jul 24, 2024
1 parent 78bead5 commit 8bf0986
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions glassure/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,9 @@ def __str__(self):
def validate(value):
if isinstance(value, list):
return np.array(value)
if isinstance(value, str):
if isinstance(value, str) or isinstance(value, bytes):
try:
v = base64.b64decode(value)
numpy_array = np.load(io.BytesIO(v), allow_pickle=False)
numpy_array = np.load(io.BytesIO(value), allow_pickle=False)
return numpy_array
except Exception as e:
raise ValueError(f"Could not decode numpy array: {e}")
Expand All @@ -345,7 +344,7 @@ def serialize(value):
# Save numpy array to bytes
with io.BytesIO() as buffer:
np.save(buffer, value, allow_pickle=False)
return base64.b64encode(buffer.getvalue()).decode("utf-8")
return buffer.getvalue()
raise TypeError(f"Invalid type for numpy array: {type(value)}")


Expand Down

0 comments on commit 8bf0986

Please sign in to comment.