Skip to content

Commit e3cc17f

Browse files
committed
get rid of deprecation warnings
1 parent f1711b5 commit e3cc17f

10 files changed

Lines changed: 68 additions & 64 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/include/duckdb_python/expression/pyexpression.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "duckdb.hpp"
1313
#include "duckdb/common/string.hpp"
1414
#include "duckdb/parser/parsed_expression.hpp"
15+
#include <duckdb/parser/expression/case_expression.hpp>
1516
#include "duckdb/parser/expression/constant_expression.hpp"
1617
#include "duckdb/parser/expression/columnref_expression.hpp"
1718
#include "duckdb/parser/expression/function_expression.hpp"

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
@@ -133,7 +133,7 @@ unique_ptr<DuckDBPyRelation> DuckDBPyRelation::ProjectFromTypes(const py::object
133133
auto *type_p = item.cast<DuckDBPyType *>();
134134
type = type_p->Type();
135135
} else {
136-
string actual_type = py::str(item.get_type());
136+
string actual_type = py::str(py::type::of(item));
137137
throw InvalidInputException("Can only project on objects of type DuckDBPyType or str, not '%s'",
138138
actual_type);
139139
}
@@ -218,7 +218,7 @@ unique_ptr<DuckDBPyRelation> DuckDBPyRelation::Sort(const py::args &args) {
218218
for (auto arg : args) {
219219
shared_ptr<DuckDBPyExpression> py_expr;
220220
if (!py::try_cast<shared_ptr<DuckDBPyExpression>>(arg, py_expr)) {
221-
string actual_type = py::str(arg.get_type());
221+
string actual_type = py::str(py::type::of(arg));
222222
throw InvalidInputException("Expected argument of type Expression, received '%s' instead", actual_type);
223223
}
224224
auto expr = py_expr->GetExpression().Copy();
@@ -247,7 +247,7 @@ vector<unique_ptr<ParsedExpression>> GetExpressions(ClientContext &context, cons
247247
auto aggregate_list = std::string(py::str(expr));
248248
return Parser::ParseExpressionList(aggregate_list, context.GetParserOptions());
249249
} else {
250-
string actual_type = py::str(expr.get_type());
250+
string actual_type = py::str(py::type::of(expr));
251251
throw InvalidInputException("Please provide either a string or list of Expression objects, not %s",
252252
actual_type);
253253
}
@@ -1182,7 +1182,7 @@ unique_ptr<DuckDBPyRelation> DuckDBPyRelation::Join(DuckDBPyRelation *other, con
11821182
auto using_list_p = py::list(condition);
11831183
for (auto &item : using_list_p) {
11841184
if (!py::isinstance<py::str>(item)) {
1185-
string actual_type = py::str(item.get_type());
1185+
string actual_type = py::str(py::type::of(item));
11861186
throw InvalidInputException("Using clause should be a list of strings, not %s", actual_type);
11871187
}
11881188
using_list.push_back(std::string(py::str(item)));
@@ -1593,7 +1593,7 @@ void DuckDBPyRelation::Update(const py::object &set_p, const py::object &where)
15931593
}
15941594
shared_ptr<DuckDBPyExpression> py_expr;
15951595
if (!py::try_cast<shared_ptr<DuckDBPyExpression>>(item_value, py_expr)) {
1596-
string actual_type = py::str(item_value.get_type());
1596+
string actual_type = py::str(py::type::of(item_value));
15971597
throw InvalidInputException("Please provide an object of type Expression as the value, not %s",
15981598
actual_type);
15991599
}

src/duckdb_py/python_replacement_scan.cpp

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

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

src/duckdb_py/python_udf.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -326,21 +326,24 @@ static scalar_function_t CreateNativeFunction(PyObject *function, PythonExceptio
326326
}
327327

328328
// Call the function
329-
auto ret = PyObject_CallObject(function, bundled_parameters.ptr());
330-
if (ret == nullptr && PyErr_Occurred()) {
331-
if (exception_handling == PythonExceptionHandling::FORWARD_ERROR) {
332-
auto exception = py::error_already_set();
333-
throw InvalidInputException("Python exception occurred while executing the UDF: %s",
334-
exception.what());
335-
} else if (exception_handling == PythonExceptionHandling::RETURN_NULL) {
336-
PyErr_Clear();
337-
FlatVector::SetNull(result, row, true);
338-
continue;
339-
} else {
329+
auto ret = py::reinterpret_steal<py::object>(PyObject_CallObject(function, bundled_parameters.ptr()));
330+
if (!ret || ret.is_none()) {
331+
if (PyErr_Occurred()) {
332+
if (exception_handling == PythonExceptionHandling::FORWARD_ERROR) {
333+
auto exception = py::error_already_set();
334+
throw InvalidInputException("Python exception occurred while executing the UDF: %s",
335+
exception.what());
336+
}
337+
if (exception_handling == PythonExceptionHandling::RETURN_NULL) {
338+
PyErr_Clear();
339+
FlatVector::SetNull(result, row, true);
340+
continue;
341+
}
340342
throw NotImplementedException("Exception handling type not implemented");
341343
}
342-
} else if ((!ret || ret == Py_None) && default_null_handling) {
343-
throw InvalidInputException(NullHandlingError());
344+
if (default_null_handling) {
345+
throw InvalidInputException(NullHandlingError());
346+
}
344347
}
345348
TransformPythonObject(ret, result, row);
346349
}

src/duckdb_py/typing/pytype.cpp

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

212212
for (const auto &arg : args) {
213213
py::object object = py::reinterpret_borrow<py::object>(arg);
214-
if (object.is(py::none().get_type())) {
214+
if (object.is_none()) {
215215
continue;
216216
}
217217
result.append(object);
@@ -309,13 +309,13 @@ static LogicalType FromObject(const py::object &object) {
309309
case PythonTypeObject::TYPE: {
310310
shared_ptr<DuckDBPyType> type_object;
311311
if (!py::try_cast<shared_ptr<DuckDBPyType>>(object, type_object)) {
312-
string actual_type = py::str(object.get_type());
312+
string actual_type = py::str(py::type::of(object));
313313
throw InvalidInputException("Expected argument of type DuckDBPyType, received '%s' instead", actual_type);
314314
}
315315
return type_object->Type();
316316
}
317317
default: {
318-
string actual_type = py::str(object.get_type());
318+
string actual_type = py::str(py::type::of(object));
319319
throw NotImplementedException("Could not convert from object of type '%s' to DuckDBPyType", actual_type);
320320
}
321321
}

0 commit comments

Comments
 (0)