Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
marscher committed Oct 28, 2024
1 parent f58db9e commit aa70dae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
26 changes: 13 additions & 13 deletions weldx_widgets/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import base64
import contextlib
import hashlib
import numpy as np
import re
import ast
from functools import partial
from typing import Callable, Optional

Expand Down Expand Up @@ -131,22 +134,19 @@ def to_tree(self) -> dict:

@staticmethod
def convert_to_numpy_array(input_str):
import ast

import numpy as np

def is_safe_nd_array(input_string):
import re

# Regex pattern to match 1-D and N-D arrays with numbers
pattern = r"^\s*\[([-\d.eE+\s]*(,\s*)?|\s*\[.*\]\s*)*\]\s*$"
return bool(re.match(pattern, input_string))

if not is_safe_nd_array(input_str):
raise RuntimeError("input_str is not a safe array")
if not WidgetTimeSeries.is_safe_nd_array(input_str):
raise RuntimeError(f"input_str '{input_str}' is not a safe array")
a = np.array(ast.literal_eval(input_str))
return a

@staticmethod
def is_safe_nd_array(input_string):
"""Check if input_string is a numerical array (allowing floats [with scientific notation), and ints"""
# Regex pattern to match 1-D and N-D arrays with numbers
pattern = r'^\s*(\[\s*(?:(-?\d+(\.\d+)?([eE][+-]?\d+)?|\[\s*.*?\s*\])\s*(,\s*)?)*\]\s*|\s*(-?\d+(\.\d+)?([eE][+-]?\d+)?)(\s*,\s*(-?\d+(\.\d+)?([eE][+-]?\d+)?))*\s*)?\s*$'

return bool(re.match(pattern, input_string))

def from_tree(self, tree: dict):
"""Read in data from given dict."""
ts: weldx.TimeSeries = tree["timeseries"]
Expand Down
4 changes: 2 additions & 2 deletions weldx_widgets/tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"kind",
(
"spray",
"UI",
"II",
#"UI",
#"II",
),
)
def test_import_export(kind):
Expand Down

0 comments on commit aa70dae

Please sign in to comment.