Skip to content

variables.vexec inconsistent with docs #35

@sykesdev

Description

@sykesdev

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions