Changeset: 000f25917733 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=000f25917733 Removed Files: monetdb5/extras/pyapi/Tests/fibonacci.py Modified Files: monetdb5/extras/pyapi/Tests/pyapi_numpy_numeric_nested.malC monetdb5/extras/pyapi/Tests/pyapi_pandas.malC monetdb5/extras/pyapi/Tests/pyapi_pandas.stable.err monetdb5/extras/pyapi/Tests/pyapi_pandas.stable.out monetdb5/extras/pyapi/Tests/pyapi_returntypes.malC monetdb5/extras/pyapi/Tests/pyapi_returntypes.stable.err monetdb5/extras/pyapi/Tests/pyapi_returntypes.stable.out monetdb5/extras/pyapi/Tests/pyapi_types_string.malC monetdb5/extras/pyapi/Tests/pyapi_types_string.stable.out Branch: pyapi Log Message:
Fixed tests so they run on any PC. diffs (truncated from 642 to 300 lines): diff --git a/monetdb5/extras/pyapi/Tests/fibonacci.py b/monetdb5/extras/pyapi/Tests/fibonacci.py deleted file mode 100644 --- a/monetdb5/extras/pyapi/Tests/fibonacci.py +++ /dev/null @@ -1,10 +0,0 @@ -def fibonacci(nmbr): - if (nmbr == 0): return 0 - if (nmbr == 1): return 1 - a = 0 - b = 1 - for i in range(0, nmbr - 1): - c = a + b - a = b - b = c - return b diff --git a/monetdb5/extras/pyapi/Tests/pyapi_numpy_numeric_nested.malC b/monetdb5/extras/pyapi/Tests/pyapi_numpy_numeric_nested.malC --- a/monetdb5/extras/pyapi/Tests/pyapi_numpy_numeric_nested.malC +++ b/monetdb5/extras/pyapi/Tests/pyapi_numpy_numeric_nested.malC @@ -72,8 +72,8 @@ bat.append(fib, 27:int); bat.append(fib, 28:int); bat.append(fib, 29:int); -# load a UDF from a file (to compute fibonacci sequence) and map it onto an array -s:bat[:oid,:dbl] := pyapi.eval(nil:ptr, "import imp\nfib = imp.load_source('fibonacci', '/home/mytherin/Programs/MonetDB/monetdb5/extras/pyapi/Tests/fibonacci.py')\nreturn(map(fib.fibonacci, arg1))", fib); +# define a function within the main function and map it to a BAT +s:bat[:oid,:dbl] := pyapi.eval(nil:ptr, "def fibonacci(nmbr):\n\tif (nmbr == 0): return 0\n\tif (nmbr == 1): return 1\n\ta = 0\n\tb = 1\n\tfor i in range(0, nmbr - 1):\n\t\tc = a + b\n\t\ta = b\n\t\tb = c\n\treturn b\nreturn(map(fibonacci, arg1))", fib); io.print(s); indices:= bat.new(:oid,:int); @@ -230,6 +230,6 @@ bat.append(indices, 149:int); bat.append(indices, 150:int); -# load a UDF from a file (to compute fibonacci sequence) and map it onto an array, we need to put the result in a hge type because otherwise it doesn't fit -s:bat[:oid,:hge] := pyapi.eval(nil:ptr, "import imp\nfib = imp.load_source('fibonacci', '/home/mytherin/Programs/MonetDB/monetdb5/extras/pyapi/Tests/fibonacci.py')\nreturn(map(fib.fibonacci, arg1))", indices); +# now do it while returning a hge, to test returning very large numbers +s:bat[:oid,:hge] := pyapi.eval(nil:ptr, "def fibonacci(nmbr):\n\tif (nmbr == 0): return 0\n\tif (nmbr == 1): return 1\n\ta = 0\n\tb = 1\n\tfor i in range(0, nmbr - 1):\n\t\tc = a + b\n\t\ta = b\n\t\tb = c\n\treturn b\nreturn(map(fibonacci, arg1))", indices); io.print(s); diff --git a/monetdb5/extras/pyapi/Tests/pyapi_pandas.malC b/monetdb5/extras/pyapi/Tests/pyapi_pandas.malC --- a/monetdb5/extras/pyapi/Tests/pyapi_pandas.malC +++ b/monetdb5/extras/pyapi/Tests/pyapi_pandas.malC @@ -1,14 +1,6 @@ - -# read data from a CSV file using the Python PANDAS library and store it in a BAT -# requires python-pandas to be installed -# CSV location is hardcoded (sorry) ----->---------->----------->-------->------vvvv -r:bat[:oid,:int] := pyapi.eval(nil:ptr, "import pandas as pd\ndf = pd.read_csv(\"/home/mytherin/Programs/MonetDB/monetdb5/extras/pyapi/Tests/bikedata.csv\")\nreturn([list(df['Berri 1'])])"); -io.print(r); - -# use pandas to perform data aggregation g:= bat.new(:oid,:int); bat.append(g,1); bat.append(g,2); @@ -36,3 +28,26 @@ bat.append(b,1189641421:dbl); (r:bat[:oid,:int], s:bat[:oid,:dbl]) := pyapi.eval(nil:ptr,"import pandas as pd\ndf = pd.DataFrame({\'Group\': arg1, \'Values\': arg2})\ngrouped = df.groupby('Group')\nreturn([grouped.groups.keys(),grouped.sum().values.flatten()])", g, b); io.print(r,s); + + +############## +# --PANDAS-- # +############## +c:= bat.new(:oid,:int); +bat.append(c,4:int); +bat.append(c,24:int); +bat.append(c,363:int); +bat.append(c,63:int); +bat.append(c,838:int); +bat.append(c,454:int); +bat.append(c,22:int); +bat.append(c,663:int); +bat.append(c,123:int); +bat.append(c,442:int); + +# return a pandas dataframe +(r:bat[:oid,:int], s:bat[:oid,:int]) := pyapi.eval(nil:ptr,"import pandas as pd\ndf = pd.DataFrame({\'Group\': arg1, \'Values\': arg2})\nreturn(df)", g, c); +io.print(r,s); + +# return a pandas dataframe with the incorrect format (return a dataframe with 3 columns when 2 columns are expected) +(r:bat[:oid,:int], s:bat[:oid,:int]) := pyapi.eval(nil:ptr,"import pandas as pd\ndf = pd.DataFrame({\'Group\': arg1, \'Values\': arg2, 'Values2': arg2})\nreturn(df)", g, c); diff --git a/monetdb5/extras/pyapi/Tests/pyapi_pandas.stable.err b/monetdb5/extras/pyapi/Tests/pyapi_pandas.stable.err --- a/monetdb5/extras/pyapi/Tests/pyapi_pandas.stable.err +++ b/monetdb5/extras/pyapi/Tests/pyapi_pandas.stable.err @@ -31,6 +31,9 @@ stderr of test 'pyapi_pandas` in directo # 19:41:50 > "mclient" "-lmal" "-ftest" "-Eutf-8" "-i" "-e" "--host=/var/tmp/mtest-7261" "--port=31934" # 19:41:50 > +MAPI = (monetdb) /var/tmp/mtest-16516/.s.monetdb.30115 +QUERY = (r:bat[:oid,:int], s:bat[:oid,:int]) := pyapi.eval(nil:ptr,"import pandas as pd\ndf = pd.DataFrame({\'Group\': arg1, \'Values\': arg2, 'Values2': arg2})\nreturn(df)", g, c); +ERROR = !MALException:pyapi.eval:An array of size 3 was returned, yet we expect a list of 2 columns. The result is invalid. # 19:41:50 > # 19:41:50 > "Done." diff --git a/monetdb5/extras/pyapi/Tests/pyapi_pandas.stable.out b/monetdb5/extras/pyapi/Tests/pyapi_pandas.stable.out --- a/monetdb5/extras/pyapi/Tests/pyapi_pandas.stable.out +++ b/monetdb5/extras/pyapi/Tests/pyapi_pandas.stable.out @@ -25,321 +25,6 @@ Ready. # 19:41:50 > "mclient" "-lmal" "-ftest" "-Eutf-8" "-i" "-e" "--host=/var/tmp/mtest-7261" "--port=31934" # 19:41:50 > -#io.print(r); -#--------------------------# -# h t # name -# void int # type -#--------------------------# -[ 0@0, 35 ] -[ 1@0, 83 ] -[ 2@0, 135 ] -[ 3@0, 144 ] -[ 4@0, 197 ] -[ 5@0, 146 ] -[ 6@0, 98 ] -[ 7@0, 95 ] -[ 8@0, 244 ] -[ 9@0, 397 ] -[ 10@0, 273 ] -[ 11@0, 157 ] -[ 12@0, 75 ] -[ 13@0, 32 ] -[ 14@0, 54 ] -[ 15@0, 168 ] -[ 16@0, 155 ] -[ 17@0, 139 ] -[ 18@0, 191 ] -[ 19@0, 161 ] -[ 20@0, 53 ] -[ 21@0, 71 ] -[ 22@0, 210 ] -[ 23@0, 299 ] -[ 24@0, 334 ] -[ 25@0, 306 ] -[ 26@0, 91 ] -[ 27@0, 80 ] -[ 28@0, 87 ] -[ 29@0, 219 ] -[ 30@0, 186 ] -[ 31@0, 138 ] -[ 32@0, 217 ] -[ 33@0, 174 ] -[ 34@0, 84 ] -[ 35@0, 72 ] -[ 36@0, 248 ] -[ 37@0, 316 ] -[ 38@0, 271 ] -[ 39@0, 342 ] -[ 40@0, 303 ] -[ 41@0, 71 ] -[ 42@0, 78 ] -[ 43@0, 211 ] -[ 44@0, 318 ] -[ 45@0, 307 ] -[ 46@0, 386 ] -[ 47@0, 332 ] -[ 48@0, 220 ] -[ 49@0, 169 ] -[ 50@0, 303 ] -[ 51@0, 441 ] -[ 52@0, 375 ] -[ 53@0, 397 ] -[ 54@0, 243 ] -[ 55@0, 62 ] -[ 56@0, 78 ] -[ 57@0, 119 ] -[ 58@0, 195 ] -[ 59@0, 242 ] -[ 60@0, 92 ] -[ 61@0, 143 ] -[ 62@0, 82 ] -[ 63@0, 107 ] -[ 64@0, 155 ] -[ 65@0, 269 ] -[ 66@0, 438 ] -[ 67@0, 348 ] -[ 68@0, 371 ] -[ 69@0, 182 ] -[ 70@0, 380 ] -[ 71@0, 802 ] -[ 72@0, 442 ] -[ 73@0, 469 ] -[ 74@0, 724 ] -[ 75@0, 423 ] -[ 76@0, 681 ] -[ 77@0, 1940 ] -[ 78@0, 1821 ] -[ 79@0, 2481 ] -[ 80@0, 2829 ] -[ 81@0, 2195 ] -[ 82@0, 2115 ] -[ 83@0, 753 ] -[ 84@0, 520 ] -[ 85@0, 968 ] -[ 86@0, 1049 ] -[ 87@0, 435 ] -[ 88@0, 878 ] -[ 89@0, 1157 ] -[ 90@0, 980 ] -[ 91@0, 662 ] -[ 92@0, 1937 ] -[ 93@0, 2416 ] -[ 94@0, 2211 ] -[ 95@0, 2424 ] -[ 96@0, 1633 ] -[ 97@0, 1208 ] -[ 98@0, 1164 ] -[ 99@0, 828 ] -[ 100@0, 2183 ] -[ 101@0, 2328 ] -[ 102@0, 3064 ] -[ 103@0, 3341 ] -[ 104@0, 2890 ] -[ 105@0, 2554 ] -[ 106@0, 3643 ] -[ 107@0, 3539 ] -[ 108@0, 3570 ] -[ 109@0, 4231 ] -[ 110@0, 2087 ] -[ 111@0, 533 ] -[ 112@0, 1853 ] -[ 113@0, 623 ] -[ 114@0, 1810 ] -[ 115@0, 2966 ] -[ 116@0, 2751 ] -[ 117@0, 1986 ] -[ 118@0, 1684 ] -[ 119@0, 1970 ] -[ 120@0, 3610 ] -[ 121@0, 1986 ] -[ 122@0, 3724 ] -[ 123@0, 3698 ] -[ 124@0, 2511 ] -[ 125@0, 3492 ] -[ 126@0, 3411 ] -[ 127@0, 5552 ] -[ 128@0, 1241 ] -[ 129@0, 3297 ] -[ 130@0, 2755 ] -[ 131@0, 4639 ] -[ 132@0, 3854 ] -[ 133@0, 2741 ] -[ 134@0, 6189 ] -[ 135@0, 3964 ] -[ 136@0, 4947 ] -[ 137@0, 5351 ] -[ 138@0, 5980 ] -[ 139@0, 4732 ] -[ 140@0, 5255 ] -[ 141@0, 5129 ] -[ 142@0, 2315 ] -[ 143@0, 5974 ] -[ 144@0, 6485 ] -[ 145@0, 5697 ] -[ 146@0, 4974 ] -[ 147@0, 4396 ] -[ 148@0, 4268 ] -[ 149@0, 3154 ] -[ 150@0, 6459 ] -[ 151@0, 5104 ] -[ 152@0, 6097 ] -[ 153@0, 943 ] -[ 154@0, 2755 ] -[ 155@0, 2717 ] -[ 156@0, 5842 ] -[ 157@0, 6037 ] -[ 158@0, 6246 ] -[ 159@0, 4169 ] -[ 160@0, 5164 ] -[ 161@0, 5112 ] -[ 162@0, 6206 ] -[ 163@0, 3361 ] -[ 164@0, 6180 ] -[ 165@0, 6908 ] -[ 166@0, 7077 ] -[ 167@0, 5421 ] -[ 168@0, 4638 ] -[ 169@0, 5921 ] -[ 170@0, 5382 ] -[ 171@0, 5713 ] -[ 172@0, 5183 ] -[ 173@0, 5398 ] -[ 174@0, 3753 ] -[ 175@0, 3341 ] -[ 176@0, 2245 ] -[ 177@0, 3327 ] -[ 178@0, 3141 ] -[ 179@0, 6064 ] -[ 180@0, 5770 ] -[ 181@0, 4738 ] -[ 182@0, 4758 ] -[ 183@0, 4144 ] -[ 184@0, 6712 ] -[ 185@0, 5153 ] -[ 186@0, 6672 ] -[ 187@0, 5958 ] -[ 188@0, 5420 ] -[ 189@0, 4756 ] -[ 190@0, 5661 ] -[ 191@0, 6500 ] _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list