Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/duckdb_py/arrow/arrow_array_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ unique_ptr<ArrowArrayStreamWrapper> PythonTableArrowArrayStreamFactory::Produce(
break;
}
default: {
auto py_object_type = string(py::str(arrow_obj_handle.get_type().attr("__name__")));
auto py_object_type = string(py::str(py::type::of(arrow_obj_handle).attr("__name__")));
throw InvalidInputException("Object of type '%s' is not a recognized Arrow object", py_object_type);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/duckdb_py/native/python_conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ struct PythonValueConversion {
auto type = ele.attr("type");
shared_ptr<DuckDBPyType> internal_type;
if (!py::try_cast<shared_ptr<DuckDBPyType>>(type, internal_type)) {
string actual_type = py::str(type.get_type());
string actual_type = py::str(py::type::of(type));
throw InvalidInputException("The 'type' of a Value should be of type DuckDBPyType, not '%s'",
actual_type);
}
Expand Down Expand Up @@ -1062,7 +1062,7 @@ void TransformPythonObjectInternal(py::handle ele, A &result, const B &param, bo
}
case PythonObjectType::Other:
throw NotImplementedException("Unable to transform python value of type '%s' to DuckDB LogicalType",
py::str(ele.get_type()).cast<string>());
py::str(py::type::of(ele)).cast<string>());
default:
throw InternalException("Object type recognized but not implemented!");
}
Expand Down
70 changes: 35 additions & 35 deletions src/duckdb_py/pyconnection.cpp

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/duckdb_py/pyconnection/type_creation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static child_list_t<LogicalType> GetChildList(const py::object &container) {
for (auto &item : fields) {
shared_ptr<DuckDBPyType> pytype;
if (!py::try_cast<shared_ptr<DuckDBPyType>>(item, pytype)) {
string actual_type = py::str(item.get_type());
string actual_type = py::str(py::type::of(item));
throw InvalidInputException("object has to be a list of DuckDBPyType's, not '%s'", actual_type);
}
types.push_back(std::make_pair(StringUtil::Format("v%d", i++), pytype->Type()));
Expand All @@ -40,14 +40,14 @@ static child_list_t<LogicalType> GetChildList(const py::object &container) {
string name = py::str(name_p);
shared_ptr<DuckDBPyType> pytype;
if (!py::try_cast<shared_ptr<DuckDBPyType>>(type_p, pytype)) {
string actual_type = py::str(type_p.get_type());
string actual_type = py::str(py::type::of(type_p));
throw InvalidInputException("object has to be a list of DuckDBPyType's, not '%s'", actual_type);
}
types.push_back(std::make_pair(name, pytype->Type()));
}
return types;
} else {
string actual_type = py::str(container.get_type());
string actual_type = py::str(py::type::of(container));
throw InvalidInputException(
"Can not construct a child list from object of type '%s', only dict/list is supported", actual_type);
}
Expand Down
2 changes: 1 addition & 1 deletion src/duckdb_py/pyexpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ shared_ptr<DuckDBPyExpression> DuckDBPyExpression::FunctionExpression(const stri
for (auto arg : args) {
shared_ptr<DuckDBPyExpression> py_expr;
if (!py::try_cast<shared_ptr<DuckDBPyExpression>>(arg, py_expr)) {
string actual_type = py::str(arg.get_type());
string actual_type = py::str(py::type::of(arg));
throw InvalidInputException("Expected argument of type Expression, received '%s' instead", actual_type);
}
auto expr = py_expr->GetExpression().Copy();
Expand Down
10 changes: 5 additions & 5 deletions src/duckdb_py/pyrelation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ unique_ptr<DuckDBPyRelation> DuckDBPyRelation::ProjectFromTypes(const py::object
auto *type_p = item.cast<DuckDBPyType *>();
type = type_p->Type();
} else {
string actual_type = py::str(item.get_type());
string actual_type = py::str(py::type::of(item));
throw InvalidInputException("Can only project on objects of type DuckDBPyType or str, not '%s'",
actual_type);
}
Expand Down Expand Up @@ -219,7 +219,7 @@ unique_ptr<DuckDBPyRelation> DuckDBPyRelation::Sort(const py::args &args) {
for (auto arg : args) {
shared_ptr<DuckDBPyExpression> py_expr;
if (!py::try_cast<shared_ptr<DuckDBPyExpression>>(arg, py_expr)) {
string actual_type = py::str(arg.get_type());
string actual_type = py::str(py::type::of(arg));
throw InvalidInputException("Expected argument of type Expression, received '%s' instead", actual_type);
}
auto expr = py_expr->GetExpression().Copy();
Expand Down Expand Up @@ -248,7 +248,7 @@ vector<unique_ptr<ParsedExpression>> GetExpressions(ClientContext &context, cons
auto aggregate_list = std::string(py::str(expr));
return Parser::ParseExpressionList(aggregate_list, context.GetParserOptions());
} else {
string actual_type = py::str(expr.get_type());
string actual_type = py::str(py::type::of(expr));
throw InvalidInputException("Please provide either a string or list of Expression objects, not %s",
actual_type);
}
Expand Down Expand Up @@ -1183,7 +1183,7 @@ unique_ptr<DuckDBPyRelation> DuckDBPyRelation::Join(DuckDBPyRelation *other, con
auto using_list_p = py::list(condition);
for (auto &item : using_list_p) {
if (!py::isinstance<py::str>(item)) {
string actual_type = py::str(item.get_type());
string actual_type = py::str(py::type::of(item));
throw InvalidInputException("Using clause should be a list of strings, not %s", actual_type);
}
using_list.push_back(std::string(py::str(item)));
Expand Down Expand Up @@ -1594,7 +1594,7 @@ void DuckDBPyRelation::Update(const py::object &set_p, const py::object &where)
}
shared_ptr<DuckDBPyExpression> py_expr;
if (!py::try_cast<shared_ptr<DuckDBPyExpression>>(item_value, py_expr)) {
string actual_type = py::str(item_value.get_type());
string actual_type = py::str(py::type::of(item_value));
throw InvalidInputException("Please provide an object of type Expression as the value, not %s",
actual_type);
}
Expand Down
2 changes: 1 addition & 1 deletion src/duckdb_py/python_replacement_scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static void CreateArrowScan(const string &name, py::object entry, TableFunctionR

static void ThrowScanFailureError(const py::object &entry, const string &name, const string &location = "") {
string error;
auto py_object_type = string(py::str(entry.get_type().attr("__name__")));
auto py_object_type = string(py::str(py::type::of(entry).attr("__name__")));
error += StringUtil::Format("Python Object \"%s\" of type \"%s\"", name, py_object_type);
if (!location.empty()) {
error += StringUtil::Format(" found on line \"%s\"", location);
Expand Down
27 changes: 15 additions & 12 deletions src/duckdb_py/python_udf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,20 +332,23 @@ static scalar_function_t CreateNativeFunction(PyObject *function, PythonExceptio
ret = py::reinterpret_steal<py::object>(PyObject_CallObject(function, nullptr));
}

if (ret == nullptr && PyErr_Occurred()) {
if (exception_handling == PythonExceptionHandling::FORWARD_ERROR) {
auto exception = py::error_already_set();
throw InvalidInputException("Python exception occurred while executing the UDF: %s",
exception.what());
} else if (exception_handling == PythonExceptionHandling::RETURN_NULL) {
PyErr_Clear();
FlatVector::SetNull(result, row, true);
continue;
} else {
if (!ret || ret.is_none()) {
if (PyErr_Occurred()) {
if (exception_handling == PythonExceptionHandling::FORWARD_ERROR) {
auto exception = py::error_already_set();
throw InvalidInputException("Python exception occurred while executing the UDF: %s",
exception.what());
}
if (exception_handling == PythonExceptionHandling::RETURN_NULL) {
PyErr_Clear();
FlatVector::SetNull(result, row, true);
continue;
}
throw NotImplementedException("Exception handling type not implemented");
}
} else if ((!ret || ret == Py_None) && default_null_handling) {
throw InvalidInputException(NullHandlingError());
if (default_null_handling) {
throw InvalidInputException(NullHandlingError());
}
}
TransformPythonObject(ret, result, row);
}
Expand Down
6 changes: 3 additions & 3 deletions src/duckdb_py/typing/pytype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ static py::tuple FilterNones(const py::tuple &args) {

for (const auto &arg : args) {
py::object object = py::reinterpret_borrow<py::object>(arg);
if (object.is(py::none().get_type())) {
if (object.is(py::type::of(py::none()))) {
continue;
}
result.append(object);
Expand Down Expand Up @@ -313,13 +313,13 @@ static LogicalType FromObject(const py::object &object) {
case PythonTypeObject::TYPE: {
shared_ptr<DuckDBPyType> type_object;
if (!py::try_cast<shared_ptr<DuckDBPyType>>(object, type_object)) {
string actual_type = py::str(object.get_type());
string actual_type = py::str(py::type::of(object));
throw InvalidInputException("Expected argument of type DuckDBPyType, received '%s' instead", actual_type);
}
return type_object->Type();
}
default: {
string actual_type = py::str(object.get_type());
string actual_type = py::str(py::type::of(object));
throw NotImplementedException("Could not convert from object of type '%s' to DuckDBPyType", actual_type);
}
}
Expand Down
Loading