Docking_project / tests /test_missing_features.py
QPromaQ's picture
Add files using upload-large-folder tool
68a8d25 verified
Raw History Blame
1.34 kB
from __future__ import annotations
import unittest
import numpy as np
from libs.adaptive.features import FeatureBundle, FeatureValue, bundles_to_wide_frames
class TestMissingFeatures(unittest.TestCase):
def test_missing_features_are_masked_and_not_silent_zero(self) -> None:
b1 = FeatureBundle(
object_id="lig_1",
features={
"f_present": FeatureValue(value=1.5, available=True, source="test", feature_type="exact"),
"f_missing": FeatureValue(value=None, available=False, source="test", feature_type="proxy"),
},
)
b2 = FeatureBundle(
object_id="lig_2",
features={
"f_present": FeatureValue(value=2.5, available=True, source="test", feature_type="exact"),
"f_missing": FeatureValue(value=3.0, available=True, source="test", feature_type="proxy"),
},
)
values, masks, names = bundles_to_wide_frames([b1, b2])
self.assertIn("f_missing", names)
lig1 = values.loc[values["ligand_id"] == "lig_1"].iloc[0]
lig1_mask = masks.loc[masks["ligand_id"] == "lig_1"].iloc[0]
self.assertTrue(np.isnan(float(lig1["f_missing"])))
self.assertEqual(int(lig1_mask["mask_f_missing"]), 0)
if __name__ == "__main__":
unittest.main()