Skip to content

(fix): sc.read with extension does not warn unnecessarily #3643

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

Merged
merged 6 commits into from
May 28, 2025

Conversation

ilan-gold
Copy link
Contributor

  • Release notes not necessary because:

@ilan-gold ilan-gold added this to the 1.11.2 milestone May 23, 2025
Copy link

codecov bot commented May 23, 2025

❌ 2 Tests Failed:

Tests completed Failed Passed Skipped
2131 2 2129 98
View the top 2 failed test(s) by shortest run time
tests/test_preprocessing.py::test_scale_zero_center_warns_dask_sparse[dask_array_sparse]
Stack Traces | 0.059s run time
array_type = <function as_sparse_dask_array at 0x7f902d3a60c0>

    @pytest.mark.parametrize("array_type", ARRAY_TYPES_SPARSE)
    def test_scale_zero_center_warns_dask_sparse(array_type):
        adata = pbmc68k_reduced()
        adata.X = adata.raw.X
        adata_casted = adata.copy()
        adata_casted.X = array_type(adata_casted.raw.X)
        with pytest.warns(UserWarning, match="zero-center.*sparse"):
            sc.pp.scale(adata_casted)
        sc.pp.scale(adata)
>       assert_allclose(adata_casted.X, adata.X, rtol=1e-5, atol=1e-5)
#x1B[1m#x1B[31mE       AssertionError: #x1B[0m
#x1B[1m#x1B[31mE       Not equal to tolerance rtol=1e-05, atol=1e-05#x1B[0m
#x1B[1m#x1B[31mE       #x1B[0m
#x1B[1m#x1B[31mE       Mismatched elements: 5581 / 535500 (1.04%)#x1B[0m
#x1B[1m#x1B[31mE       Max absolute difference among violations: 0.01053696#x1B[0m
#x1B[1m#x1B[31mE       Max relative difference among violations: 2.85978674#x1B[0m
#x1B[1m#x1B[31mE        ACTUAL: array([[-0.399906, -0.200817, -0.855342, ..., -0.258421, -0.684061,#x1B[0m
#x1B[1m#x1B[31mE                2.79155 ],#x1B[0m
#x1B[1m#x1B[31mE              [ 1.980319, -0.200817,  1.067341, ..., -0.258421,  2.087584,...#x1B[0m
#x1B[1m#x1B[31mE        DESIRED: array([[-0.399906, -0.200817, -0.86101 , ..., -0.258421, -0.684061,#x1B[0m
#x1B[1m#x1B[31mE                2.79155 ],#x1B[0m
#x1B[1m#x1B[31mE              [ 1.980319, -0.200817,  1.067071, ..., -0.258421,  2.087584,...#x1B[0m

#x1B[1m#x1B[31mtests/test_preprocessing.py#x1B[0m:287: AssertionError
tests/test_highly_variable_genes.py::test_compare_to_upstream[dask_array_sparse-seurat-fgd]
Stack Traces | 0.069s run time
@pytest.mark.parametrize("func", ["hvg", "fgd"])
    @pytest.mark.parametrize(
        ("flavor", "params", "ref_path"),
        [
            pytest.param(
                "seurat", dict(min_mean=0.0125, max_mean=3, min_disp=0.5), FILE, id="seurat"
            ),
            pytest.param(
                "cell_ranger", dict(n_top_genes=100), FILE_CELL_RANGER, id="cell_ranger"
            ),
        ],
    )
    @pytest.mark.parametrize("array_type", ARRAY_TYPES)
    def test_compare_to_upstream(
        *,
        request: pytest.FixtureRequest,
        func: Literal["hvg", "fgd"],
        flavor: Literal["seurat", "cell_ranger"],
        params: dict[str, float | int],
        ref_path: Path,
        array_type: Callable,
    ):
        if func == "fgd" and flavor == "cell_ranger":
            reason = "The deprecated filter_genes_dispersion behaves differently with cell_ranger"
            request.applymarker(pytest.mark.xfail(reason=reason))
        hvg_info = pd.read_csv(ref_path)
    
        pbmc = pbmc68k_reduced()
        pbmc.X = pbmc.raw.X
        pbmc.X = array_type(pbmc.X)
        pbmc.var_names_make_unique()
        sc.pp.filter_cells(pbmc, min_counts=1)
        sc.pp.normalize_total(pbmc, target_sum=1e4)
    
        if func == "hvg":
            sc.pp.log1p(pbmc)
            sc.pp.highly_variable_genes(pbmc, flavor=flavor, **params, inplace=True)
        elif func == "fgd":
            sc.pp.filter_genes_dispersion(
                pbmc, flavor=flavor, **params, log=True, subset=False
            )
        else:
            raise AssertionError()
    
        np.testing.assert_array_equal(
            hvg_info["highly_variable"], pbmc.var["highly_variable"]
        )
    
        # (still) Not equal to tolerance rtol=2e-05, atol=2e-05
        # np.testing.assert_allclose(4, 3.9999, rtol=2e-05, atol=2e-05)
>       np.testing.assert_allclose(
            hvg_info["means"],
            pbmc.var["means"],
            rtol=2e-05,
            atol=2e-05,
        )
#x1B[1m#x1B[31mE       AssertionError: #x1B[0m
#x1B[1m#x1B[31mE       Not equal to tolerance rtol=2e-05, atol=2e-05#x1B[0m
#x1B[1m#x1B[31mE       #x1B[0m
#x1B[1m#x1B[31mE       Mismatched elements: 42 / 765 (5.49%)#x1B[0m
#x1B[1m#x1B[31mE       Max absolute difference among violations: 0.01178531#x1B[0m
#x1B[1m#x1B[31mE       Max relative difference among violations: 0.00858193#x1B[0m
#x1B[1m#x1B[31mE        ACTUAL: array([1.88077 , 0.862207, 2.789555, 3.51563 , 0.779662, 2.495507,#x1B[0m
#x1B[1m#x1B[31mE              2.051983, 2.200089, 2.121406, 2.272991, 2.340023, 2.030907,#x1B[0m
#x1B[1m#x1B[31mE              2.267801, 1.565244, 2.465999, 0.676449, 2.246484, 3.938324,...#x1B[0m
#x1B[1m#x1B[31mE        DESIRED: array([1.88077 , 0.862207, 2.789555, 3.515629, 0.779662, 2.495507,#x1B[0m
#x1B[1m#x1B[31mE              2.051983, 2.200089, 2.121406, 2.272991, 2.340023, 2.030907,#x1B[0m
#x1B[1m#x1B[31mE              2.267801, 1.565244, 2.465999, 0.676449, 2.246485, 3.938324,...#x1B[0m

#x1B[1m#x1B[31mtests/test_highly_variable_genes.py#x1B[0m:406: AssertionError

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

Copy link

codecov bot commented May 23, 2025

Codecov Report

Attention: Patch coverage is 88.88889% with 2 lines in your changes missing coverage. Please review.

Project coverage is 76.14%. Comparing base (82adc79) to head (f718bad).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/scanpy/readwrite.py 88.88% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3643   +/-   ##
=======================================
  Coverage   76.13%   76.14%           
=======================================
  Files         114      114           
  Lines       12736    12741    +5     
=======================================
+ Hits         9697     9702    +5     
  Misses       3039     3039           
Files with missing lines Coverage Δ
src/scanpy/readwrite.py 77.55% <88.88%> (+0.24%) ⬆️

@ilan-gold ilan-gold enabled auto-merge (squash) May 28, 2025 08:28
@ilan-gold ilan-gold merged commit 350c342 into main May 28, 2025
13 of 14 checks passed
@ilan-gold ilan-gold deleted the ig/read_ext_error branch May 28, 2025 10:36
Copy link

lumberbot-app bot commented May 28, 2025

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout 1.11.x
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 350c3424d2f96c4a3a7bb3b7d0428d38d842ebe8
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #3643: (fix): `sc.read` with extension does not warn unnecessarily'
  1. Push to a named branch:
git push YOURFORK 1.11.x:auto-backport-of-pr-3643-on-1.11.x
  1. Create a PR against branch 1.11.x, I would have named this PR:

"Backport PR #3643 on branch 1.11.x ((fix): sc.read with extension does not warn unnecessarily)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the Still Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free to suggest an improvement.

ilan-gold added a commit that referenced this pull request May 28, 2025
* (fix): `sc.read` with extension does not warn unnecessarily

* (fix): obey `return_ext`

* (fix): add extension check internally

* (chore): relnote

(cherry picked from commit 350c342)
ilan-gold added a commit that referenced this pull request May 28, 2025
…3661)

* (fix): `sc.read` with extension does not warn unnecessarily

* (fix): obey `return_ext`

* (fix): add extension check internally

* (chore): relnote

(cherry picked from commit 350c342)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

irrelevant warning in sc.read
2 participants