Skip to content

Commit

Permalink
Avoid crash when updating likelihoods of empty Results
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremykubica committed Dec 12, 2024
1 parent d5d9a1f commit 04c07ce
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/kbmod/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,15 @@ def _update_likelihood(self):
------
Raises an IndexError if the necessary columns are missing.
"""
num_rows = len(self.table)
if num_rows == 0:
return # Nothing to do for an empty table

if "psi_curve" not in self.table.colnames:
raise IndexError("Missing column 'phi_curve'. Use add_psi_phi_data()")
if "phi_curve" not in self.table.colnames:
raise IndexError("Missing column 'phi_curve'. Use add_psi_phi_data()")

num_rows = len(self.table)
num_times = len(self.table["phi_curve"][0])
if "obs_valid" in self.table.colnames:
phi_sum = (self.table["phi_curve"] * self.table["obs_valid"]).sum(axis=1)
Expand Down
3 changes: 3 additions & 0 deletions tests/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def test_empty(self):
self.assertEqual(len(table.colnames), 7)
self.assertEqual(table.get_num_times(), 0)

# Check that we don't crash on updating the likelihoods.
table._update_likelihood()

def test_from_trajectories(self):
table = Results.from_trajectories(self.trj_list)
self.assertEqual(len(table), self.num_entries)
Expand Down

0 comments on commit 04c07ce

Please sign in to comment.