Skip to content
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

Add replace option to subsample and rename function to sample #943

Merged
merged 41 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
bf922e1
Add replace option to subsample.
gokceneraslan Dec 2, 2019
32baba1
Merge branch 'master' into withreplacement
gokceneraslan Apr 20, 2020
671ec71
Add sc.pp.sample with axis argument.
gokceneraslan Apr 20, 2020
9e0739b
Fix fraction doc
gokceneraslan Apr 20, 2020
8ec8cf3
Add to release notes
gokceneraslan Apr 20, 2020
cdf4c65
Merge branch 'main' into withreplacement
flying-sheep Nov 14, 2024
fdf524a
refactor
flying-sheep Nov 14, 2024
061a19d
Refactor tests
flying-sheep Nov 14, 2024
8528f2d
Merge branch 'main' into withreplacement
flying-sheep Nov 14, 2024
06d4280
handle array case in test
flying-sheep Nov 14, 2024
6eeab2e
Test errors
flying-sheep Nov 14, 2024
b1f5061
prettier deprecations
flying-sheep Nov 14, 2024
cec8aff
docs
flying-sheep Nov 14, 2024
daa147e
ignore dask warning correctly
flying-sheep Nov 14, 2024
3c31abd
sig exception
flying-sheep Nov 14, 2024
d350411
WIP
flying-sheep Nov 18, 2024
f02725a
Merge branch 'main' into withreplacement
flying-sheep Nov 19, 2024
c24e9b2
remove duplicate _LegacyRandom
flying-sheep Nov 19, 2024
e246f02
undo compat thing
flying-sheep Nov 19, 2024
4ad40b7
fix backwards compat
flying-sheep Nov 19, 2024
1b8c81e
Use fake Generator
flying-sheep Nov 19, 2024
594d961
backwards compat test
flying-sheep Nov 19, 2024
00fdd77
Merge branch 'main' into withreplacement
flying-sheep Nov 21, 2024
59a171c
Fix tests for old Pythons
flying-sheep Nov 21, 2024
59adc76
test that random state is modified
flying-sheep Nov 21, 2024
ef27db0
Fix util
flying-sheep Nov 21, 2024
c471e94
types
flying-sheep Nov 21, 2024
3028dff
move deprecated stuff
flying-sheep Nov 21, 2024
f11b6ba
Use deprecation decorator
flying-sheep Nov 21, 2024
735f00a
relnote
flying-sheep Nov 21, 2024
4d54700
Merge branch 'pa/deprecated' into withreplacement
flying-sheep Nov 21, 2024
0a5b284
fix dask warning stuff
flying-sheep Nov 21, 2024
0ca9411
oops
flying-sheep Nov 21, 2024
f587cdf
Merge branch 'main' into withreplacement
flying-sheep Nov 22, 2024
396b21a
Bump numpy to version that has get_bit_generator
flying-sheep Nov 22, 2024
e3831bd
Merge branch 'main' into withreplacement
flying-sheep Dec 12, 2024
1ab8c97
update to compatible numba version
flying-sheep Dec 12, 2024
10db5be
front-load validation
flying-sheep Dec 19, 2024
8927554
add test for n=1
flying-sheep Dec 19, 2024
f163014
Merge branch 'main' into withreplacement
flying-sheep Dec 19, 2024
ce02426
use typevar
flying-sheep Dec 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion scanpy/preprocessing/_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,7 @@ def subsample(
n_obs: Optional[int] = None,
random_state: Union[int, RandomState] = 0,
copy: bool = False,
replace: bool = False,
) -> Optional[AnnData]:
"""\
Subsample to a fraction of the number of observations.
Expand All @@ -959,6 +960,8 @@ def subsample(
copy
If an :class:`~anndata.AnnData` is passed,
determines whether a copy is returned.
replace
If True, samples are drawn with replacement.

Returns
-------
Expand All @@ -979,7 +982,7 @@ def subsample(
logg.debug(f'... subsampled to {new_n_obs} data points')
else:
raise ValueError('Either pass `n_obs` or `fraction`.')
obs_indices = np.random.choice(old_n_obs, size=new_n_obs, replace=False)
obs_indices = np.random.choice(old_n_obs, size=new_n_obs, replace=replace)
if isinstance(data, AnnData):
adata = data.copy() if copy else data
adata._inplace_subset_obs(obs_indices)
Expand Down
2 changes: 2 additions & 0 deletions scanpy/tests/test_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ def test_subsample():
assert adata.n_obs == 40
sc.pp.subsample(adata, fraction=0.1)
assert adata.n_obs == 4
sc.pp.subsample(adata, n_obs=201, replace=True)
assert adata.n_obs == 201


def test_scale():
Expand Down