jeudi 25 juillet 2019

How to implement functions which act as instance method as well as class methods in python?

I am working on a class which represents a stock portfolio. I have been implementing this by extending over pandas.DataFrame. I have been writing some generic portfolio analyzing visualizations. Till now I have a module with all visualization functions which can be used as

visualization1(portfolio_instance ,*args, **kwargs)

I did wrap them to be used as instance methods like

def visualization(self, *args, **kwargs):
       from module import visualziation1

        return visualziation1(self.data, *args, **kwargs)

But I am pretty sure there is a better way for this

How are these implemented in standard library like pandas for e.g.

df_inst_1.merge(df_inst_2, on = 'something', how= 'left' )

and

pd.merge(df_inst_1, df_inst_2, on ='something', how = 'left')

Aucun commentaire:

Enregistrer un commentaire