Skip to content

Commit

Permalink
Merge pull request #467 from jlitzingerdev/449-feature-avail-failing
Browse files Browse the repository at this point in the history
Fix failing tests to to column not being datetime.
  • Loading branch information
levithatcher committed Feb 1, 2018
2 parents 4e415b7 + ea96105 commit 8aaf1f7
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions healthcareai/tests/test_feature_availability_profiler.py
Expand Up @@ -7,19 +7,37 @@
from healthcareai.common.healthcareai_error import HealthcareAIError


def random_datetimes(start, end, ntimes):
"""Generate a fixed number of random timestamps between two dates.
:param start: Starting timestamp
:type start: datetime.datetime
:param end: Ending timestamp
:type end: datetime.datetime
:param ntimes: Number of timestamps
:type ntimes: int
"""
delta = end - start
int_delta = int(delta.total_seconds())
return [start + timedelta(seconds=randrange(int_delta))
for _ in range(ntimes)]


class TestFeatureAvailabilityProfiler(unittest.TestCase):
def setUp(self):
self.df = pd.DataFrame(np.random.randn(1000, 4),
columns=['A', 'B', 'AdmitDTS', 'LastLoadDTS'])
# generate load date
self.df['LastLoadDTS'] = pd.datetime(2015, 5, 20)
# generate datetime objects for admit date
admit = pd.Series(1000)
delta = pd.datetime(2015, 5, 20) - pd.datetime(2015, 5, 1)
int_delta = (delta.days * 24 * 60 * 60) + delta.seconds
for i in range(1000):
random_second = randrange(int_delta)
admit[i] = pd.datetime(2015, 5, 1) + timedelta(seconds=random_second)
admit = random_datetimes(
pd.datetime(2015, 5, 1),
pd.datetime(2015, 5, 20),
1000
)
self.df['AdmitDTS'] = admit
# add nulls
a = np.random.rand(1000) > .5
Expand Down Expand Up @@ -84,13 +102,11 @@ def setUp(self):
# generate load date
self.df['LastLoadDTS'] = pd.datetime(2015, 5, 20)
# generate datetime objects for admit date
admit = pd.Series(1000)
delta = pd.datetime(2015, 5, 20) - pd.datetime(2015, 5, 1)
int_delta = (delta.days * 24 * 60 * 60) + delta.seconds
for i in range(1000):
random_second = randrange(int_delta)
admit[i] = pd.datetime(2015, 5, 1) + timedelta(
seconds=random_second)
admit = random_datetimes(
pd.datetime(2015, 5, 1),
pd.datetime(2015, 5, 20),
1000
)
self.df['AdmitDTS'] = admit

def runTest(self):
Expand Down

0 comments on commit 8aaf1f7

Please sign in to comment.