-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests and docs for python plugin
- Loading branch information
Showing
3 changed files
with
72 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import pandas as pd | ||
import numpy as np | ||
import pytest | ||
|
||
from countess.core.logger import ConsoleLogger | ||
from countess.plugins.python import PythonPlugin | ||
|
||
logger = ConsoleLogger() | ||
|
||
|
||
dfi = pd.DataFrame([[1,1,2,7,11],[2,2,3,8,1],[3,3,4,9,3],[4,4,5,10,4],[5,5,6,12,7]], columns=['a','b','c','d','e']) | ||
|
||
def test_python_builtins(): | ||
plugin = PythonPlugin() | ||
plugin.set_parameter("code", """ | ||
x = mean(a,b,c,d,e) | ||
y = std(a,b,c,d,e) | ||
z = sqrt(pow(a,2) + pow(b,2)) | ||
v = var(a,b,c,d,e) | ||
""") | ||
|
||
plugin.prepare(["test"], None) | ||
dfo = plugin.process_dataframe(dfi, logger) | ||
output = dfo.to_records() | ||
|
||
assert output[0]["x"] == 4.4 | ||
assert 2.48 < output[1]["y"] < 2.49 | ||
assert 4.24 < output[2]["z"] < 4.25 | ||
assert 5.43 < output[3]["v"] < 5.45 | ||
|
||
|
||
def test_python_dropna(): | ||
plugin = PythonPlugin() | ||
plugin.set_parameter("code", """ | ||
a = None | ||
n = None | ||
if d >= 10: d = None | ||
""") | ||
plugin.set_parameter("dropna", True) | ||
|
||
plugin.prepare(["test"], None) | ||
dfo = plugin.process_dataframe(dfi, logger) | ||
|
||
assert "a" not in dfo.columns | ||
assert "n" not in dfo.columns | ||
assert "d" in dfo.columns | ||
|
||
assert any(np.isnan(dfo['d'])) | ||
assert not any(np.isnan(dfo['b'])) |