Skip to content

Commit

Permalink
Upgrade numpy to 1.16.6 (#3137)
Browse files Browse the repository at this point in the history
* Upgrade numpy to latest that supports python 2.7

* Remove unused numpy imports

* Replace deprecated boolean subtraction

* increment version
  • Loading branch information
willgearty committed Oct 24, 2020
1 parent d2be90d commit 481a1ec
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 18 deletions.
18 changes: 9 additions & 9 deletions esp/esp/program/controllers/classchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ def initialize(self):
except IndexError:
pass

self.student_not_checked_in[numpy.transpose(numpy.nonzero(True-self.enroll_orig.any(axis=(1,2))))] = True
self.student_not_checked_in[numpy.transpose(numpy.nonzero(~(self.enroll_orig.any(axis=(1,2)))))] = True

# Populate request matrix
request_regs = StudentRegistration.objects.filter(self.Q_REQ).values_list('user__id', 'section__id', 'section__meeting_times__id').distinct()
Expand Down Expand Up @@ -518,7 +518,7 @@ def initialize(self):
self.section_capacities[sec_ind] += numpy.count_nonzero(sec_enroll_orig * any_overlapping_requests)
# Commit to enrolling students into this section if they were
# originally in it and they didn't request any overlapping classes
self.enroll_final[numpy.transpose(numpy.nonzero(sec_enroll_orig * (True - any_overlapping_requests))), sec_ind, self.section_schedules[sec_ind,:]] = True
self.enroll_final[numpy.transpose(numpy.nonzero(sec_enroll_orig * ~(any_overlapping_requests))), sec_ind, self.section_schedules[sec_ind,:]] = True
self.section_scores[sec_ind] = -self.section_capacities[sec_ind]
self.section_scores[sec_ind] += numpy.count_nonzero(self.request[:, sec_ind, :].any(axis=1)) # number who want to switch in
self.section_capacities_orig = numpy.copy(self.section_capacities)
Expand Down Expand Up @@ -563,11 +563,11 @@ def fill_section(self, si, priority=False):

# Filter students by who has all of the section's timeslots available
for [ts_ind,] in timeslots:
possible_students *= (True - self.enroll_final[:, :, ts_ind].any(axis=1))
possible_students *= ~(self.enroll_final[:, :, ts_ind].any(axis=1))

# Filter students by who is not already registered for a different section of the class
for sec_index in numpy.nonzero(self.same_subject[:, si])[0]:
possible_students *= (True - self.enroll_final[:, sec_index, :].any(axis=1))
possible_students *= ~(self.enroll_final[:, sec_index, :].any(axis=1))

# Filter students by lunch constraint - if class overlaps with lunch period, student must have 1 additional free spot
# NOTE: Currently only works with 2 lunch periods per day
Expand All @@ -577,7 +577,7 @@ def fill_section(self, si, priority=False):
for j in range(self.lunch_timeslots.shape[1]):
timeslot_index = self.timeslot_indices[self.lunch_timeslots[lunch_day, j]]
if timeslot_index != ts_ind:
possible_students *= (True - self.student_schedules[:, timeslot_index])
possible_students *= ~(self.student_schedules[:, timeslot_index])

candidate_students = numpy.nonzero(possible_students)[0]
num_spaces = self.section_capacities[si]
Expand Down Expand Up @@ -621,7 +621,7 @@ def push_back_students(self):
# 1-dimensional matrix of whether students are free during the
# times of this class section in the enrollment we've computed
# so far
no_enroll_final = True - self.enroll_final[:,:,self.section_schedules[sec_ind,:]].any(axis=(1,2))
no_enroll_final = ~(self.enroll_final[:,:,self.section_schedules[sec_ind,:]].any(axis=(1,2)))
# Find students that were originally enrolled in this class and
# did not get any classes overlapping it in the enrollment
# we've computed so far
Expand Down Expand Up @@ -692,8 +692,8 @@ def save_assignments(self):
""" Store lottery assignments in the database once they have been computed.
This is a fairly time consuming step compared to computing the assignments. """

assignments = numpy.transpose(numpy.nonzero((self.enroll_final * (True - self.enroll_orig)).any(axis=2)))
removals = numpy.transpose(numpy.nonzero((self.enroll_orig * (True - self.enroll_final)).any(axis=2)))
assignments = numpy.transpose(numpy.nonzero((self.enroll_final * ~(self.enroll_orig)).any(axis=2)))
removals = numpy.transpose(numpy.nonzero((self.enroll_orig * ~(self.enroll_final)).any(axis=2)))
relationship, created = RegistrationType.objects.get_or_create(name='Enrolled')

for (student_ind,section_ind) in removals:
Expand Down Expand Up @@ -741,5 +741,5 @@ def send_emails(self, for_real = False):
self.extra_headers['Reply-To'] = self.from_email
for [student_ind] in numpy.transpose(numpy.nonzero(self.changed)):
self.send_student_email(student_ind, changed = True, for_real = for_real, f = f)
for [student_ind] in numpy.transpose(numpy.nonzero(True-self.changed)):
for [student_ind] in numpy.transpose(numpy.nonzero(~(self.changed))):
self.send_student_email(student_ind, changed = False, for_real = for_real, f = f)
6 changes: 3 additions & 3 deletions esp/esp/program/controllers/lottery.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,11 @@ def fill_section(self, si, priority=False, rank=10):

# Filter students by who has all of the section's timeslots available
for i in range(timeslots.shape[0]):
possible_students *= (True - self.student_schedules[:, timeslots[i]])
possible_students *= ~(self.student_schedules[:, timeslots[i]])

# Filter students by who is not already registered for a different section of the class
for sec_index in numpy.nonzero(self.section_overlap[:, si])[0]:
possible_students *= (True - self.student_sections[:, sec_index])
possible_students *= ~(self.student_sections[:, sec_index])

# Filter students by lunch constraint - if class overlaps with lunch period, student must have 1 additional free spot
# NOTE: Currently only works with 2 lunch periods per day
Expand All @@ -407,7 +407,7 @@ def fill_section(self, si, priority=False, rank=10):
for j in range(self.lunch_timeslots.shape[1]):
timeslot_index = self.timeslot_indices[self.lunch_timeslots[lunch_day, j]]
if timeslot_index != timeslots[i]:
possible_students *= (True - self.student_schedules[:, timeslot_index])
possible_students *= ~(self.student_schedules[:, timeslot_index])

candidate_students = numpy.nonzero(possible_students)[0]
if candidate_students.shape[0] <= num_spaces:
Expand Down
3 changes: 0 additions & 3 deletions esp/esp/program/controllers/studentregsanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
Email: web-team@learningu.org
"""

import numpy
import numpy.random

from datetime import date, datetime
import logging
logger = logging.getLogger(__name__)
Expand Down
1 change: 0 additions & 1 deletion esp/esp/program/modules/handlers/lotteryfrontendmodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from esp.utils.web import render_to_response
from esp.users.models import ESPUser
from esp.utils.decorators import json_response
import numpy

class LotteryFrontendModule(ProgramModuleObj):

Expand Down
1 change: 0 additions & 1 deletion esp/esp/program/modules/handlers/schedulingcheckmodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ def __init__(self, program, formatter=JSONFormatter()):
self.d_grades = []

def _getLunchByDay(self):
import numpy
# Get IDs of timeslots allocated to lunch by day
# (note: requires that this is constant across days)
lunch_timeslots = Event.objects.filter(meeting_times__parent_class__parent_program=self.p, meeting_times__parent_class__category__category='Lunch').order_by('start').distinct()
Expand Down
2 changes: 1 addition & 1 deletion esp/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ docutils==0.12 # Needed for django.contrib.admindocs
flake8==2.5.0 # Required for linter
ipython==3.2.1 # Used for shell_plus
Markdown==2.3.1 # Used in QSD
numpy==1.7.1 # Used mainly in the lottery and class change controller
numpy==1.16.6 # Used mainly in the lottery and class change controller
pillow==6.2.2 # Required for ImageField, which we use in teacher bios
psycopg2==2.8.6 # Talks to postgres
pycurl==7.19.5.1 # Used only in mailing labels and a formstack script which I think is outdated
Expand Down

0 comments on commit 481a1ec

Please sign in to comment.