Skip to content

Commit

Permalink
compute counts
Browse files Browse the repository at this point in the history
  • Loading branch information
Intron7 committed Nov 21, 2024
1 parent ac19bb3 commit 7d91abc
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions src/scanpy/preprocessing/_normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,9 @@ def _normalize_data(X, counts, after=None, *, copy: bool = False):
X = X.astype(np.float32) # TODO: Check if float64 should be used
if after is None:
if isinstance(counts, DaskArray):

def nonzero_median(x):
return np.ma.median(np.ma.masked_array(x, x == 0)).item()

after = da.from_delayed(
dask.delayed(nonzero_median)(counts),
shape=(),
meta=counts._meta,
dtype=counts.dtype,
)
else:
counts_greater_than_zero = counts[counts > 0]
after = np.median(counts_greater_than_zero, axis=0)
counts = counts.compute()

Check warning on line 35 in src/scanpy/preprocessing/_normalization.py

View check run for this annotation

Codecov / codecov/patch

src/scanpy/preprocessing/_normalization.py#L35

Added line #L35 was not covered by tests
counts_greater_than_zero = counts[counts > 0]
after = np.median(counts_greater_than_zero, axis=0)
counts = counts / after
return axis_mul_or_truediv(
X,
Expand Down

0 comments on commit 7d91abc

Please sign in to comment.