Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Syntax Question - Qualitative Screen in Pipeline

Can anyone tell me why the following doesn't work? I have a function that computes all the factors for my pipeline. I am trying to filter on the output of one factor, form_type. This factor can represents something like '10-Q','10-K', etc.

The function that pulls the form type is pretty straightforward.

from quantopian.pipeline.data import USEquityPricing, morningstar,Fundamentals  
f = Fundamentals

def form_type():  
   return f.form_type.latest  

I have my pipeline set up as follows.

factors = make_factors()

def make_pipeline(factors):  
    factors = {name: f() for name, f in factors.iteritems()}  
    factors['Sector'] = Sector()  
    ft_filter = (factors['form_type'] == '10-Q')  
    return Pipeline(columns=factors,  
                    screen=base_universe & ft_filter  
                   )  

However, I get the following error. "NotImplementedError: couldn't find matching opcode for 'and_bbi'"

Does anyone know why this isn't working?

6 responses

I'm not sure there is enough information to answer your question. The function make_factors() is never defined in the code snippets you provided.

Sorry, I forgot a few lines of code. I only wanted to include the piece of the get_factors() where I pull form_type, since it is what I am trying to use in the screen.
It would look more like this. This is a shortened version, and form_type() is just one of many factors included in the pipeline.

from quantopian.pipeline.data import USEquityPricing, morningstar,Fundamentals  
f = Fundamentals

def make_factors():

   def form_type():  
         return f.form_type.latest  

all_factors = {  
        'form_type':form_type,  
}        
return all_factors  

As a refresher, it is included in the pipeline as follows.

factors = make_factors()

def make_pipeline(factors):  
    factors = {name: f() for name, f in factors.iteritems()}  
    factors['Sector'] = Sector()  
    ft_filter = (factors['form_type'] == '10-Q')  
    return Pipeline(columns=factors,  
                    screen=base_universe & ft_filter  
                   )  

However, I get the following error. "NotImplementedError: couldn't find matching opcode for 'and_bbi'"

Does anyone know why this isn't working?

Hi Zak,

I should have caught this earlier. The problem is in building your ft_filter. When creating a filter from a factor, you need to use the factor's .eq() method as opposed to the == operator. In other words:

ft_filter = factors['form_type'].eq('10-Q')

After making that change, it seemed to run fine. See attached notebook.

@Zak,

Michael's answer is correct, you need to use .eq to make the comparison here. Pipeline terms that have a dtype (data type) of str or int representing a label or categorical value are of type Classifier, not Factor. The == operator is not overloaded in the Classifier class. Instead, you have to use the Classifier.eq method.

If you haven't seen it yet, the Pipeline Tutorial walks through the differences between Factors, Filters, and Classifiers. I'd recommend taking a read through if you haven't already.

I hope this helps!

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 both. I have seen the pipeline tutorial, but forgot about the distinctions.

Hi Jamie,

Thanks for clarifying the error in my explanation!