Skip to content

Reuse sized iterator values when calculating variance - #399

Merged
dgilland merged 1 commit into
dgilland:developfrom
ShahadatTest:fix/variance-sized-iterators
Nov 1, 2026
Merged

dgilland merged 1 commit into
dgilland:developfrom
ShahadatTest:fix/variance-sized-iterators

Conversation

@ShahadatTest

Copy link
Copy Markdown
Contributor

variance(numpy.array([1., 2., 3.]).flat) returns NaN instead of 2/3. The input has a length, so it is not saved before the mean consumes it; the squared-deviation pass then sees no items. std_deviation inherits this problem.

Materialize iterator inputs even when they implement __len__. Reusable sized collections retain their existing path. Regression tests use a dependency-free sized iterator and cover variance, standard deviation, single-item and empty inputs. Controls verify that dict, UserDict and mapping-proxy inputs still process values.

Validation on Windows:

  • Before: 6 new regression cases fail, 8 empty/mapping controls pass.
  • Full unit tests/doctests on Python 3.10 and 3.12: 3,093 passed with 100% coverage each.
  • Manually verified NumPy flat iterators now return variance 0.6666666666666666 and standard deviation 0.816496580927726, without adding a NumPy test dependency.
  • Full configured Ruff lint, changed-file formatting, package mypy (15 files), and final diff whitespace checks pass.

Checked current contribution instructions and existing issues/PRs. Earlier merged #261 handles unsized iterators; this fixes the remaining sized-iterator path. No overlapping open change was found. The account already appears in AUTHORS.rst.

AI assistance: OpenAI Codex investigated, implemented and tested this change at the account owner's request, aro 2ta, expanded to eta soho aro 25ta koro???. No independent human review is claimed.

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 100.0%. remained the same — ShahadatTest:fix/variance-sized-iterators into dgilland:develop

@dgilland
dgilland merged commit 2c54cb2 into dgilland:develop Nov 1, 2026
12 checks passed
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.

3 participants