Skip to content

Commit

Permalink
Merge pull request UDST#99 from urbansim/data-types
Browse files Browse the repository at this point in the history
Bug fixes to support NumPy 1.16
  • Loading branch information
theocharides authored Sep 23, 2019
2 parents cce7c9f + bafeef7 commit 10e4f42
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions baus/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def _proportional_jobs_model(
# city but not locations to put them in. we need to drop this demand
drop = need_more_jobs.index.difference(locations_series.unique())
print "We don't have any locations for these locations:\n", drop
need_more_jobs = need_more_jobs.drop(drop)
need_more_jobs = need_more_jobs.drop(drop).astype('int')

# choose random locations within jurises to match need_more_jobs totals
choices = groupby_random_choice(locations_series, need_more_jobs,
Expand Down Expand Up @@ -570,7 +570,7 @@ def residential_developer(feasibility, households, buildings, parcels, year,
year=year,
form_to_btype_callback=form_to_btype_func,
add_more_columns_callback=add_extra_columns_func,
num_units_to_build=target,
num_units_to_build=int(target),
profit_to_prob_func=subsidies.profit_to_prob_func,
**kwargs)

Expand Down Expand Up @@ -778,7 +778,7 @@ def office_developer(feasibility, jobs, buildings, parcels, year,
form_to_btype_callback=form_to_btype_func,
add_more_columns_callback=add_extra_columns_func,
residential=False,
num_units_to_build=target,
num_units_to_build=int(target),
profit_to_prob_func=subsidies.profit_to_prob_func,
**dev_settings['kwargs'])

Expand Down
6 changes: 6 additions & 0 deletions baus/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,14 @@ def constrained_normalization(marginals, constraint, total):
def simple_ipf(seed_matrix, col_marginals, row_marginals, tolerance=1, cnt=0):
assert np.absolute(row_marginals.sum() - col_marginals.sum()) < 5.0

# most numpy/pandas combinations will perform this conversion
# automatically, but explicit is safer - see PR #99
if isinstance(col_marginals, pd.Series):
col_marginals = col_marginals.values

# first normalize on columns
ratios = col_marginals / seed_matrix.sum(axis=0)

seed_matrix *= ratios
closeness = np.absolute(row_marginals - seed_matrix.sum(axis=1)).sum()
assert np.absolute(col_marginals - seed_matrix.sum(axis=0)).sum() < .01
Expand Down

0 comments on commit 10e4f42

Please sign in to comment.