If I have a class that is wrapping another object (let's say Pandas dataframe), how can I pass the docstrings from the wrapped class to the wrapper class?
For example, in the code below:
import pandas as pd
class DataframeWrapper():
def __init__(self, df):
self.df = df
def plot(self, *args, **kwargs):
self.df.plot(*args, **kwargs)
df1 = pd.DataFrame(data=np.random.normal(0,1, size=(10,2)), columns=['a', 'b'])
wdf1 = DataframeWrapper(df1)
wdf1.plot('a', 'b')
How can I get the plot function in the wrapper class to have the same docstring as Pandas plot (so that it can be seen in Jupyter by pressing shift+tab)?
__doc__property on objects. They are writable.self.plot.__doc__ = df.plot.__doc__AttributeError: attribute '__doc__' of 'method' objects is not writable. I am adding this line to the end of the constructor.