def test_softmax(self, mocker, lineage: Lineage): try: _ = lineage.reduce("foo", "bar", normalize_weights="softmax", mode="dist") except ValueError: pass finally: mocker.assert_called_once()
def test_normal_run_combination_only_1(self, lineage: Lineage): lin = lineage.reduce("foo, bar") assert lin.shape == (10, 1) np.testing.assert_allclose(np.sum(lin, axis=1), 1.0) np.testing.assert_array_equal(lin.names, ["bar or foo"]) np.testing.assert_array_equal(lin.colors, lineage[["foo, bar"]].colors)
def test_row_normalize(self, mocker, lineage: Lineage): try: _ = lineage.reduce("foo", "bar", mode="scale") except ValueError: pass finally: mocker.assert_called_once()
def test_mutual_info(self, mocker, lineage: Lineage): try: _ = lineage.reduce("foo", "bar", dist_measure="mutual_info", mode="dist") except ValueError: pass finally: mocker.assert_called_once()
def test_normal_run(self, lineage: Lineage): lin = lineage.reduce("foo", "bar") assert lin.shape == (10, 2) np.testing.assert_allclose(np.sum(lin, axis=1), 1.0) np.testing.assert_array_equal(lin.names, ["foo", "bar"]) np.testing.assert_array_equal(lin.colors, lineage[["foo", "bar"]].colors)
def test_equal(self, mocker, lineage: Lineage): try: _ = lineage.reduce("foo", "bar", dist_measure="equal", mode="dist") except ValueError: pass finally: # should be twice, but we have extra check inside and we're mocking that does nothing mocker.assert_called_once()
def test_return_weights_mode_dist(self, lineage: Lineage): lin, weights = lineage.reduce("foo", "bar", mode="dist", return_weights=True) assert isinstance(lin, Lineage) assert isinstance(weights, DataFrame)
def test_return_weights_mode_scale(self, lineage: Lineage): lin, weights = lineage.reduce("foo", "bar", mode="scale", return_weights=True) assert isinstance(lin, Lineage) assert weights is None
def test_normal_run_combination_all(self, lineage: Lineage): assert lineage.shape == (10, 4) lin = lineage.reduce("foo, bar", "baz, quux") assert lin.shape == (10, 2) np.testing.assert_allclose(np.sum(lin, axis=1), 1.0) np.testing.assert_array_equal(lin.names, ["bar or foo", "baz or quux"]) np.testing.assert_array_equal( lin.colors, lineage[["foo, bar", "baz or quux"]].colors)
def test_invalid_weight_normalize(self, lineage: Lineage): with pytest.raises(ValueError): lineage.reduce("foo", "bar", normalize_weights="foo")
def test_invalid_dist_measure(self, lineage: Lineage): with pytest.raises(ValueError): lineage.reduce("foo", "bar", dist_measure="foo")
def test_invalid_mode(self, lineage: Lineage): with pytest.raises(ValueError): lineage.reduce("foo", "bar", mode="foo")
def test_all_names(self, lineage: Lineage): lin = lineage.reduce(*lineage.names) np.testing.assert_array_equal(lin.X, lineage.X)
def test_invalid_key(self, lineage: Lineage): with pytest.raises(KeyError): lineage.reduce("non_existent")
def test_not_summing_to_1(self, lineage: Lineage): lineage[0, 0] = 0 with pytest.raises(ValueError): lineage.reduce("foo")
def test_empty_keys(self, lineage: Lineage): with pytest.raises(ValueError): lineage.reduce()