Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add to pandas example #5

Merged
merged 1 commit into from
Apr 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions examples/to_pandas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!python3
import os
import pyarrow as pa
import chdb

# get current file dir
current_dir = os.path.dirname(os.path.abspath(__file__))
test_parquet = current_dir + "/../contrib/arrow/cpp/submodules/parquet-testing/data/alltypes_dictionary.parquet"

# run SQL on parquet file and return arrow format
res = chdb.query(f"select * from file('{test_parquet}', Parquet)", "Arrow")
print("\nresult from chdb:")
print(res.get_memview().tobytes())

def to_arrowTable(res):
# convert arrow format to arrow table
paTable = pa.RecordBatchFileReader(res.get_memview()).read_all()
return paTable

def to_df(res):
# convert arrow format to arrow table
paTable = to_arrowTable(res)
# convert arrow table to pandas dataframe
return paTable.to_pandas(use_threads=True)

print("\nresult from chdb to pyarrow:")
print(to_arrowTable(res))

# convert arrow table to pandas dataframe
print("\nresult from chdb to pandas:")
print(to_df(res))
8 changes: 0 additions & 8 deletions pybind/libtest.py

This file was deleted.

5 changes: 0 additions & 5 deletions pybind/readarrow.py

This file was deleted.