@@ -434,6 +434,15 @@ static LogicalType pyNumpyArrayLogicalType(const py::array& arr) {
434434 return type;
435435}
436436
437+ static bool hasNumpyTypeModule (const py::handle& val) {
438+ auto module = py::str (val.get_type ().attr (" __module__" )).cast <std::string>();
439+ return module == " numpy" || module .starts_with (" numpy." );
440+ }
441+
442+ static bool isNumpyArray (const py::handle& val) {
443+ return hasNumpyTypeModule (val) && py::isinstance<py::array>(val);
444+ }
445+
437446static LogicalType pyLogicalType (const py::handle& val) {
438447 auto datetime_datetime = importCache->datetime .datetime ();
439448 auto time_delta = importCache->datetime .timedelta ();
@@ -514,7 +523,7 @@ static LogicalType pyLogicalType(const py::handle& val) {
514523 childValueType = std::move (resultValue);
515524 }
516525 return LogicalType::MAP (std::move (childKeyType), std::move (childValueType));
517- } else if (py::isinstance<py::array> (val)) {
526+ } else if (isNumpyArray (val)) {
518527 return pyNumpyArrayLogicalType (py::reinterpret_borrow<py::array>(val));
519528 } else if (py::isinstance<py::list>(val)) {
520529 py::list lst = py::reinterpret_borrow<py::list>(val);
@@ -620,7 +629,7 @@ static LogicalType pyLogicalTypeFromParameter(const py::handle& val) {
620629 structFields.emplace_back (std::move (keyName), std::move (keyType));
621630 }
622631 return LogicalType::STRUCT (std::move (structFields));
623- } else if (py::isinstance<py::array> (val)) {
632+ } else if (isNumpyArray (val)) {
624633 return pyNumpyArrayLogicalType (py::reinterpret_borrow<py::array>(val));
625634 } else if (py::isinstance<py::list>(val)) {
626635 py::list lst = py::reinterpret_borrow<py::list>(val);
@@ -852,7 +861,7 @@ Value PyConnection::transformPythonValueAs(const py::handle& val, const LogicalT
852861 return Value{uuidToAppend};
853862 }
854863 case LogicalTypeID::LIST: {
855- if (py::isinstance<py::array> (val)) {
864+ if (isNumpyArray (val)) {
856865 return transformNumpyArrayAs (py::reinterpret_borrow<py::array>(val), type);
857866 }
858867 py::list lst = py::reinterpret_borrow<py::list>(val);
@@ -910,7 +919,7 @@ Value PyConnection::transformPythonValueFromParameterAs(const py::handle& val,
910919 auto jsonStr = pythonObjectToJsonString (val);
911920 return Value::createValue<std::string>(jsonStr);
912921 }
913- if (py::isinstance<py::array> (val)) {
922+ if (isNumpyArray (val)) {
914923 return transformNumpyArrayAs (py::reinterpret_borrow<py::array>(val), type);
915924 }
916925 py::list lst = py::reinterpret_borrow<py::list>(val);
0 commit comments