Skip to content

Commit 208082a

Browse files
committed
fix for msvc
1 parent fc677e2 commit 208082a

5 files changed

Lines changed: 14 additions & 8 deletions

File tree

src/duckdb_py/arrow/arrow_array_stream.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ unique_ptr<ArrowArrayStreamWrapper> PythonTableArrowArrayStreamFactory::Produce(
188188
break;
189189
}
190190
default: {
191-
auto py_object_type = py::cast<std::string>(py::str((arrow_obj_handle).type().attr("__name__")));
191+
// py::object wrap: py::str() of a bare .attr() accessor is an ambiguous overload on MSVC.
192+
auto py_object_type = py::cast<std::string>(py::str(py::object((arrow_obj_handle).type().attr("__name__"))));
192193
throw InvalidInputException("Object of type '%s' is not a recognized Arrow object", py_object_type);
193194
}
194195
}

src/duckdb_py/native/python_objects.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,16 @@ interval_t PyTimeDelta::ToInterval() {
4545
}
4646

4747
int64_t PyTimeDelta::GetDays(py::handle &obj) {
48-
return py::cast<int64_t>(py::int_(obj.attr("days")));
48+
// py::object wrap: py::int_() of a bare .attr() accessor is an ambiguous overload on MSVC.
49+
return py::cast<int64_t>(py::int_(py::object(obj.attr("days"))));
4950
}
5051

5152
int64_t PyTimeDelta::GetSeconds(py::handle &obj) {
52-
return py::cast<int64_t>(py::int_(obj.attr("seconds")));
53+
return py::cast<int64_t>(py::int_(py::object(obj.attr("seconds"))));
5354
}
5455

5556
int64_t PyTimeDelta::GetMicros(py::handle &obj) {
56-
return py::cast<int64_t>(py::int_(obj.attr("microseconds")));
57+
return py::cast<int64_t>(py::int_(py::object(obj.attr("microseconds"))));
5758
}
5859

5960
PyDecimal::PyDecimal(py::handle &obj) : obj(obj) {

src/duckdb_py/pyconnection.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ void DuckDBPyConnection::RegisterFilesystem(py::object filesystem) {
339339

340340
auto &fs = database.GetFileSystem();
341341

342-
auto protocol = filesystem.attr("protocol");
342+
// py::object (not auto, which deduces an accessor): py::str(protocol) below is an ambiguous overload on MSVC.
343+
py::object protocol = filesystem.attr("protocol");
343344
if (protocol.is_none() || py::str("abstract").equal(protocol)) {
344345
throw InvalidInputException("Must provide concrete fsspec implementation");
345346
}
@@ -1843,7 +1844,8 @@ std::unique_ptr<DuckDBPyRelation> DuckDBPyConnection::FromArrow(py::object &arro
18431844
auto &connection = con.GetConnection();
18441845
string name = "arrow_object_" + StringUtil::GenerateRandomName();
18451846
if (!IsAcceptedArrowObject(arrow_object)) {
1846-
auto py_object_type = py::cast<std::string>(py::str((arrow_object).type().attr("__name__")));
1847+
// py::object wrap: py::str() of a bare .attr() accessor is an ambiguous overload on MSVC.
1848+
auto py_object_type = py::cast<std::string>(py::str(py::object((arrow_object).type().attr("__name__"))));
18471849
throw InvalidInputException("Python Object Type %s is not an accepted Arrow Object.", py_object_type);
18481850
}
18491851
auto tableref = PythonReplacementScan::ReplacementObject(arrow_object, name, *connection.context, true);

src/duckdb_py/python_replacement_scan.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ static void CreateArrowScan(const string &name, py::object entry, TableFunctionR
8686

8787
static void ThrowScanFailureError(const py::object &entry, const string &name, const string &location = "") {
8888
string error;
89-
auto py_object_type = py::cast<std::string>(py::str((entry).type().attr("__name__")));
89+
// py::object wrap: py::str() of a bare .attr() accessor is an ambiguous overload on MSVC.
90+
auto py_object_type = py::cast<std::string>(py::str(py::object((entry).type().attr("__name__"))));
9091
error += StringUtil::Format("Python Object \"%s\" of type \"%s\"", name, py_object_type);
9192
if (!location.empty()) {
9293
error += StringUtil::Format(" found on line \"%s\"", location);

src/duckdb_py/typing/pytype.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ static LogicalType FromGenericAlias(const py::object &obj) {
261261
py::module_ types = py::module_::import_("types");
262262
auto generic_alias = types.attr("GenericAlias");
263263
D_ASSERT(py::isinstance(obj, generic_alias));
264-
auto origin = obj.attr("__origin__");
264+
// py::object (not auto, which deduces an accessor): py::str(accessor) is an ambiguous overload on MSVC.
265+
py::object origin = obj.attr("__origin__");
265266
py::tuple args = obj.attr("__args__");
266267

267268
if (origin.is(builtins.attr("list"))) {

0 commit comments

Comments
 (0)