I have written a small python package which extends a pandas dataframe with a few additional methods.
At the moment, I have this code in my package:
def init():
@pd.api.extensions.register_dataframe_accessor("test")
class _:
def __init__(self, pandas_obj):
self._obj = pandas_obj
def myMethod(self):
pass
I then do the following in python:
import pandas as pd
import mypackage as mp
mp.init()
test = pd.Dataframe(<define data frame>)
test.mp.myMethod()
My question is, is it possible to do the pandas import and register the accessor from within the __init__.py
in mypackage, so that once mypackage is imported, I automatically have access to mymethod without the init() step? My current approach feels a bit clunky...