Skip to content

Commit

Permalink
Refactor tests to allow new featurizer columns to exist as long as ol…
Browse files Browse the repository at this point in the history
…d ones are present
  • Loading branch information
ml-evs committed Mar 29, 2024
1 parent 9c0ccdf commit c2ce382
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions modnet/tests/test_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ def check_column_values(new: MODData, reference: MODData, tolerance=0.03):
Allows for some columns to be checked more loosely (see inline comment below).
"""
new_cols = set(new.df_featurized.columns)
old_cols = set(reference.df_featurized.columns)

# Check that the new df only adds new columns and is not missing anything
assert not (old_cols - new_cols)

error_cols = set()
for col in new.df_featurized.columns:
for col in old_cols:
if not (
np.absolute(
(
Expand Down Expand Up @@ -349,14 +355,6 @@ def test_small_moddata_featurization(small_moddata_2023, featurizer_mode):
featurizer.featurizer_mode = featurizer_mode
new = MODData(structures, targets, target_names=names, featurizer=featurizer)
new.featurize(fast=False, n_jobs=1)

new_cols = sorted(new.df_featurized.columns.tolist())
old_cols = sorted(old.df_featurized.columns.tolist())

for i in range(len(old_cols)):
assert new_cols[i] == old_cols[i]

np.testing.assert_array_equal(old_cols, new_cols)
check_column_values(new, old, tolerance=0.03)


Expand All @@ -376,13 +374,6 @@ def test_small_moddata_composition_featurization(
new = MODData(materials=compositions, featurizer=featurizer)
new.featurize(fast=False, n_jobs=1)

new_cols = sorted(new.df_featurized.columns.tolist())
ref_cols = sorted(reference.df_featurized.columns.tolist())

for i in range(len(ref_cols)):
# print(new_cols[i], ref_cols[i])
assert new_cols[i] == ref_cols[i]

# assert relative error below 3 percent
check_column_values(new, reference, tolerance=0.03)

Expand Down

0 comments on commit c2ce382

Please sign in to comment.