import sys
import scipy as sp
import numpy as np
import matplotlib as mpl
import pandas as pd
import sklearn as skl
from erlport.erlterms import Atom

# simple return sys version
def version():
    return sys.version

# descriptive stats over a dataframe
# this is used with a dynamical assignment since
# data frame will hold by erlang process and the
# syntax to apply functions over data will be complex
def jun_dataframe(df, fn, args, axis=None):
    if ( isinstance(df, pd.core.frame.DataFrame) ):
        if axis is not None:
            fun = getattr(df[axis], fn)
        else:
            fun = getattr(df, fn)
        # explicity execute the fun
        if len(args) == 0:
            value = fun()
        else:
            value = fun(*args)
        # check for instance of int64 and return as scalar
        if isinstance(value, np.int64): 
            return np.asscalar(fun())
        else:
            return value
    else:
        return 'error_format_data_frame_invalid'

# a common function to decode the pandas dataframe into
# a readable erlang term
def to_erl(value):
    if isinstance(value, pd.core.frame.DataFrame):
        # fill NaN as default since term cannot back to py
        jundataframe = value.fillna('NaN').values.tolist()
        columns = list(value)
        return (Atom("pandas.core.frame.DataFrame"), columns, jundataframe)
    else:
        return 'error_formar_data_frame_invalid'

@@ -437,20 +437,35 @@
 s, axis=
+'
 None
+', keywords=%5B%5D
 ):%0A    i
@@ -531,19 +531,17 @@
 xis 
-is not 
+!= '
 None
+'
 :%0A  
@@ -622,24 +622,105 @@
 ttr(df, fn)%0A
+        # make dict from keywords even if empty!%0A        kwargs = dict(keywords)%0A
         # ex
@@ -794,16 +794,24 @@
 e = fun(
+**kwargs
 )%0A      
@@ -843,24 +843,34 @@
  = fun(*args
+, **kwargs
 )%0A        # 
@@ -994,13 +994,13 @@
 lar(
-fun()
+value
 )%0A  

support for keywords in python fun