pycox
pycox copied to clipboard
AttributeError: 'Series' object has no attribute 'is_monotonic'
Hi, dear Haavard
When I execute this function---- ev=EvalSurv (surv, durations_test, events_test, center_surv='km '), the following error occurs:
AttributeError Traceback (most recent call last) Cell In[27], line 1 ----> 1 ev = EvalSurv(surv, durations_test, events_test, censor_surv='km')
File D:\anaconda3\envs\pytorch\lib\site-packages\pycox\evaluation\eval_surv.py:33, in EvalSurv.init(self, surv, durations, events, censor_surv, censor_durations, steps) 31 self.durations = durations 32 self.events = events ---> 33 self.censor_surv = censor_surv 34 self.censor_durations = censor_durations 35 self.steps = steps
File D:\anaconda3\envs\pytorch\lib\site-packages\pycox\evaluation\eval_surv.py:51, in EvalSurv.censor_surv(self, censor_surv) 49 elif type(censor_surv) is str: 50 if censor_surv == 'km': ---> 51 self.add_km_censor() 52 else: 53 raise ValueError(f"censor_surv cannot be {censor_surv}. Use e.g. 'km'")
File D:\anaconda3\envs\pytorch\lib\site-packages\pycox\evaluation\eval_surv.py:107, in EvalSurv.add_km_censor(self, steps) 104 km = utils.kaplan_meier(self.durations, 1-self.events) 105 surv = pd.DataFrame(np.repeat(km.values.reshape(-1, 1), len(self.durations), axis=1), 106 index=km.index) --> 107 return self.add_censor_est(surv, steps)
File D:\anaconda3\envs\pytorch\lib\site-packages\pycox\evaluation\eval_surv.py:95, in EvalSurv.add_censor_est(self, censor_surv, steps)
84 """Add censoring estimates so one can use inverse censoring weighting.
85 censor_surv
are the survival estimates trained on (durations, 1-events),
86
(...)
92 or lower index 'post'. If None
use self.steps
(default: {None})
93 """
94 if not isinstance(censor_surv, EvalSurv):
---> 95 censor_surv = self._constructor(censor_surv, self.durations, 1-self.events, None,
96 steps=steps)
97 self.censor_surv = censor_surv
98 return self
File D:\anaconda3\envs\pytorch\lib\site-packages\pycox\evaluation\eval_surv.py:36, in EvalSurv.init(self, surv, durations, events, censor_surv, censor_durations, steps) 34 self.censor_durations = censor_durations 35 self.steps = steps ---> 36 assert pd.Series(self.index_surv).is_monotonic
File D:\anaconda3\envs\pytorch\lib\site-packages\pandas\core\generic.py:5989, in NDFrame.getattr(self, name) 5982 if ( 5983 name not in self._internal_names_set 5984 and name not in self._metadata 5985 and name not in self._accessors 5986 and self._info_axis._can_hold_identifiers_and_holds_name(name) 5987 ): 5988 return self[name] -> 5989 return object.getattribute(self, name)
AttributeError: 'Series' object has no attribute 'is_monotonic'
Have you ever encountered this problem? Thank you!