From ca291aa7c61155fa90fd45a5a770e892f29cc061 Mon Sep 17 00:00:00 2001 From: wudidapaopao Date: Mon, 15 Sep 2025 02:34:36 +0800 Subject: [PATCH 1/2] fix: fix query pandas data frame with index --- programs/local/PythonUtils.cpp | 2 +- tests/test_query_py.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/programs/local/PythonUtils.cpp b/programs/local/PythonUtils.cpp index b9565836e38..bee513c897a 100644 --- a/programs/local/PythonUtils.cpp +++ b/programs/local/PythonUtils.cpp @@ -146,7 +146,7 @@ const void * tryGetPyArray(const py::object & obj, py::handle & result, py::hand // chdb todo: need more type check if (row_count > 0) { - auto elem_type = obj.attr("__getitem__")(0).attr("__class__").attr("__name__").cast(); + auto elem_type = obj.attr("iloc").attr("__getitem__")(0).attr("__class__").attr("__name__").cast(); if (elem_type == "str" || elem_type == "unicode") { result = array; diff --git a/tests/test_query_py.py b/tests/test_query_py.py index f8cc0d45e56..ea6a2074665 100644 --- a/tests/test_query_py.py +++ b/tests/test_query_py.py @@ -110,6 +110,40 @@ def test_query_df(self): ret = chdb.query("SELECT b, sum(a) FROM Python(df) GROUP BY b ORDER BY b") self.assertEqual(str(ret), EXPECTED) + def test_query_df_with_index(self): + df = pd.DataFrame( + { + "a": [1, 2, 3, 4, 5, 6], + "b": ["tom", "jerry", "auxten", "tom", "jerry", "auxten"], + }, + index=[3, 1, 2, 4, 5, 6], + ) + + ret = chdb.query("SELECT * FROM Python(df)") + self.assertIn("tom", str(ret)) + + df = pd.DataFrame( + { + "a": [1, 2, 3, 4, 5, 6], + "b": ["tom", "jerry", "auxten", "tom", "jerry", "auxten"], + }, + index=[0, 1, 2, 4, 5, 6], + ) + + ret = chdb.query("SELECT * FROM Python(df)") + self.assertIn("tom", str(ret)) + + df = pd.DataFrame( + { + "a": [1, 2, 3, 4, 5, 6], + "b": ["tom", "jerry", "auxten", "tom", "jerry", "auxten"], + }, + index=['a', 1, 2, 4, 5, 6], + ) + + ret = chdb.query("SELECT * FROM Python(df)") + self.assertIn("tom", str(ret)) + def test_query_arrow(self): table = pa.table( { From f14077d7e9ca7282e82e391a90ef0a21e80f7a8a Mon Sep 17 00:00:00 2001 From: wudidapaopao Date: Mon, 15 Sep 2025 14:27:00 +0800 Subject: [PATCH 2/2] fix: fix tests --- .github/workflows/build_macos_arm64_wheels.yml | 3 ++- .github/workflows/build_macos_x86_wheels.yml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_macos_arm64_wheels.yml b/.github/workflows/build_macos_arm64_wheels.yml index e21ea74858a..96ef0b988a6 100644 --- a/.github/workflows/build_macos_arm64_wheels.yml +++ b/.github/workflows/build_macos_arm64_wheels.yml @@ -78,7 +78,8 @@ jobs: brew update brew install ca-certificates lz4 mpdecimal openssl@3 readline sqlite xz z3 zstd brew install --ignore-dependencies llvm@19 - brew install git ccache ninja libtool gettext gcc binutils grep findutils nasm + brew install git ninja libtool gettext gcc binutils grep findutils nasm + brew install --build-from-source ccache brew install go cd /usr/local/opt/ && sudo rm -f llvm && sudo ln -sf llvm@19 llvm export PATH=$(brew --prefix llvm@19)/bin:$PATH diff --git a/.github/workflows/build_macos_x86_wheels.yml b/.github/workflows/build_macos_x86_wheels.yml index e6dbf565a4a..85ebe048c87 100644 --- a/.github/workflows/build_macos_x86_wheels.yml +++ b/.github/workflows/build_macos_x86_wheels.yml @@ -78,7 +78,8 @@ jobs: brew update brew install ca-certificates lz4 mpdecimal openssl@3 readline sqlite xz z3 zstd brew install --ignore-dependencies llvm@19 - brew install git ccache ninja libtool gettext gcc binutils grep findutils nasm + brew install git ninja libtool gettext gcc binutils grep findutils nasm + brew install --build-from-source ccache brew install go cd /usr/local/opt/ && sudo rm -f llvm && sudo ln -sf llvm@19 llvm export PATH=$(brew --prefix llvm@19)/bin:$PATH