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

numpy scalars break with v0.7 #415

Closed
cincin77 opened this Issue Mar 22, 2016 · 7 comments

Comments

Projects
None yet
2 participants
@cincin77

cincin77 commented Mar 22, 2016

I can no longer call my Python functions after i upgraded to v0.7.
v0.7 is installed while there was v0.6.x on the system. xlwings addin update is run. v0.7's .bas file is imported into the excel. xlwings32.dll that comes with v0.7 is copied to the python installation folder.
Excel knows about the Python functions but they return #VALUE!

@fzumstein

This comment has been minimized.

Member

fzumstein commented Mar 22, 2016

Can you please download the udf.zip (example 6) from here, unzip and check if it works or if you get any errors with this?

@cincin77

This comment has been minimized.

cincin77 commented Mar 22, 2016

It worked. Then should everything be ok?

@fzumstein

This comment has been minimized.

Member

fzumstein commented Mar 22, 2016

Are you using very big arrays in your functions, i.e. do they work with a small toy sample? If so, then it's likely that some of the data processing/cleaning we've added causes this, see also: #396, #397, #401.

If that's not the case, then please post a sample UDF to replicate the issue.

@cincin77

This comment has been minimized.

cincin77 commented Mar 22, 2016

actually it is a very simple UDF that causes this problem:

import math
from scipy.stats import norm
import xlwings as xw

@xw.func
def GBlackScholes(callputflag,S, X, t, r, b, v):
    d1 = (math.log(S/X)+(b+math.pow(v, 2)/2)*t)/(v*math.sqrt(t))
    # print(d1)
    d2 = d1 - v * math.sqrt(t)
    if callputflag == 'c':
        val = S*math.exp((b-r)*t)*norm.cdf(d1) - X*math.exp(-r*t)*norm.cdf(d2)
    elif callputflag == 'p':
        val = X*math.exp(-r*t) * norm.cdf(-d2) - S*math.exp((b-r)*t)*norm.cdf(-d1)
    return val
@fzumstein

This comment has been minimized.

Member

fzumstein commented Mar 22, 2016

Ok the issue is that val is a numpy scalar of type numpy.float64 which are currently causing troubles as this has in fact changed with 0.7 (<0.7 numpy scalars were returned as 1d arrays). To fix this, just transform things back into a regular float: return float(val) for now until we have a fix implemented for this.

@fzumstein fzumstein changed the title from xlwings problem after upgrading to 0.7 to numpy scalars break with v0.7 Mar 22, 2016

@fzumstein fzumstein added the bug label Mar 22, 2016

@cincin77

This comment has been minimized.

cincin77 commented Mar 22, 2016

Thanks.
By the way, i had another function that returns nothing and it also had the problem. I returned a dummy value in order to solve it. Shall this be another bug?

@fzumstein

This comment has been minimized.

Member

fzumstein commented Mar 22, 2016

This one has already been logged here: #390

@fzumstein fzumstein added this to the v0.7.1 milestone Mar 22, 2016

@fzumstein fzumstein closed this Mar 22, 2016

@fzumstein fzumstein referenced this issue Mar 22, 2016

Merged

Smaller fixes #416

fzumstein added a commit that referenced this issue Jun 28, 2016

fzumstein added a commit that referenced this issue Jun 30, 2016

Bluesky range tests (#501)
* Refactored range tests, added missing mac-fix for #415
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment