Repository navigation
Conversation
ormsbee
force-pushed
the
ormsbee/remove-numpy
branch
from
November 20, 2026 03:53
57b68e7 to
22c75d3
Compare
ormsbee
marked this pull request as ready for review
November 20, 2026 03:55
The course quality view only used numpy for mean, median, and rounding. Replace them with statistics.fmean(), statistics.median(), and round(), which rounds half to even like np.around(). The results are wrapped in float() so the serialized values stay the same (e.g. 2.0, not 2). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
compute_percent() used numpy.around(x, decimals=4). Replace it with round(x * 10000) / 10000, which is the same algorithm numpy uses (scale, round half to even, unscale), so the results are bit-for-bit identical. This is deliberately not round(x, 4). Python's round() works from the exact decimal value of the float, so for some inputs it gives a different fourth decimal place than numpy, which could shift persisted grades. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ormsbee
force-pushed
the
ormsbee/remove-numpy
branch
from
November 21, 2026 01:31
22c75d3 to
f628a1c
Compare
Contributor
Author
|
FYI @blarghmatey and @pdpinch, as this touches grade calculation, though I don't expect it to actually cause any issues. |
Contributor
Author
|
@feanil, @kdmccormick: May I trouble one of you folks to review this one? |
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Removes the two direct uses of numpy in edx-platform and replaces them with the standard library. This follows #39410, which did the same for scipy in the course quality API.
Course quality API (
cms/djangoapps/contentstore/api/views/course_quality.py)np.around(np.mean(...))andnp.around(np.median(...))becomefloat(round(statistics.fmean(...)))andfloat(round(statistics.median(...))).round()rounds half to even, likenp.around(). Thefloat()keeps the serialized output unchanged (2.0, not2).Grade percentages (
lms/djangoapps/grades/scores.py)compute_percent()usednumpy.around(x, decimals=4). It now usesround(x * 10000) / 10000, which is the same algorithm numpy uses: scale, round half to even, then unscale. I deliberately avoidedround(x, 4). It works from the float's exact decimal value, so it sometimes gives a different fourth decimal place than numpy, and that could shift persisted grades.Testing
compute_percent: 3.56M inputs, including every integerearned/possiblewithpossible <= 2000, random weighted scores, sums of fractional points, and values on and next to each half-step. There were 0 mismatches. For comparison,round(x, 4)would have differed on 2,374 of them.cms/djangoapps/contentstore/api/tests/test_quality.pypasses. It already covers the round-half-to-even case (a mean and median of 1.5 report as 2.0).lms/djangoapps/gradestest suite passes.Where numpy still comes from
numpy stays installed after this, because these dependencies require it:
sin,sqrt,log, and the rest onto numpy andnumpy.lib.scimath. edx-platform importscalcdirectly incommon/djangoapps/util/views.py, and capa uses it for numerical and formula responses.numpy>=1.26. capa uses it for image response click regions.chem.milleruses numpy vectors to grade crystallography problems. chem also declares scipy, but nothing in it imports scipy. That declaration is now the only reason scipy is installed in the LMS/CMS environment.responsetypes.pyimports numpy, but only fornumpy.complexinFormulaResponse.strip_dict(). That attribute was removed in numpy 1.24, and nothing calls the method. capa'ssafe_execalso lists numpy and scipy as lazy imports for problem code.numpy<2.0.0constraint exists (Unpin elasticsearch and numpy in edx-platform #35126), so that constraint should stay.The codejail sandbox (
requirements/edx-sandbox) pins numpy and scipy directly, so that problem code can use them. That's intentional and unaffected by this PR.🤖 Generated with Claude Code