Skip to content

Commit

Permalink
test, fix: annotated/commented new fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
jspaezp committed Dec 8, 2024
1 parent b02567a commit b06b01e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def psm_df_1000_parquet(tmp_path):
@pytest.fixture
def psms_dataset(psm_df_1000) -> LinearPsmDataset:
"""A small LinearPsmDataset"""
data = _psm_df_rand(500, 500)
data = _psm_df_rand(500, 500, share_ids=True)

psms = LinearPsmDataset(
psms=data.df,
Expand Down
18 changes: 15 additions & 3 deletions tests/system_tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pathlib import Path

import pandas as pd
import numpy as np
import pytest

from ..helpers.cli import run_mokapot_cli
Expand Down Expand Up @@ -221,7 +222,9 @@ def make_pin_file(filename, desc, seed=None):
df.drop(columns=score_cols + ["target"], inplace=True)
df["Label"] = targets * 1 # Q: what does the *1 do ?
df["feat"] = scores * (1 if desc else -1)
df["scannr"] = np.random.randint(0, 1000, 1000)

# Why is this re-shuffled?
# df["scannr"] = np.random.randint(0, 1000, 1000)
file = tmp_path / filename
df.to_csv(file, sep="\t", index=False)
return file, df
Expand Down Expand Up @@ -280,8 +283,17 @@ def mean_score(file):
# Let's check now that the score columns are indeed equal to the
# normal/negated feature column

feature_col1 = df1b[df1b.Label == 1].sort_values(by="specid").feat
score_col1 = psms_df1b.sort_values(by="PSMId").score
# Q: isnt the right behavior to have the scaled version of the data
# instead of just the negated feature??
sorted_df1b = df1b[df1b.Label == 1].sort_values(by="specid")
feature_col1 = sorted_df1b.feat
sorted_psms_df1b= psms_df1b.sort_values(by="PSMId")
score_col1 = sorted_psms_df1b.score
np.testing.assert_equal(
# Note, stable was introduced in v2.0.0
np.argsort(feature_col1.to_numpy()), # , stable=True),
np.argsort(score_col1.to_numpy()) # , stable=True)
)
pd.testing.assert_series_equal(
score_col1, feature_col1, check_index=False, check_names=False
)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def test_model_predict(psms_dataset):

# The case where a model is trained on a dataset with different features:
psms_dataset._data["blah"] = np.random.randn(len(psms_dataset))
psms_dataset._feature_columns = ("score", "blah")
psms_dataset._feature_columns = ("score0", "blah")
with pytest.raises(ValueError):
model.predict(psms_dataset)

Expand Down

0 comments on commit b06b01e

Please sign in to comment.