-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Query on multiple Pandas DataFrame (#89)
* Add dataframe.query() to run sql on multi dataframe * Add join dataframe test * Support passing dataframe as table
- Loading branch information
Showing
7 changed files
with
222 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!python3 | ||
|
||
import unittest | ||
import pandas as pd | ||
from chdb import dataframe as cdf | ||
|
||
|
||
class TestJoinDf(unittest.TestCase): | ||
def test_1df(self): | ||
df1 = pd.DataFrame({"a": [1, 2, 3], "b": [b"one", b"two", b"three"]}) | ||
cdf1 = cdf.Table(dataframe=df1) | ||
ret1 = cdf.query(sql="select * from __tbl1__", tbl1=cdf1) | ||
self.assertEqual(str(ret1), str(df1)) | ||
|
||
def test_2df(self): | ||
df1 = pd.DataFrame({"a": [1, 2, 3], "b": ["one", "two", "three"]}) | ||
df2 = pd.DataFrame({"c": [1, 2, 3], "d": ["①", "②", "③"]}) | ||
ret_tbl = cdf.query( | ||
sql="select * from __tbl1__ t1 join __tbl2__ t2 on t1.a = t2.c", | ||
tbl1=df1, | ||
tbl2=df2, | ||
) | ||
self.assertEqual( | ||
str(ret_tbl), | ||
str( | ||
pd.DataFrame( | ||
{ | ||
"a": [1, 2, 3], | ||
"b": [b"one", b"two", b"three"], | ||
"c": [1, 2, 3], | ||
"d": [b"\xe2\x91\xa0", b"\xe2\x91\xa1", b"\xe2\x91\xa2"], | ||
} | ||
) | ||
), | ||
) | ||
|
||
ret_tbl2 = ret_tbl.query( | ||
"select b, a+c s from __table__ order by s" | ||
) | ||
self.assertEqual( | ||
str(ret_tbl2), | ||
str(pd.DataFrame({"b": [b"one", b"two", b"three"], "s": [2, 4, 6]})), | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Oops, something went wrong.