Skip to content

Commit

Permalink
Merge pull request #7 from maxfarago/master
Browse files Browse the repository at this point in the history
Fixed empty design matrices error
  • Loading branch information
davidwarshaw authored Mar 20, 2017
2 parents 25fd3cc + eba165e commit 32d3f95
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion hmc/hmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, root):

def _get_parent(self, child):
# Return the parent of this node
return self.nodes[child] if child != self.root else self.root
return self.nodes[child] if (child in self.nodes and child != self.root) else self.root

def _get_children(self, parent):
# Return a list of children nodes in alpha order
Expand Down Expand Up @@ -215,6 +215,9 @@ def _predict_stages(self, X):
else:
y_hat[stage['stage']] = y_hat[self.stages[stage_number - 1]['stage']]
dm = X[y_hat[stage['stage']].isin([stage['stage']])]
# Skip empty matrices
if dm.empty:
continue
# combine_first reorders DataFrames, so we have to do this the ugly way
y_hat_stage = pd.DataFrame(stage['tree'].predict(dm), index=dm.index)
y_hat = y_hat.assign(stage_col=y_hat_stage)
Expand Down

0 comments on commit 32d3f95

Please sign in to comment.