Back to Community
Bug in Pipeline output or pandas?

Hi Folks

I've been trying to extract a single value from a dataframe returned by the pipeline. Not sure if I'm doing something wrong or there's a bug in get_value ?

Algo is fairly straightforward. Here's how I'm building the pipeline:

def make_pipeline():  
    returns_builtin = Returns(  
    window_length=20,  
)
    return Pipeline(  
        columns={  
            'Builtin_returns': returns_builtin,  
        }, screen = StaticAssets(symbols('AMZN', 'MSFT', 'ADBE'))  
    )  

And here's my attempt at parsing the output

def before_trading_start(context,data):  
    msft = symbols('MSFT')  
    result_today_df = algo.pipeline_output('my_pipeline')  
    print((result_today_df.get_value(msft,'Builtin_returns')))

However get_value throws this runtime error:

TypeError: '[Equity(5061 [MSFT])]' is an invalid key There was a
runtime error on line 102.

Funny thing is the pipeline does return a 3x1 shaped dataframe

Appreciate your help in figuring this out

3 responses

The answer to this conundrum is the subtle difference between the two functions symbol and symbols (notice the 's' at the end). The symbol function returns a single asset object while the symbols function (plural) returns a list of asset objects. In the later case, even though there may be a single asset, it is still a list but just a list of one.

So, the error

TypeError: '[Equity(5061 [MSFT])]' is an invalid key

stems from the fact that the get_value method expects a single value and not a list. It's easy to miss, but notice in the error message there are brackets around 'Equity(5061 [MSFT])' indicating a list. The fix is easy. Change symbols to symbol something like this

    msft = symbol('MSFT')  

That should do it. Good luck!

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

thank you Dan. I literally discovered it and you beat me to the reply. Thanks for your quick response.

@varun uppal Good you got it working. I often get caught with the difference between symbols and symbol too. Especially when copying code from research into the IDE. In the research environment there is just the single function symbols.