def test__find_parent_id_all_good(self, choice_mock): """If all are good, use the likelihoods unmodified.""" likelihoods = pd.Series([0.5, 1, 1.5, 2]) num_rows = pd.Series([1, 2, 3, 4]) Sampler._find_parent_id(likelihoods, num_rows) expected_weights = np.array([0.5 / 5, 1 / 5, 1.5 / 5, 2 / 5]) assert choice_mock.call_count == 1 assert list(choice_mock.call_args[0][0]) == list(likelihoods.index) np.testing.assert_array_equal(choice_mock.call_args[1]['p'], expected_weights)
def test__find_parent_id_all_0_or_singlar_matrix(self, choice_mock): """If likehoods are either 0 or NaN, fill the gaps with num_rows.""" likelihoods = pd.Series([0, None, 0, None]) num_rows = pd.Series([1, 2, 3, 4]) Sampler._find_parent_id(likelihoods, num_rows) expected_weights = np.array([0, 2 / 6, 0, 4 / 6]) assert choice_mock.call_count == 1 assert list(choice_mock.call_args[0][0]) == list(likelihoods.index) np.testing.assert_array_equal(choice_mock.call_args[1]['p'], expected_weights)
def test__find_parent_id_some_good(self, choice_mock): """If some likehoods are good, fill the gaps with num_rows.""" likelihoods = pd.Series([0.5, None, 1.5, None]) num_rows = pd.Series([1, 2, 3, 4]) Sampler._find_parent_id(likelihoods, num_rows) expected_weights = np.array([0.5 / 4, 1 / 4, 1.5 / 4, 1 / 4]) assert choice_mock.call_count == 1 assert list(choice_mock.call_args[0][0]) == list(likelihoods.index) np.testing.assert_array_equal(choice_mock.call_args[1]['p'], expected_weights)
def test__find_parent_id_all_singlar_matrix(self, choice_mock): """If all likelihoods got singular matrix, use num_rows.""" likelihoods = pd.Series([None, None, None, None]) num_rows = pd.Series([1, 2, 3, 4]) Sampler._find_parent_id(likelihoods, num_rows) expected_weights = np.array([1 / 10, 2 / 10, 3 / 10, 4 / 10]) assert choice_mock.call_count == 1 assert list(choice_mock.call_args[0][0]) == list(likelihoods.index) np.testing.assert_array_equal(choice_mock.call_args[1]['p'], expected_weights)