Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'Series' object has no attribute 'is_monotonic' #162

Open
alexxiecan opened this issue May 3, 2023 · 19 comments
Open

AttributeError: 'Series' object has no attribute 'is_monotonic' #162

alexxiecan opened this issue May 3, 2023 · 19 comments

Comments

@alexxiecan
Copy link

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!

@kcleal
Copy link

kcleal commented May 19, 2023

Same issue here. Looks like that function has been removed from pandas?

@alexxiecan
Copy link
Author

alexxiecan commented May 19, 2023 via email

@CarlosHernandezP
Copy link

CarlosHernandezP commented Jun 29, 2023

Have you found a way to use a 2.* version of pandas and pycox simultaneously.

Are there plans to update the pycox code to reflect this underlying change in pandas?

@salan668
Copy link

Yes, I have to change it manually to make it works.

Further, maybe a version restriction should be added in the setup.py .

@alexxiecan
Copy link
Author

alexxiecan commented Jul 19, 2023 via email

@jjww2023
Copy link

I encountered a similar issue when using the pycox class EvalSurv to evaluate the concordance. The error message was "AttributeError: 'Series' object has no attribute 'is_monotonic'. " Can anyone help me solve the problem? Thanks!

@alexxiecan
Copy link
Author

alexxiecan commented Aug 29, 2023 via email

@jjww2023
Copy link

jjww2023 commented Aug 30, 2023 via email

@jjww2023
Copy link

jjww2023 commented Aug 30, 2023 via email

@alexxiecan
Copy link
Author

alexxiecan commented Aug 30, 2023 via email

@alexxiecan
Copy link
Author

alexxiecan commented Aug 30, 2023 via email

@jjww2023
Copy link

jjww2023 commented Aug 30, 2023 via email

@xytd20
Copy link

xytd20 commented Aug 30, 2023

but I still can't run it after I change all ‘is_monotonic’ into ‘is_monotonic_increasing’

@jjww2023
Copy link

jjww2023 commented Aug 30, 2023 via email

@qaisqasaimeh
Copy link

Could you please elaborate more on this issue?

@amir78pgd
Copy link

to what version of pandas and pycox did u upgrade ?

@chengzhishi
Copy link

36 assert pd.Series(self.index_surv).is_monotonic
change this line to assert pd.Series(self.index_surv).is_monotonic_increasing
Or downgrade your pandas to 1.8

@mafanedza
Copy link

36 assert pd.Series(self.index_surv).is_monotonic change this line to assert pd.Series(self.index_surv).is_monotonic_increasing Or downgrade your pandas to 1.5

@antonromashko
Copy link

fixed with PR #180, many thanks to @havakv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests