diff --git a/cymysql/converters.py b/cymysql/converters.py index 5036bee7..2c74e687 100644 --- a/cymysql/converters.py +++ b/cymysql/converters.py @@ -92,6 +92,11 @@ def escape_decimal(obj): return str(obj) +def escape_vector(obj): + import numpy as np + return escape_bytes(obj.astype(np.float32).tobytes()) + + def convert_datetime(obj): """Returns a DATETIME or TIMESTAMP column value as a datetime object: @@ -355,6 +360,12 @@ def convert_decimal(obj): encoders[unicode] = escape_string encoders[long] = escape_long +try: + import numpy as np + encoders[np.ndarray] = escape_vector +except ImportError: + pass + def escape_item(val, charset, encoders=encoders): if type(val) in [tuple, list, set]: