Skip to content

update PythonFunction test case #415

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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
42 changes: 40 additions & 2 deletions tests/test_base_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import numpy as np
import pandas as pd
from sqlalchemy import Column, Float, DateTime
from iotfunctions.bif import Coalesce, DateDifference
from iotfunctions.db import Database
from iotfunctions.dbtables import FileModelStore
from iotfunctions.bif import Coalesce, DateDifference, PythonFunction
from nose.tools import assert_true

# constants
Expand All @@ -14,6 +16,21 @@
sal = 'SaliencyAnomalyScore'
gen = 'TemperatureGeneralizedScore'

@nottest
class DatabaseDummy:
tenant_id = '###_IBM_###'
db_type = 'db2'
model_store = FileModelStore('./data')

def _init(self):
return

def make_function(self, function_name, function_code, filename=None, bucket=None):
print(function_code)
exec(function_code)
fn = locals()[function_name]
return fn


def test_base_functions():

Expand Down Expand Up @@ -80,6 +97,27 @@ def test_base_functions():
print (df_i['datediff'])
comp = (np.all(results1 == origins1), np.all(results2 == origins2),
np.all(df_i['datediff'] == my_delta))
results1 = df_i['Results1'].values[0:5]

print('Python Functions')

db_schema=None
db = DatabaseDummy()
jobsettings = { 'db': db, '_db_schema': 'public'} #, 'save_trace_to_file' : True}

funcStr = \
'def my_test_function(df, parameters):\n print(df.columns)\n print(parameters)\n df[\'PythonFunction\']=\'PythonFunction\'\n\
return df'

bif_pf = PythonFunction(funcStr, 'datediff', 'PythonFunction', {'function_name': 'my_test_function', 'a': 63})
et = bif_pf._build_entity_type(columns=[Column('datediff', DateTime())], **jobsettings)

bif_pf._entity_type = et
print(bif_pf._entity_type._timestamp)
df_i = bif_pf.execute(df=df_i)

print(df_i['PythonFunction'][0])


print(results1)
print(results2)
Expand All @@ -93,4 +131,4 @@ def test_base_functions():

pass

# test_base_scores()
#test_base_functions()