havakv / pycox

Survival analysis with PyTorch
BSD 2-Clause "Simplified" License
803 stars 188 forks source link

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

Open alexxiecan opened 1 year ago

alexxiecan commented 1 year ago

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 commented 1 year ago

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

alexxiecan commented 1 year ago

Yes, in the new version of Pandas, use “is monotonic incrementing” instead of "is_ monotonic"    

谢灿 @.***

 

------------------ 原始邮件 ------------------ 发件人: "Kez @.>; 发送时间: 2023年5月19日(星期五) 晚上10:10 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [havakv/pycox] AttributeError: 'Series' object has no attribute 'is_monotonic' (Issue #162)

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

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

CarlosHernandezP commented 1 year ago

Have you found a way to use a 2.* version of pandasand pycoxsimultaneously.

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

salan668 commented 1 year ago

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

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

alexxiecan commented 1 year ago

thank you, dude  

谢灿 @.***

 

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2023年7月19日(星期三) 下午3:00 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [havakv/pycox] AttributeError: 'Series' object has no attribute 'is_monotonic' (Issue #162)

是的,我必须手动更改它,使其工作。

此外,也许应该在setup.py中添加版本限制。

— 直接回复此邮件,在GitHub上查看,或者取消订阅. @.***与>.

jjww2023 commented 1 year ago

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 commented 1 year ago

Changed pd.Series.is_monotonic to pd.Series.is_monotonic_increasing for newer versions of pandas.  

谢灿 @.***

 

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2023年8月29日(星期二) 中午1:20 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [havakv/pycox] AttributeError: 'Series' object has no attribute 'is_monotonic' (Issue #162)

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!

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

jjww2023 commented 1 year ago

Hi Can,

Thank you so much for your reply. I appreciate you taking your valuable time to help me. I followed your instruction by changing the line “assert pd.Series(self.index_surv).is_monotonic” to “assert pd.Series.is_monotonic_increasing” in the eval_surv.py file. However, I still encountered the same error.

The example that I am using is the pycox dataset “metabric”. The pythyon syntax has been posted at this link: https://github.com/havakv/pycox/blob/master/examples/cox-ph.ipynb . I am able to run all lines except “ev = EvalSurv(surv, durations_test, events_test, censor_surv='km')” . I have attached the eval_surv.py file, and would appreciate it very much if you could please review it and advise me.

Thank you, sincerely, Jane

From: Can Xie @.> Sent: Tuesday, August 29, 2023 4:43 AM To: havakv/pycox @.> Cc: Jing Wang @.>; Comment @.> Subject: Re: [havakv/pycox] AttributeError: 'Series' object has no attribute 'is_monotonic' (Issue #162)

Changed pd.Series.is_monotonic to pd.Series.is_monotonic_increasing for newer versions of pandas.  

谢灿 @.<mailto:@.>

 

------------------ 原始邮件 ------------------ 发件人: @.&gt<mailto:@.&gt>;; 发送时间: 2023年8月29日(星期二) 中午1:20 收件人: @.&gt<mailto:@.&gt>;; 抄送: @.&gt<mailto:@.&gt>;; @.&gt<mailto:@.&gt>;; 主题: Re: [havakv/pycox] AttributeError: 'Series' object has no attribute 'is_monotonic' (Issue #162)

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!

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.&gt<mailto:@.&gt>;

— Reply to this email directly, view it on GitHubhttps://github.com/havakv/pycox/issues/162#issuecomment-1697194057, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BCGNGDQ7CHWBRU4TWZSWBNDXXXBR7ANCNFSM6AAAAAAXUNTZ4Q. You are receiving this because you commented.Message ID: @.**@.>>

jjww2023 commented 1 year ago

Hi Can,

I wanted to let you know that I was just able to run the EvalSurv after upgrading pandas and pycox.

Thanks again for your help! Jane From: Jing Wang @.> Sent: Tuesday, August 29, 2023 10:30 PM To: havakv/pycox @.>; havakv/pycox @.> Cc: Comment @.> Subject: RE: [havakv/pycox] AttributeError: 'Series' object has no attribute 'is_monotonic' (Issue #162)

Hi Can,

Thank you so much for your reply. I appreciate you taking your valuable time to help me. I followed your instruction by changing the line “assert pd.Series(self.index_surv).is_monotonic” to “assert pd.Series.is_monotonic_increasing” in the eval_surv.py file. However, I still encountered the same error.

The example that I am using is the pycox dataset “metabric”. The pythyon syntax has been posted at this link: https://github.com/havakv/pycox/blob/master/examples/cox-ph.ipynb . I am able to run all lines except “ev = EvalSurv(surv, durations_test, events_test, censor_surv='km')” . I have attached the eval_surv.py file, and would appreciate it very much if you could please review it and advise me.

Thank you, sincerely, Jane

From: Can Xie @.**@.>> Sent: Tuesday, August 29, 2023 4:43 AM To: havakv/pycox @.**@.>> Cc: Jing Wang @.**@.>>; Comment @.**@.>> Subject: Re: [havakv/pycox] AttributeError: 'Series' object has no attribute 'is_monotonic' (Issue #162)

Changed pd.Series.is_monotonic to pd.Series.is_monotonic_increasing for newer versions of pandas.  

谢灿 @.<mailto:@.>

 

------------------ 原始邮件 ------------------ 发件人: @.&gt<mailto:@.&gt>;; 发送时间: 2023年8月29日(星期二) 中午1:20 收件人: @.&gt<mailto:@.&gt>;; 抄送: @.&gt<mailto:@.&gt>;; @.&gt<mailto:@.&gt>;; 主题: Re: [havakv/pycox] AttributeError: 'Series' object has no attribute 'is_monotonic' (Issue #162)

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!

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.&gt<mailto:@.&gt>;

— Reply to this email directly, view it on GitHubhttps://github.com/havakv/pycox/issues/162#issuecomment-1697194057, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BCGNGDQ7CHWBRU4TWZSWBNDXXXBR7ANCNFSM6AAAAAAXUNTZ4Q. You are receiving this because you commented.Message ID: @.**@.>>

alexxiecan commented 1 year ago

Sorry, Jane. I haven't used Pycox for half a year, but I vaguely remember a modification in an official SDK location. Please take a look at the error information and I'll give you a screenshot for reference,that may help you.

---Original--- From: @.> Date: Wed, Aug 30, 2023 12:44 PM To: @.>; Cc: "Can @.**@.>; Subject: Re: [havakv/pycox] AttributeError: 'Series' object has no attribute'is_monotonic' (Issue #162)

Hi Can,

I wanted to let you know that I was just able to run the EvalSurv after upgrading pandas and pycox.

Thanks again for your help! Jane From: Jing Wang @.> Sent: Tuesday, August 29, 2023 10:30 PM To: havakv/pycox @.>; havakv/pycox @.> Cc: Comment @.> Subject: RE: [havakv/pycox] AttributeError: 'Series' object has no attribute 'is_monotonic' (Issue #162)

Hi Can,

Thank you so much for your reply. I appreciate you taking your valuable time to help me. I followed your instruction by changing the line “assert pd.Series(self.index_surv).is_monotonic” to “assert pd.Series.is_monotonic_increasing” in the eval_surv.py file. However, I still encountered the same error.

The example that I am using is the pycox dataset “metabric”. The pythyon syntax has been posted at this link: https://github.com/havakv/pycox/blob/master/examples/cox-ph.ipynb . I am able to run all lines except “ev = EvalSurv(surv, durations_test, events_test, censor_surv='km')” . I have attached the eval_surv.py file, and would appreciate it very much if you could please review it and advise me.

Thank you, sincerely, Jane

From: Can Xie @.**@.>> Sent: Tuesday, August 29, 2023 4:43 AM To: havakv/pycox @.**@.>> Cc: Jing Wang @.**@.>>; Comment @.**@.>> Subject: Re: [havakv/pycox] AttributeError: 'Series' object has no attribute 'is_monotonic' (Issue #162)

Changed&nbsp;pd.Series.is_monotonic&nbsp;to&nbsp;pd.Series.is_monotonic_increasing&nbsp;for newer versions of pandas. &nbsp;

谢灿 @.<mailto:@.>

&nbsp;

------------------&nbsp;原始邮件&nbsp;------------------ 发件人: @.&gt<mailto:@.&gt>;; 发送时间: 2023年8月29日(星期二) 中午1:20 收件人: @.&gt<mailto:@.&gt>;; 抄送: @.&gt<mailto:@.&gt>;; @.&gt<mailto:@.&gt>;; 主题: Re: [havakv/pycox] AttributeError: &#39;Series&#39; object has no attribute &#39;is_monotonic&#39; (Issue #162)

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!

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.&gt<mailto:@.&gt>;

— Reply to this email directly, view it on GitHub<https://github.com/havakv/pycox/issues/162#issuecomment-1697194057&gt;, or unsubscribe<https://github.com/notifications/unsubscribe-auth/BCGNGDQ7CHWBRU4TWZSWBNDXXXBR7ANCNFSM6AAAAAAXUNTZ4Q&gt;. You are receiving this because you commented.Message ID: @.**@.>>

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

alexxiecan commented 1 year ago

It doesn't seem like this position is correct. You have already made the changes, and I am recalling it😓😓

---Original--- From: @.> Date: Wed, Aug 30, 2023 12:44 PM To: @.>; Cc: "Can @.**@.>; Subject: Re: [havakv/pycox] AttributeError: 'Series' object has no attribute'is_monotonic' (Issue #162)

Hi Can,

I wanted to let you know that I was just able to run the EvalSurv after upgrading pandas and pycox.

Thanks again for your help! Jane From: Jing Wang @.> Sent: Tuesday, August 29, 2023 10:30 PM To: havakv/pycox @.>; havakv/pycox @.> Cc: Comment @.> Subject: RE: [havakv/pycox] AttributeError: 'Series' object has no attribute 'is_monotonic' (Issue #162)

Hi Can,

Thank you so much for your reply. I appreciate you taking your valuable time to help me. I followed your instruction by changing the line “assert pd.Series(self.index_surv).is_monotonic” to “assert pd.Series.is_monotonic_increasing” in the eval_surv.py file. However, I still encountered the same error.

The example that I am using is the pycox dataset “metabric”. The pythyon syntax has been posted at this link: https://github.com/havakv/pycox/blob/master/examples/cox-ph.ipynb . I am able to run all lines except “ev = EvalSurv(surv, durations_test, events_test, censor_surv='km')” . I have attached the eval_surv.py file, and would appreciate it very much if you could please review it and advise me.

Thank you, sincerely, Jane

From: Can Xie @.**@.>> Sent: Tuesday, August 29, 2023 4:43 AM To: havakv/pycox @.**@.>> Cc: Jing Wang @.**@.>>; Comment @.**@.>> Subject: Re: [havakv/pycox] AttributeError: 'Series' object has no attribute 'is_monotonic' (Issue #162)

Changed&nbsp;pd.Series.is_monotonic&nbsp;to&nbsp;pd.Series.is_monotonic_increasing&nbsp;for newer versions of pandas. &nbsp;

谢灿 @.<mailto:@.>

&nbsp;

------------------&nbsp;原始邮件&nbsp;------------------ 发件人: @.&gt<mailto:@.&gt>;; 发送时间: 2023年8月29日(星期二) 中午1:20 收件人: @.&gt<mailto:@.&gt>;; 抄送: @.&gt<mailto:@.&gt>;; @.&gt<mailto:@.&gt>;; 主题: Re: [havakv/pycox] AttributeError: &#39;Series&#39; object has no attribute &#39;is_monotonic&#39; (Issue #162)

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!

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.&gt<mailto:@.&gt>;

— Reply to this email directly, view it on GitHub<https://github.com/havakv/pycox/issues/162#issuecomment-1697194057&gt;, or unsubscribe<https://github.com/notifications/unsubscribe-auth/BCGNGDQ7CHWBRU4TWZSWBNDXXXBR7ANCNFSM6AAAAAAXUNTZ4Q&gt;. You are receiving this because you commented.Message ID: @.**@.>>

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

jjww2023 commented 1 year ago

No worries, Can. I was able to run the syntax with no error after I made your suggested change in the evaluation file. Thank you for helping me!

Have a great day! Jane

From: Can Xie @.> Sent: Tuesday, August 29, 2023 11:36 PM To: havakv/pycox @.> Cc: Jing Wang @.>; Comment @.> Subject: Re: [havakv/pycox] AttributeError: 'Series' object has no attribute 'is_monotonic' (Issue #162)

It doesn't seem like this position is correct. You have already made the changes, and I am recalling it😓😓

---Original--- From: @.&gt<mailto:@.&gt>; Date: Wed, Aug 30, 2023 12:44 PM To: @.&gt<mailto:@.&gt>;; Cc: "Can @.**@.&gtmailto:***@***.******@***.***&gt;; Subject: Re: [havakv/pycox] AttributeError: 'Series' object has no attribute'is_monotonic' (Issue #162)

Hi Can,

I wanted to let you know that I was just able to run the EvalSurv after upgrading pandas and pycox.

Thanks again for your help! Jane From: Jing Wang @.&gt<mailto:@.&gt>; Sent: Tuesday, August 29, 2023 10:30 PM To: havakv/pycox @.&gt<mailto:@.&gt>;; havakv/pycox @.&gt<mailto:@.&gt>; Cc: Comment @.&gt<mailto:@.&gt>; Subject: RE: [havakv/pycox] AttributeError: 'Series' object has no attribute 'is_monotonic' (Issue #162)

Hi Can,

Thank you so much for your reply. I appreciate you taking your valuable time to help me. I followed your instruction by changing the line “assert pd.Series(self.index_surv).is_monotonic” to “assert pd.Series.is_monotonic_increasing” in the eval_surv.py file. However, I still encountered the same error.

The example that I am using is the pycox dataset “metabric”. The pythyon syntax has been posted at this link: https://github.com/havakv/pycox/blob/master/examples/cox-ph.ipynb . I am able to run all lines except “ev = EvalSurv(surv, durations_test, events_test, censor_surv='km')” . I have attached the eval_surv.py file, and would appreciate it very much if you could please review it and advise me.

Thank you, sincerely, Jane

From: Can Xie @.**@.>&gtmailto:***@***.******@***.***&gt;&gt; Sent: Tuesday, August 29, 2023 4:43 AM To: havakv/pycox @.**@.>&gtmailto:***@***.******@***.***&gt;&gt; Cc: Jing Wang @.**@.>&gtmailto:***@***.******@***.***&gt;&gt;; Comment @.**@.>&gtmailto:***@***.******@***.***&gt;&gt; Subject: Re: [havakv/pycox] AttributeError: 'Series' object has no attribute 'is_monotonic' (Issue #162)

Changed&nbsp;pd.Series.is_monotonic&nbsp;to&nbsp;pd.Series.is_monotonic_increasing&nbsp;for newer versions of pandas. &nbsp;

谢灿 @.<mailto:@.&gtmailto:***@***.***%3cmailto:***@***.***&gt;

&nbsp;

------------------&nbsp;原始邮件&nbsp;------------------ 发件人: @.&gt<mailto:@.&gt&gtmailto:***@***.***&amp;gt%3cmailto:***@***.***&amp;gt&gt;;; 发送时间: 2023年8月29日(星期二) 中午1:20 收件人: @.&gt<mailto:@.&gt&gtmailto:***@***.***&amp;gt%3cmailto:***@***.***&amp;gt&gt;;; 抄送: @.&gt<mailto:@.&gt&gtmailto:***@***.***&amp;gt%3cmailto:***@***.***&amp;gt&gt;;; @.&gt<mailto:@.&gt&gtmailto:***@***.***&amp;gt%3cmailto:***@***.***&amp;gt&gt;;; 主题: Re: [havakv/pycox] AttributeError: &#39;Series&#39; object has no attribute &#39;is_monotonic&#39; (Issue #162)

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!

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.&gt<mailto:@.&gt&gtmailto:***@***.***&amp;gt%3cmailto:***@***.***&amp;gt&gt;;

— Reply to this email directly, view it on GitHub<https://github.com/havakv/pycox/issues/162#issuecomment-1697194057&gt;, or unsubscribe<https://github.com/notifications/unsubscribe-auth/BCGNGDQ7CHWBRU4TWZSWBNDXXXBR7ANCNFSM6AAAAAAXUNTZ4Q&gt;. You are receiving this because you commented.Message ID: @.**@.>>

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

— Reply to this email directly, view it on GitHubhttps://github.com/havakv/pycox/issues/162#issuecomment-1698521713, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BCGNGDURQ6BTQXYRCHSPQ4LXX3GL5ANCNFSM6AAAAAAXUNTZ4Q. You are receiving this because you commented.Message ID: @.**@.>>

xytd20 commented 1 year ago

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

jjww2023 commented 1 year ago

I got it to work after upgrading pycox and pandas. Try it. Hope it works for you.

From: xytd20 @.> Sent: Wednesday, August 30, 2023 9:45 AM To: havakv/pycox @.> Cc: Jing Wang @.>; Comment @.> Subject: Re: [havakv/pycox] AttributeError: 'Series' object has no attribute 'is_monotonic' (Issue #162)

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

— Reply to this email directly, view it on GitHubhttps://github.com/havakv/pycox/issues/162#issuecomment-1699426103, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BCGNGDQQFGYOAS6EQLNXINLXX5NZTANCNFSM6AAAAAAXUNTZ4Q. You are receiving this because you commented.Message ID: @.**@.>>

qaisqasaimeh commented 1 year ago

Could you please elaborate more on this issue?

amir78pgd commented 8 months ago

to what version of pandas and pycox did u upgrade ?

chengzhishi commented 8 months ago

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 commented 2 months ago

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 commented 3 weeks ago

fixed with PR #180, many thanks to @havakv