Skip to content

Commit 93bc7ae

Browse files
Fix deprecations (#285)
Fixes pybind11 deprecation warnings
2 parents 3c5b7bc + e080f2d commit 93bc7ae

9 files changed

Lines changed: 66 additions & 63 deletions

File tree

src/duckdb_py/arrow/arrow_array_stream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ unique_ptr<ArrowArrayStreamWrapper> PythonTableArrowArrayStreamFactory::Produce(
109109
break;
110110
}
111111
default: {
112-
auto py_object_type = string(py::str(arrow_obj_handle.get_type().attr("__name__")));
112+
auto py_object_type = string(py::str(py::type::of(arrow_obj_handle).attr("__name__")));
113113
throw InvalidInputException("Object of type '%s' is not a recognized Arrow object", py_object_type);
114114
}
115115
}

src/duckdb_py/native/python_conversion.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ struct PythonValueConversion {
606606
auto type = ele.attr("type");
607607
shared_ptr<DuckDBPyType> internal_type;
608608
if (!py::try_cast<shared_ptr<DuckDBPyType>>(type, internal_type)) {
609-
string actual_type = py::str(type.get_type());
609+
string actual_type = py::str(py::type::of(type));
610610
throw InvalidInputException("The 'type' of a Value should be of type DuckDBPyType, not '%s'",
611611
actual_type);
612612
}
@@ -1062,7 +1062,7 @@ void TransformPythonObjectInternal(py::handle ele, A &result, const B &param, bo
10621062
}
10631063
case PythonObjectType::Other:
10641064
throw NotImplementedException("Unable to transform python value of type '%s' to DuckDB LogicalType",
1065-
py::str(ele.get_type()).cast<string>());
1065+
py::str(py::type::of(ele)).cast<string>());
10661066
default:
10671067
throw InternalException("Object type recognized but not implemented!");
10681068
}

src/duckdb_py/pyconnection.cpp

Lines changed: 35 additions & 35 deletions
Large diffs are not rendered by default.

src/duckdb_py/pyconnection/type_creation.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static child_list_t<LogicalType> GetChildList(const py::object &container) {
2626
for (auto &item : fields) {
2727
shared_ptr<DuckDBPyType> pytype;
2828
if (!py::try_cast<shared_ptr<DuckDBPyType>>(item, pytype)) {
29-
string actual_type = py::str(item.get_type());
29+
string actual_type = py::str(py::type::of(item));
3030
throw InvalidInputException("object has to be a list of DuckDBPyType's, not '%s'", actual_type);
3131
}
3232
types.push_back(std::make_pair(StringUtil::Format("v%d", i++), pytype->Type()));
@@ -40,14 +40,14 @@ static child_list_t<LogicalType> GetChildList(const py::object &container) {
4040
string name = py::str(name_p);
4141
shared_ptr<DuckDBPyType> pytype;
4242
if (!py::try_cast<shared_ptr<DuckDBPyType>>(type_p, pytype)) {
43-
string actual_type = py::str(type_p.get_type());
43+
string actual_type = py::str(py::type::of(type_p));
4444
throw InvalidInputException("object has to be a list of DuckDBPyType's, not '%s'", actual_type);
4545
}
4646
types.push_back(std::make_pair(name, pytype->Type()));
4747
}
4848
return types;
4949
} else {
50-
string actual_type = py::str(container.get_type());
50+
string actual_type = py::str(py::type::of(container));
5151
throw InvalidInputException(
5252
"Can not construct a child list from object of type '%s', only dict/list is supported", actual_type);
5353
}

src/duckdb_py/pyexpression.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ shared_ptr<DuckDBPyExpression> DuckDBPyExpression::FunctionExpression(const stri
500500
for (auto arg : args) {
501501
shared_ptr<DuckDBPyExpression> py_expr;
502502
if (!py::try_cast<shared_ptr<DuckDBPyExpression>>(arg, py_expr)) {
503-
string actual_type = py::str(arg.get_type());
503+
string actual_type = py::str(py::type::of(arg));
504504
throw InvalidInputException("Expected argument of type Expression, received '%s' instead", actual_type);
505505
}
506506
auto expr = py_expr->GetExpression().Copy();

src/duckdb_py/pyrelation.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ unique_ptr<DuckDBPyRelation> DuckDBPyRelation::ProjectFromTypes(const py::object
134134
auto *type_p = item.cast<DuckDBPyType *>();
135135
type = type_p->Type();
136136
} else {
137-
string actual_type = py::str(item.get_type());
137+
string actual_type = py::str(py::type::of(item));
138138
throw InvalidInputException("Can only project on objects of type DuckDBPyType or str, not '%s'",
139139
actual_type);
140140
}
@@ -219,7 +219,7 @@ unique_ptr<DuckDBPyRelation> DuckDBPyRelation::Sort(const py::args &args) {
219219
for (auto arg : args) {
220220
shared_ptr<DuckDBPyExpression> py_expr;
221221
if (!py::try_cast<shared_ptr<DuckDBPyExpression>>(arg, py_expr)) {
222-
string actual_type = py::str(arg.get_type());
222+
string actual_type = py::str(py::type::of(arg));
223223
throw InvalidInputException("Expected argument of type Expression, received '%s' instead", actual_type);
224224
}
225225
auto expr = py_expr->GetExpression().Copy();
@@ -248,7 +248,7 @@ vector<unique_ptr<ParsedExpression>> GetExpressions(ClientContext &context, cons
248248
auto aggregate_list = std::string(py::str(expr));
249249
return Parser::ParseExpressionList(aggregate_list, context.GetParserOptions());
250250
} else {
251-
string actual_type = py::str(expr.get_type());
251+
string actual_type = py::str(py::type::of(expr));
252252
throw InvalidInputException("Please provide either a string or list of Expression objects, not %s",
253253
actual_type);
254254
}
@@ -1183,7 +1183,7 @@ unique_ptr<DuckDBPyRelation> DuckDBPyRelation::Join(DuckDBPyRelation *other, con
11831183
auto using_list_p = py::list(condition);
11841184
for (auto &item : using_list_p) {
11851185
if (!py::isinstance<py::str>(item)) {
1186-
string actual_type = py::str(item.get_type());
1186+
string actual_type = py::str(py::type::of(item));
11871187
throw InvalidInputException("Using clause should be a list of strings, not %s", actual_type);
11881188
}
11891189
using_list.push_back(std::string(py::str(item)));
@@ -1594,7 +1594,7 @@ void DuckDBPyRelation::Update(const py::object &set_p, const py::object &where)
15941594
}
15951595
shared_ptr<DuckDBPyExpression> py_expr;
15961596
if (!py::try_cast<shared_ptr<DuckDBPyExpression>>(item_value, py_expr)) {
1597-
string actual_type = py::str(item_value.get_type());
1597+
string actual_type = py::str(py::type::of(item_value));
15981598
throw InvalidInputException("Please provide an object of type Expression as the value, not %s",
15991599
actual_type);
16001600
}

src/duckdb_py/python_replacement_scan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static void CreateArrowScan(const string &name, py::object entry, TableFunctionR
8080

8181
static void ThrowScanFailureError(const py::object &entry, const string &name, const string &location = "") {
8282
string error;
83-
auto py_object_type = string(py::str(entry.get_type().attr("__name__")));
83+
auto py_object_type = string(py::str(py::type::of(entry).attr("__name__")));
8484
error += StringUtil::Format("Python Object \"%s\" of type \"%s\"", name, py_object_type);
8585
if (!location.empty()) {
8686
error += StringUtil::Format(" found on line \"%s\"", location);

src/duckdb_py/python_udf.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -332,20 +332,23 @@ static scalar_function_t CreateNativeFunction(PyObject *function, PythonExceptio
332332
ret = py::reinterpret_steal<py::object>(PyObject_CallObject(function, nullptr));
333333
}
334334

335-
if (ret == nullptr && PyErr_Occurred()) {
336-
if (exception_handling == PythonExceptionHandling::FORWARD_ERROR) {
337-
auto exception = py::error_already_set();
338-
throw InvalidInputException("Python exception occurred while executing the UDF: %s",
339-
exception.what());
340-
} else if (exception_handling == PythonExceptionHandling::RETURN_NULL) {
341-
PyErr_Clear();
342-
FlatVector::SetNull(result, row, true);
343-
continue;
344-
} else {
335+
if (!ret || ret.is_none()) {
336+
if (PyErr_Occurred()) {
337+
if (exception_handling == PythonExceptionHandling::FORWARD_ERROR) {
338+
auto exception = py::error_already_set();
339+
throw InvalidInputException("Python exception occurred while executing the UDF: %s",
340+
exception.what());
341+
}
342+
if (exception_handling == PythonExceptionHandling::RETURN_NULL) {
343+
PyErr_Clear();
344+
FlatVector::SetNull(result, row, true);
345+
continue;
346+
}
345347
throw NotImplementedException("Exception handling type not implemented");
346348
}
347-
} else if ((!ret || ret == Py_None) && default_null_handling) {
348-
throw InvalidInputException(NullHandlingError());
349+
if (default_null_handling) {
350+
throw InvalidInputException(NullHandlingError());
351+
}
349352
}
350353
TransformPythonObject(ret, result, row);
351354
}

src/duckdb_py/typing/pytype.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ static py::tuple FilterNones(const py::tuple &args) {
215215

216216
for (const auto &arg : args) {
217217
py::object object = py::reinterpret_borrow<py::object>(arg);
218-
if (object.is(py::none().get_type())) {
218+
if (object.is(py::type::of(py::none()))) {
219219
continue;
220220
}
221221
result.append(object);
@@ -313,13 +313,13 @@ static LogicalType FromObject(const py::object &object) {
313313
case PythonTypeObject::TYPE: {
314314
shared_ptr<DuckDBPyType> type_object;
315315
if (!py::try_cast<shared_ptr<DuckDBPyType>>(object, type_object)) {
316-
string actual_type = py::str(object.get_type());
316+
string actual_type = py::str(py::type::of(object));
317317
throw InvalidInputException("Expected argument of type DuckDBPyType, received '%s' instead", actual_type);
318318
}
319319
return type_object->Type();
320320
}
321321
default: {
322-
string actual_type = py::str(object.get_type());
322+
string actual_type = py::str(py::type::of(object));
323323
throw NotImplementedException("Could not convert from object of type '%s' to DuckDBPyType", actual_type);
324324
}
325325
}

0 commit comments

Comments
 (0)