From 122f63805c6d3eb48e991bfb3c1a868f4f5fe310 Mon Sep 17 00:00:00 2001 From: David Ormsbee Date: Thu, 19 Nov 2026 21:44:53 -0500 Subject: [PATCH 1/2] refactor: drop numpy from the course quality API 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 --- cms/djangoapps/contentstore/api/views/course_quality.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cms/djangoapps/contentstore/api/views/course_quality.py b/cms/djangoapps/contentstore/api/views/course_quality.py index 99c7a65ac45e..b843f81bc9d1 100644 --- a/cms/djangoapps/contentstore/api/views/course_quality.py +++ b/cms/djangoapps/contentstore/api/views/course_quality.py @@ -3,7 +3,6 @@ import statistics import time -import numpy as np from edxval.api import get_course_videos_qset from openedx_authz.authz import COURSES_VIEW_COURSE from rest_framework.generics import GenericAPIView @@ -276,8 +275,10 @@ def _stats_dict(self, data): # pylint: disable=missing-function-docstring return dict( min=min(data), max=max(data), - mean=np.around(np.mean(data)), - median=np.around(np.median(data)), + # round() rounds half to even, as np.around() did. float() + # keeps the serialized values the same as before (2.0, not 2). + mean=float(round(statistics.fmean(data))), + median=float(round(statistics.median(data))), # On a tie, report the smallest of the most common values. mode=min(statistics.multimode(data)), ) From f628a1cce181b47c4e6641a9abb885982cbbdb19 Mon Sep 17 00:00:00 2001 From: David Ormsbee Date: Thu, 19 Nov 2026 21:44:53 -0500 Subject: [PATCH 2/2] refactor: drop numpy from grade percent rounding 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 --- lms/djangoapps/grades/scores.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lms/djangoapps/grades/scores.py b/lms/djangoapps/grades/scores.py index 82e255c8d935..c0c966ac7da9 100644 --- a/lms/djangoapps/grades/scores.py +++ b/lms/djangoapps/grades/scores.py @@ -5,7 +5,6 @@ from logging import getLogger -from numpy import around from xblock.core import XBlock from openedx.core.lib.cache_utils import process_cached @@ -151,8 +150,11 @@ def compute_percent(earned, possible): Returns the percentage of the given earned and possible values. """ if possible > 0: - # Rounds to four decimal places. - return around(earned / possible, decimals=4) + # Rounds half to even, to four decimal places. This is deliberately not + # round(x, 4): scaling, rounding to an integer, and scaling back is how + # numpy.around() works, and it produces slightly different results from + # round(x, 4) for some values. Changing it could shift persisted grades. + return round(earned / possible * 10000) / 10000 else: return 0.0