Skip to content

docs(pp.scale): document that variance/std use ddof=1 (sample correction)#4196

Open
AxelMcKenna wants to merge 1 commit into
scverse:mainfrom
AxelMcKenna:docs/scale-ddof
Open

docs(pp.scale): document that variance/std use ddof=1 (sample correction)#4196
AxelMcKenna wants to merge 1 commit into
scverse:mainfrom
AxelMcKenna:docs/scale-ddof

Conversation

@AxelMcKenna

@AxelMcKenna AxelMcKenna commented Jul 4, 2026

Copy link
Copy Markdown
  • Closes #
  • Tests included or not required because: docs-only change, no behavior is added or modified.

sc.pp.scale computes gene-wise variance and standard deviation with Bessel's correction (ddof=1), via mean_var(x, axis=0, correction=1) in scale_array and scale_array_masked. This convention isn't stated anywhere in the docstring, so a reimplementation using numpy.std() defaults (ddof=0, population variance) silently diverges from sc.pp.scale's output - negligible for large n_obs, but non-negligible for small datasets (e.g. ~0.02% on a ~2700-cell PBMC3k-sized dataset, enough to shift where max_value clipping takes effect).

This PR adds a .. note:: to the scale docstring stating the correction used. No behavior change.

@codecov

codecov Bot commented Jul 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.85%. Comparing base (ecec3c2) to head (4a7ba69).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4196   +/-   ##
=======================================
  Coverage   79.85%   79.85%           
=======================================
  Files         121      121           
  Lines       12924    12924           
=======================================
  Hits        10321    10321           
  Misses       2603     2603           
Flag Coverage Δ
hatch-test.low-vers 78.97% <ø> (ø)
hatch-test.pre 79.78% <ø> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/scanpy/preprocessing/_scale.py 89.58% <ø> (ø)

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.

1 participant