Skip to content
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

variables.vexec inconsistent with docs #35

Open
sykesdev opened this issue Jun 11, 2020 · 2 comments
Open

variables.vexec inconsistent with docs #35

sykesdev opened this issue Jun 11, 2020 · 2 comments

Comments

@sykesdev
Copy link

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
Copy link
Collaborator

Thank you, really appreciate your efforts!

@sykesdev
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants