Author Topic: returning an array breaks argument passing?  (Read 773 times)

aavanian

  • Newbie
  • *
  • Posts: 27
  • Karma: +0/-0
    • View Profile
returning an array breaks argument passing?
« on: September 17, 2015, 11:12:04 AM »
Hi, I've been trying different things to make this work but couldn't. I reduced the issue to the following (of course, ultimately I want to return a true array, this is only for example):

code:
Code: [Select]
@xl_func("int n, int tpf, float alpha: float[]")
def basic_function(n, tpf, alpha):
    print(n, tpf, alpha)
    res = [[n * tpf * alpha]]
    return res


XL call:
Code: [Select]
=basic_function(20,5,2)
log:
Code: [Select]
2015-09-17 18:02:21,305 - INFO :
------------------------------------------------------------------------------
  PyXLL

  Version          2.2.2
  Buildtime        2014-12-14 17:49
  Python version   3.4.3.final.0
  Excel version    15.0

  www.pyxll.com
------------------------------------------------------------------------------

2015-09-17 18:10:15,715 - DEBUG : Functions will not be cancellable by default.
2015-09-17 18:10:15,716 - DEBUG : Prepending python path with [...]
2015-09-17 18:10:15,716 - DEBUG : Importing basic
2015-09-17 18:10:15,734 - DEBUG : Added worksheet function 'basic_function'
2015-09-17 18:10:15,734 - DEBUG : Imported basic
2015-09-17 18:04:00,665 - INFO : 20 0 1.384459e-317

If I return a float (not an array), then it works as expected.
This seems so basic I must be missing something obvious...

Thanks in advance

Tony

  • Administrator
  • Hero Member
  • *****
  • Posts: 615
  • Karma: +14/-1
    • View Profile
Re: returning an array breaks argument passing?
« Reply #1 on: September 17, 2015, 11:49:33 AM »
Hi,

what get's returned from the function? An error or just a blank cell? It certainly looks like it should work.

Are you using the 32 bit version or 64 bit? If you're using the 64 bit version there was a problem to do with returning arrays, but I'd not seen it happen in such a simple case as this. The workaround for that particular problem is to use var instead of float[], so you try that and see if it works.

The specific problem I'm thinking of is fixed in beta version 2.3, which you can download from https://beta.pyxll.com/download.html. If changing from float[] to var works then it would be worth checking to see if that new version fixes your problem.

If you're not using the 64 bit version and it's not that problem please let me know so I can investigate further.

Best regards,
Tony

Tony

  • Administrator
  • Hero Member
  • *****
  • Posts: 615
  • Karma: +14/-1
    • View Profile
Re: returning an array breaks argument passing?
« Reply #2 on: September 17, 2015, 11:53:35 AM »
Actually, I've just double checked that bug that I was thinking of and it's not limited to just the 64 bit version. It's actually that it only occurs in newer versions of Excel.

I think the beta version of 2.3 will fix your problem. 2.3 will be released as a non-beta release soon.

Best regards,
Tony

aavanian

  • Newbie
  • *
  • Posts: 27
  • Karma: +0/-0
    • View Profile
Re: returning an array breaks argument passing?
« Reply #3 on: September 17, 2015, 01:50:16 PM »
Thanks for the quick feedback.

The function return 0 (because it interprets some arguments as 0) and I'm running the 64bit version.

Indeed, I finally bypassed the problem by returning var[] after tinkering with it and it's working properly.

I'll try to give the 2.3beta a run. If I want to roll back to 2.2, I just have to overwrite the install (keeping the .cfg file), right?

Regards

Tony

  • Administrator
  • Hero Member
  • *****
  • Posts: 615
  • Karma: +14/-1
    • View Profile
Re: returning an array breaks argument passing?
« Reply #4 on: September 17, 2015, 02:44:44 PM »
Hi,

yes exactly - just copy over the pyxll.xll file, none of the others need to be changed.

Best regards,
Tony

aavanian

  • Newbie
  • *
  • Posts: 27
  • Karma: +0/-0
    • View Profile
Re: returning an array breaks argument passing?
« Reply #5 on: September 18, 2015, 07:03:49 AM »
Hi,

my original code (return float[]) works under the 2.3 beta

Regards

Tony

  • Administrator
  • Hero Member
  • *****
  • Posts: 615
  • Karma: +14/-1
    • View Profile
Re: returning an array breaks argument passing?
« Reply #6 on: September 18, 2015, 10:12:18 AM »
Great, thanks for confirming. 2.3 will be released soon!

Best regards,
Tony