-
Notifications
You must be signed in to change notification settings - Fork 646
Add replace option to subsample and rename function to sample #943
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
Changes from 37 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
bf922e1
Add replace option to subsample.
gokceneraslan 32baba1
Merge branch 'master' into withreplacement
gokceneraslan 671ec71
Add sc.pp.sample with axis argument.
gokceneraslan 9e0739b
Fix fraction doc
gokceneraslan 8ec8cf3
Add to release notes
gokceneraslan cdf4c65
Merge branch 'main' into withreplacement
flying-sheep fdf524a
refactor
flying-sheep 061a19d
Refactor tests
flying-sheep 8528f2d
Merge branch 'main' into withreplacement
flying-sheep 06d4280
handle array case in test
flying-sheep 6eeab2e
Test errors
flying-sheep b1f5061
prettier deprecations
flying-sheep cec8aff
docs
flying-sheep daa147e
ignore dask warning correctly
flying-sheep 3c31abd
sig exception
flying-sheep d350411
WIP
flying-sheep f02725a
Merge branch 'main' into withreplacement
flying-sheep c24e9b2
remove duplicate _LegacyRandom
flying-sheep e246f02
undo compat thing
flying-sheep 4ad40b7
fix backwards compat
flying-sheep 1b8c81e
Use fake Generator
flying-sheep 594d961
backwards compat test
flying-sheep 00fdd77
Merge branch 'main' into withreplacement
flying-sheep 59a171c
Fix tests for old Pythons
flying-sheep 59adc76
test that random state is modified
flying-sheep ef27db0
Fix util
flying-sheep c471e94
types
flying-sheep 3028dff
move deprecated stuff
flying-sheep f11b6ba
Use deprecation decorator
flying-sheep 735f00a
relnote
flying-sheep 4d54700
Merge branch 'pa/deprecated' into withreplacement
flying-sheep 0a5b284
fix dask warning stuff
flying-sheep 0ca9411
oops
flying-sheep f587cdf
Merge branch 'main' into withreplacement
flying-sheep 396b21a
Bump numpy to version that has get_bit_generator
flying-sheep e3831bd
Merge branch 'main' into withreplacement
flying-sheep 1ab8c97
update to compatible numba version
flying-sheep 10db5be
front-load validation
flying-sheep 8927554
add test for n=1
flying-sheep f163014
Merge branch 'main' into withreplacement
flying-sheep ce02426
use typevar
flying-sheep 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,5 @@ | |
|
||
pp.filter_genes_dispersion | ||
pp.normalize_per_cell | ||
pp.subsample | ||
``` |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
{func}`~scanpy.pp.sample` supports both upsampling and downsampling of observations and variables. {func}`~scanpy.pp.subsample` is now deprecated. {smaller}`G Eraslan` & {smaller}`P Angerer` |
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
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from ..._compat import _legacy_numpy_gen, old_positionals | ||
from .._simple import sample | ||
|
||
if TYPE_CHECKING: | ||
import numpy as np | ||
from anndata import AnnData | ||
from numpy.typing import NDArray | ||
from scipy.sparse import csc_matrix, csr_matrix | ||
|
||
from ..._compat import _LegacyRandom | ||
|
||
CSMatrix = csr_matrix | csc_matrix | ||
|
||
|
||
@old_positionals("n_obs", "random_state", "copy") | ||
def subsample( | ||
data: AnnData | np.ndarray | CSMatrix, | ||
fraction: float | None = None, | ||
*, | ||
n_obs: int | None = None, | ||
random_state: _LegacyRandom = 0, | ||
copy: bool = False, | ||
) -> AnnData | tuple[np.ndarray | CSMatrix, NDArray[np.int64]] | None: | ||
"""\ | ||
Subsample to a fraction of the number of observations. | ||
|
||
.. deprecated:: 1.11.0 | ||
|
||
Use :func:`~scanpy.pp.sample` instead. | ||
|
||
Parameters | ||
---------- | ||
data | ||
The (annotated) data matrix of shape `n_obs` × `n_vars`. | ||
Rows correspond to cells and columns to genes. | ||
fraction | ||
Subsample to this `fraction` of the number of observations. | ||
n_obs | ||
Subsample to this number of observations. | ||
random_state | ||
Random seed to change subsampling. | ||
copy | ||
If an :class:`~anndata.AnnData` is passed, | ||
determines whether a copy is returned. | ||
|
||
Returns | ||
------- | ||
Returns `X[obs_indices], obs_indices` if data is array-like, otherwise | ||
subsamples the passed :class:`~anndata.AnnData` (`copy == False`) or | ||
returns a subsampled copy of it (`copy == True`). | ||
""" | ||
|
||
rng = _legacy_numpy_gen(random_state) | ||
return sample( | ||
data=data, fraction=fraction, n=n_obs, rng=rng, copy=copy, replace=False, axis=0 | ||
) |
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
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.
Uh oh!
There was an error while loading. Please reload this page.