Skip to content

Commit

Permalink
Warning kaplan meier negative durations (#40)
Browse files Browse the repository at this point in the history
* Add warning if use of negatve duartion in kaplan_meier

* Bump version: 0.2.1 → 0.2.2

Co-authored-by: havakv <haavard.kvamme@gmail..com>
  • Loading branch information
havakv and havakv committed Jul 5, 2020
1 parent 608ea31 commit 67d213b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pycox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

__author__ = """Haavard Kvamme"""
__email__ = 'haavard.kvamme@gmail.com'
__version__ = '0.2.1'
__version__ = '0.2.2'

import pycox.datasets
import pycox.evaluation
Expand Down
6 changes: 5 additions & 1 deletion pycox/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
import pandas as pd
import numpy as np
import numba
Expand Down Expand Up @@ -52,6 +53,9 @@ def kaplan_meier(durations, events, start_duration=0):
"""
n = len(durations)
assert n == len(events)
if start_duration > durations.min():
warnings.warn(f"start_duration {start_duration} is larger than minimum duration {durations.min()}. "
"If intentional, consider changing start_duration when calling kaplan_meier.")
order = np.argsort(durations)
durations = durations[order]
events = events[order]
Expand All @@ -72,7 +76,7 @@ def kaplan_meier(durations, events, start_duration=0):
surv[i:] = 0.
else:
surv = np.exp(np.log(1 - di / ni).cumsum())
if start_duration != surv_idx.min():
if start_duration < surv_idx.min():
tmp = np.ones(len(surv)+ 1, dtype=surv.dtype)
tmp[1:] = surv
surv = tmp
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.2.1
current_version = 0.2.2
commit = True
tag = False

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

setup(
name='pycox',
version='0.2.1',
version='0.2.2',
description="Survival analysis with PyTorch",
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down

0 comments on commit 67d213b

Please sign in to comment.