Back to Community
Annoying import warnings for built-in functions

Hi!

First of all, thanks for what you've built so far, both the platform and the lectures. Amazing stuff.

I was following the Hypotesis Testing Tutorial (great, again), and in the middle of it I tried to see what the attributes of a Equity object were. For that, I looked up in the interned for ways to list the attributes, and I found here and here that the method dict(with double underscores) of an object is one, and another one is using the built-in function getattr(object_name, attribute). Both trials caused a warning message similar to the following one to appear:

InputRejected:
Insecure built-in function 'getattr' Last warning! One more import error and your account will be suspended for security reasons until a human can talk to you.

It was this chunk of code what caused the problem

symbol_list = ["SPY", "AAPL"]  
start = '2015-01-01'  
end = '2016-01-01'  
pricing_sample = get_pricing(symbol_list, start_date = start, end_date = end, fields='price')  
elements = [element for element in dir(pricing_sample.columns[0])]

for element in elements:  
    getattr(pricing_sample.columns[0], element)  

This is pretty annoying, as I wasn't trying to break Quantopian or anything, just trying to learn a bit more of what I was doing.

I understand that some caution has to be taken, but it would be nice to revise all those functions/ libraries that probably don't represent any security issue to Quantopian but are not allowed yet to be used, some of them already requested more than 2 years ago...

Again, thanks for everything and keep getting better!

PS: is there any safe way to do what I was trying to do, apart from doing pricing_sample.columns[0].attribute1, pricing_sample.columns[0].attribute2...? EDIT: Yes, the method to_dict().

2 responses

Hi!

A simpler way in the Quantopian Research environment is simply to run foo = pricing_sample.columns[0] and then, in the next cell, write foo. and hit the tab key. A drop-down menu will then appear showing you not only all the attributes of foo, the Equity object, but also any methods you can call on it.

This is a nice feature of Jupyter notebooks and is super helpful because it works for any object.

Hi George,

Yes, I'm aware of that, I've been using ipython notebooks for a while. What I wanted was to know the value of each of the attributes, and that can be made with the method to_dict() of an Equity object, as I added yesterday to the end of my message.

One thing that is not good about the Research environment, related to what you say, is that, for example, the function getattr appeared on that drop-down menu yesterday after typing getat and the tab key, as one of the functions in theory available, but was indeed not available.

BTW, how do you write coloured text like that in your message?

Thanks!
Xoel