@@ -322,5 +322,37 @@ def test_scale_by_heavyatomcount_raises_runtimeerror_when_cannot_infer_heavy_ato
322322 with pytest .raises (RuntimeError , match = r"Could not infer heavy atom column" ):
323323 obj .scale_by_heavyatomcount_and_log_scale (df , descr_type = "demo" )
324324
325+ def test_scale_by_heavyatomcount_and_log_scale_raises_on_negative_log_feature (monkeypatch ):
326+ params = param_parser .wrapper ({
327+ "dataset_key" : "fake.csv" ,
328+ "featurizer" : "compouted_descriptors" ,
329+ "descriptor_type" : "rdkit_raw" ,})
330+ obj = feat .ComputedDescriptorFeaturization (params )
331+
332+ # No "HeavyAtomCount" or "nHeavyAtom" in descr_cols, and we do not pass heavy_atom_col
333+ monkeypatch .setattr (
334+ obj .__class__ ,
335+ "desc_type_cols" ,
336+ {"test_type" : ["SomeFeature_log_scaled" , "HeavyAtomCount" ]},
337+ raising = False ,
338+ )
339+
340+ # Build a DataFrame where:
341+ # - HeavyAtomCount is present so the function can infer heavy atom counts
342+ # - SomeFeature has a negative value, and desc_type_cols includes SomeFeature_log_scaled
343+ df = pd .DataFrame ({
344+ "HeavyAtomCount" : [10 , 12 ],
345+ "SomeFeature" : [- 1.0 , 2.0 ] # negative value triggers ValueError in log scaling
346+ })
347+
348+ with pytest .raises (ValueError ) as excinfo :
349+ obj .scale_by_heavyatomcount_and_log_scale (
350+ desc_df = df ,
351+ descr_type = "test_type" # uses desc_type_cols defined above
352+ )
353+
354+ # Optionally check the error message
355+ assert "Cannot log scale SomeFeature" in str (excinfo .value )
356+
325357if __name__ == '__main__' :
326358 test_compute_moe ()
0 commit comments