Skip to content

Commit

Permalink
fixes #17: heroku deployment issue caused by empty database
Browse files Browse the repository at this point in the history
  • Loading branch information
mukeshmk committed Jul 20, 2020
1 parent 78398de commit 8f3e2b9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/fmlearn.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import math
from datetime import datetime
import pandas as pd
from sklearn.model_selection import train_test_split
Expand Down Expand Up @@ -52,6 +53,11 @@ def load_data(self):

# loads data from the SQL database and pre-processes the data.
self._df = utils.get_df_from_db()

# fail safe to load data later when the database is empty
if self._df.empty:
self._new_recs = math.inf
return
self._shape = self._df.shape

# replacing NA values in the dataframe with -1
Expand All @@ -67,6 +73,10 @@ def load_data(self):
self._encoders[utils.DATASET_HASH] = ds_hash_encoder

def train(self):
# fail safe to train model later when the database is empty
if self._new_recs == math.inf:
return

# throws error if the data is not loaded before training.
if self._X is None:
raise RuntimeError('data not loaded! \n`call function `load_data()` before train()')
Expand Down

0 comments on commit 8f3e2b9

Please sign in to comment.