Skip to content

Commit

Permalink
Fix type handling of Pandas 2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
auxten committed Jun 24, 2024
1 parent 62626e9 commit 3f39349
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/Common/PythonUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <string>
#include <Common/PythonUtils.h>
#include "config.h"

Expand Down Expand Up @@ -312,15 +313,26 @@ const void * tryGetPyArray(const py::object & obj, py::handle & result, py::hand
row_count = py::len(obj);
// if element type is bytes or object, we need to convert it to string
// chdb todo: need more type check
if (array.dtype().kind() == 'O')
if (row_count > 0)
{
auto str_obj = obj.attr("astype")(py::dtype("str"));
array = str_obj.attr("values");
result = array;
tmp = array;
tmp.inc_ref();
return array.data();
auto elem_type = obj.attr("__getitem__")(0).attr("__class__").attr("__name__").cast<std::string>();
if (elem_type == "str" || elem_type == "unicode")
{
result = array;
return array.data();
}
if (elem_type == "bytes" || elem_type == "object")
{
// chdb todo: better handle for bytes and object type
auto str_obj = obj.attr("astype")(py::dtype("str"));
array = str_obj.attr("values");
result = array;
tmp = array;
tmp.inc_ref();
return array.data();
}
}

result = array;
return array.data();
}
Expand Down

0 comments on commit 3f39349

Please sign in to comment.