Pyvot 0.1.2 error in xl.apply


In tools.py version 0.1.2 (the latest, AFAIK), there is a function xl.apply(), which runs on a column, creating a new column with the list that is returned. This fails with an error such as the following:
>>> xl.apply(CompareToAverage, wb.get("id"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\pyvot-0.1.2-py2.7.egg\xl\tools.py", line 94, in apply
    y = __builtin__.apply(func, xs)
TypeError: apply() arg 2 expected sequence, found generator
The reason for this error seems to be line 92 in xl/tools.py:
xs = (_to_value(r) for r in rangeIn)  
That is a generator expression. The apply function is expecting a list, not a generator, so it blows up.

If you change the line to a list comprehension (replace outer parens with brackets), it works as expected:
xs = [_to_value(r) for r in rangeIn]
Hope this helps.


Zooba wrote Mar 26 at 11:58 PM

I'd suggest the better fix is changing the apply call to be func(*xs) (supported since 2.3, according to the docs).

Thanks for the report!