Skip to content

Commit 1a7b699

Browse files
committed
Fix up query default args value
1 parent 16f88ac commit 1a7b699

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

chdb/__init__.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import sys
22
import os
33

4+
5+
# If any UDF is defined, the path of the UDF will be set to this variable
6+
# and the path will be deleted when the process exits
7+
# UDF config path will be f"{g_udf_path}/udf_config.xml"
8+
# UDF script path will be f"{g_udf_path}/{func_name}.py"
9+
g_udf_path = ""
10+
411
chdb_version = (0, 6, 0)
512
if sys.version_info[:2] >= (3, 7):
613
# get the path of the current file
@@ -32,27 +39,30 @@ def to_arrowTable(res):
3239
import pyarrow as pa
3340
import pandas
3441
except ImportError as e:
35-
print(f'ImportError: {e}')
42+
print(f"ImportError: {e}")
3643
print('Please install pyarrow and pandas via "pip install pyarrow pandas"')
37-
raise ImportError('Failed to import pyarrow or pandas') from None
44+
raise ImportError("Failed to import pyarrow or pandas") from None
3845
if len(res) == 0:
3946
return pa.Table.from_batches([], schema=pa.schema([]))
4047
return pa.RecordBatchFileReader(res.bytes()).read_all()
4148

4249

4350
# return pandas dataframe
4451
def to_df(r):
45-
""""convert arrow table to Dataframe"""
52+
"""convert arrow table to Dataframe"""
4653
t = to_arrowTable(r)
4754
return t.to_pandas(use_threads=True)
4855

4956

5057
# wrap _chdb functions
51-
def query(sql, output_format="CSV", path=None, udf_path=None):
58+
def query(sql, output_format="CSV", path="", udf_path=""):
59+
global g_udf_path
60+
if udf_path != "":
61+
g_udf_path = udf_path
5262
lower_output_format = output_format.lower()
5363
if lower_output_format == "dataframe":
54-
return to_df(_chdb.query(sql, "Arrow", path=path, udf_path=udf_path))
55-
elif lower_output_format == 'arrowtable':
56-
return to_arrowTable(_chdb.query(sql, "Arrow", path=path, udf_path=udf_path))
64+
return to_df(_chdb.query(sql, "Arrow", path=path, udf_path=g_udf_path))
65+
elif lower_output_format == "arrowtable":
66+
return to_arrowTable(_chdb.query(sql, "Arrow", path=path, udf_path=g_udf_path))
5767
else:
58-
return _chdb.query(sql, output_format, path=path, udf_path=udf_path)
68+
return _chdb.query(sql, output_format, path=path, udf_path=g_udf_path)

0 commit comments

Comments
 (0)