CamDavidsonPilon / lifelines

Survival analysis in Python
lifelines.readthedocs.org
MIT License
2.32k stars 551 forks source link

KaplanMeierFitter `label` class attribute is not inherited #1552

Closed CatChenal closed 9 months ago

CatChenal commented 10 months ago

The KaplanMeierFitter class (KM) has a handy label attribute: a plot of the fitted values will inherit the label in the legend. However, the corresponding attribute of an instance becomes _label:

km1 = KM(label='S1: Stage III')
km1._label                      # discovered via dir(km1)
>>> 'S1: Stage III'

But

km1 = KM(label='S1: Stage III')
km1.label  # 'S1: Stage III'
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-116-bb7f3ecaa1b2> in <module>
----> 1 km1.label

AttributeError: 'KaplanMeierFitter' object has no attribute 'label'

Having to run dir() on an instance to find out if/how a class attribute is inherited is a drawback, especially when working with multiple models programmatically. Is there a specific reason for this?

CamDavidsonPilon commented 9 months ago

Hi @CatChenal,

No reason really, probably just inexperience when I first wrote this. I'll promote it to a top level attribute.

CatChenal commented 9 months ago

Thanks!