ScottfreeLLC / AlphaPy

Python AutoML for Trading Systems and Sports Betting
Apache License 2.0
1.11k stars 201 forks source link

variables.vexec inconsistent with docs #35

Open sykesdev opened 4 years ago

sykesdev commented 4 years ago

Hi,

Hopefully these contributions are useful, it seems very quiet, hopefully you are all in good health!

vexec's doc says "To write your own variable function, your function must have a pandas DataFrame as an input parameter and must return a pandas DataFrame with the new variable(s)."

However it doesn't quite work that way. Perhaps something like the change below would be useful?

diff --git a/alphapy/variables.py b/alphapy/variables.py
index 8477647..ed3bc9a 100644
--- a/alphapy/variables.py
+++ b/alphapy/variables.py
@@ -448,7 +448,11 @@ def vexec(f, v, vfuncs=None):
                         func = None
             if func:
                 # Create the variable by calling the function
-                f[v] = func(*newlist)
+                r = func(*newlist)
+                if(type(r) is pd.core.frame.DataFrame):
+                    f = pd.concat([f, r], axis=1, join='inner')
+                else:
+                    f[v] = r
             elif func_name not in dir(builtins):
                 module_error = "*** Could not find module to execute function {} ***".format(func_name)
                 logger.error(module_error)

All the best.

mrconway commented 4 years ago

Thank you, really appreciate your efforts!

sykesdev commented 4 years ago

You're welcome. Please let me know if anything is wrong / non-idiomatic / stylistically bad etc, I'm happy to take your lead...