So when I create function that references Data I need to pass Data to the function, i.e. it is not global. There appears to be no conflict in calling the variable I pass to the function by the same name, "Data". Now, the Data variable is a Datapanel, is it not?
I ask because I noticed something bizarre. So I created a function that performs a batch_transform and I pass the Data variable to it, calling it Data in the function as well. Everything seemed to work until I tried to do a "Prices.mean" transform - the program says it does not recognize that transform.
So I tried playing with the function in the API Docs.
The original function runs without issue:
@batch_transform(window_length=10)
def get_averages(datapanel):
# get the dataframe of prices
prices = datapanel['price']
# return a dataframe with one row showing the averages for each stock.
return prices.mean()
But if I replace 'datapanel' with 'data' I get the same error, mean transform not recognized:
@batch_transform(window_length=10)
def get_averages(data):
# get the dataframe of prices
prices = data['price']
# return a dataframe with one row showing the averages for each stock.
return prices.mean()
So I tried a total made up name, yabbazabba, for the data variable and that works:
@batch_transform(window_length=10)
def get_averages(yabbazabba):
# get the dataframe of prices
prices = yabbazabba['price']
# return a dataframe with one row showing the averages for each stock.
return prices.mean()
** So the question: it appears that there is something special about the name 'data' for a variable and it is essentially reserved. Is this true? It seems to be the default to pass 'data' by the name 'data' to other functions, except in the case where we are doing a batch_transform where the default seems to be datapanel? At least that seems to be the tendency in the API Docs. I guess I'm just confused as to the cause of this particular error. If data is not global, why should it be different than using yabbazabba? **
Obviously this problem is easy to work around but it has me curious as to what is going on...