-
Notifications
You must be signed in to change notification settings - Fork 3
pp test expansion
#232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vbrennsteiner
wants to merge
3
commits into
main
Choose a base branch
from
pp_test_expansion
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
pp test expansion
#232
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,3 +102,57 @@ def test_scanpy_pycombat( | |
| assert result is None | ||
|
|
||
| pd.testing.assert_frame_equal(adata.to_df(layer=layer), expected_adata.to_df()) | ||
|
|
||
|
|
||
| def test_scanpy_pycombat_layer_none(pycombat_test_data_simple): | ||
| """When layer=None, the corrected matrix is written back to adata.X (not a layer).""" | ||
| df, md = pycombat_test_data_simple | ||
| adata = ad.AnnData(df, obs=md) | ||
| X_before = adata.X.copy() | ||
|
|
||
| result = scanpy_pycombat(adata, batch="batch", layer=None) | ||
|
|
||
| # in-place modification on the local `adata` rebound in the function — returns None | ||
| assert result is None | ||
| # caller's adata.X was modified before the rebind (astype on line 184), and copy=False | ||
| # path still mutates the caller's X via line 212 when no NaN-coerce is needed | ||
| assert not np.array_equal(adata.X, X_before) | ||
|
|
||
|
|
||
| def test_scanpy_pycombat_coerces_nan_batches(): | ||
| """NaN values in the batch column should be coerced to an 'NA' batch.""" | ||
| df = pd.DataFrame( | ||
| {"A": [1.0, 2.0, 4.0, 8.0, 16.0, 32.0], "B": [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]}, | ||
| index=list("ABCDEF"), | ||
| ) | ||
| md = pd.DataFrame({"batch": ["x", "x", "x", np.nan, np.nan, np.nan]}, index=list("ABCDEF")) | ||
| adata = ad.AnnData(df, obs=md) | ||
|
|
||
| result = scanpy_pycombat(adata, batch="batch", copy=True) | ||
|
|
||
| assert "NA" in result.obs["batch"].tolist() | ||
| assert not result.obs["batch"].isna().any() | ||
|
Comment on lines
+133
to
+134
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we test for the full result here? |
||
|
|
||
|
|
||
| def test_scanpy_pycombat_raises_on_nan_data(pycombat_test_data_simple): | ||
| """If adata.X contains NaNs, scanpy_pycombat raises ValueError.""" | ||
| df, md = pycombat_test_data_simple | ||
| df_with_nan = df.copy() | ||
| df_with_nan.iloc[0, 0] = np.nan | ||
| adata = ad.AnnData(df_with_nan, obs=md) | ||
|
|
||
| with pytest.raises(ValueError, match="contains NaN"): | ||
| scanpy_pycombat(adata, batch="batch") | ||
|
|
||
|
|
||
| def test_scanpy_pycombat_raises_on_singleton_batch(): | ||
| """If a batch contains only one sample, scanpy_pycombat raises ValueError.""" | ||
| df = pd.DataFrame( | ||
| {"A": [1.0, 2.0, 3.0, 4.0, 5.0], "B": [1.0, 2.0, 3.0, 4.0, 5.0]}, | ||
| index=list("ABCDE"), | ||
| ) | ||
| md = pd.DataFrame({"batch": ["x", "x", "y", "y", "z"]}, index=list("ABCDE")) # z is singleton | ||
| adata = ad.AnnData(df, obs=md) | ||
|
|
||
| with pytest.raises(ValueError, match="only one single sample"): | ||
| scanpy_pycombat(adata, batch="batch") | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why no cover by tests? (for the above
raise) statements it might be fine to not cover them, this is a functional piece of logic)