Skip to content

Commit

Permalink
Fix initialization of integer Series and Dataframes when they should …
Browse files Browse the repository at this point in the history
…contain floats
  • Loading branch information
samakinen committed Jun 17, 2024
1 parent 3e346c5 commit d238074
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Scripts/assignment/mock_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def aggregate_results(self, resultdata):
pass

def calc_noise(self):
return pandas.Series(0, zone_param.area_aggregation)
return pandas.Series(0.0, zone_param.area_aggregation)

def prepare_network(self, car_dist_unit_cost: Optional[float]=None):
pass
Expand Down
2 changes: 1 addition & 1 deletion Scripts/datatypes/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TourLengthHistogram:
def __init__(self):
index = ["{}-{}".format(intervals[i], intervals[i + 1])
for i in range(len(intervals) - 1)]
self.histogram = pandas.Series(0, index)
self.histogram = pandas.Series(0.0, index)

def add(self, dist):
self.histogram.iat[numpy.searchsorted(self._u, dist, "right")] += 1
Expand Down
2 changes: 1 addition & 1 deletion Scripts/demand/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def calc_external(self, mode: str, internal_trips: pandas.Series) -> Demand:
Matrix of whole day trips from external to internal zones
"""
base_mtx = self.base_demand.get_external(mode)
mtx = pandas.DataFrame(0, self.all_zone_numbers, self.growth.index)
mtx = pandas.DataFrame(0.0, self.all_zone_numbers, self.growth.index)
municipalities = ZoneIntervals("municipalities")
# Base matrix is aggregated to municipality level,
# so we need to disaggregate it
Expand Down
2 changes: 1 addition & 1 deletion Scripts/demand/trips.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def create_population(self):
numpy.random.seed(param.population_draw)
self.population = []
zone_numbers = self.zone_data.zone_numbers[self.bounds]
self.zone_population = pandas.Series(0, zone_numbers)
self.zone_population = pandas.Series(0.0, zone_numbers)
# Group -1 is under-7-year-olds
age_range = numpy.arange(-1, len(param.age_groups))
for zone_number in zone_numbers:
Expand Down
2 changes: 1 addition & 1 deletion Scripts/models/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, purpose, resultdata):

def init_tours(self):
"""Initialize `tours` vector to 0."""
self.tours = pandas.Series(0, self.purpose.zone_numbers)
self.tours = pandas.Series(0.0, self.purpose.zone_numbers)

def add_tours(self):
"""Generate and add (peripheral) tours to zone vector."""
Expand Down
2 changes: 1 addition & 1 deletion Scripts/modelsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def _calculate_accessibility_and_savu_zones(self):
"result_summary")

def _sum_trips_per_zone(self, mode, include_dests=True):
int_demand = pandas.Series(0, self.zdata_base.zone_numbers)
int_demand = pandas.Series(0.0, self.zdata_base.zone_numbers)
for purpose in self.dm.tour_purposes:
if mode in purpose.modes and purpose.dest != "source":
bounds = (next(iter(purpose.sources)).bounds
Expand Down
8 changes: 4 additions & 4 deletions Scripts/utils/zone_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def __init__(self, zone_numbers):
self.init_matrix()

def init_matrix(self):
self.matrix = pandas.DataFrame(0, self.keys, self.keys)
self.matrix = pandas.DataFrame(0.0, self.keys, self.keys)

def add(self, orig, dest):
"""Add individual tour to aggregated matrix.
Expand All @@ -183,7 +183,7 @@ def add(self, orig, dest):
dest : int
Tour destination zone number
"""
self.matrix.at[self.mapping[orig], self.mapping[dest]] += 1
self.matrix.at[self.mapping[orig], self.mapping[dest]] += 1.0

def aggregate(self, matrix):
"""Aggregate (tour demand) matrix to larger areas.
Expand All @@ -194,7 +194,7 @@ def aggregate(self, matrix):
Disaggregated matrix with zone indices and columns
"""
self.init_matrix()
tmp_mtx = pandas.DataFrame(0, self.keys, matrix.columns)
tmp_mtx = pandas.DataFrame(0.0, self.keys, matrix.columns)
for area in self:
i = self._get_slice(area, matrix.index)
tmp_mtx.loc[area] = matrix.loc[i].sum(0).values
Expand All @@ -210,7 +210,7 @@ def __init__(self, zone_numbers):
self.init_array()

def init_array(self):
self.array = pandas.Series(0, self.keys)
self.array = pandas.Series(0.0, self.keys)

def add(self, zone):
"""Add individual tour to aggregated array.
Expand Down

0 comments on commit d238074

Please sign in to comment.