From 156e33c0d65851c2f9aa4198e22ac8c748700b1f Mon Sep 17 00:00:00 2001 From: Sam Maurer Date: Sat, 8 Jun 2019 15:14:23 -0700 Subject: [PATCH 1/5] Explicitly convert pd.Series to Numpy array --- baus/utils.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/baus/utils.py b/baus/utils.py index aae97ea3d..5fb1d7fb8 100644 --- a/baus/utils.py +++ b/baus/utils.py @@ -207,8 +207,13 @@ 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 + # certain numpy versions have trouble multiplying matrices by pd.Series; see PR #98 + 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 From 0a6f74fe862a74b4ca973a27cc3a613211e62094 Mon Sep 17 00:00:00 2001 From: Sam Maurer Date: Sat, 8 Jun 2019 15:29:37 -0700 Subject: [PATCH 2/5] PEP8 fixes --- baus/utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/baus/utils.py b/baus/utils.py index 5fb1d7fb8..108dfb4c2 100644 --- a/baus/utils.py +++ b/baus/utils.py @@ -207,13 +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 - # certain numpy versions have trouble multiplying matrices by pd.Series; see PR #98 + # most numpy/pandas combinations will perform this conversion + # automatically, but explicit is safer - see PR #98 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 From 66976e08829b656dc392ab653a7f18369bf1d2c7 Mon Sep 17 00:00:00 2001 From: Sam Maurer Date: Mon, 17 Jun 2019 11:48:42 -0700 Subject: [PATCH 3/5] Data type casts with error reporting --- baus/models.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/baus/models.py b/baus/models.py index ab5ae13dc..6296593a0 100644 --- a/baus/models.py +++ b/baus/models.py @@ -119,7 +119,16 @@ 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) + + print "TEMP INSTRUMENTING" + print type(need_more_jobs) + print type(drop) + print type(need_more_jobs.drop(drop)) + print need_more_jobs + print drop + print 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, @@ -511,6 +520,10 @@ def residential_developer(feasibility, households, buildings, parcels, year, # method below buildings = orca.get_table('buildings') + print "TEMP INSTRUMENTING" + print type(target) + print target + new_buildings = utils.run_developer( "residential", households, @@ -523,7 +536,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) @@ -718,6 +731,10 @@ def office_developer(feasibility, jobs, buildings, parcels, year, # method below buildings = orca.get_table('buildings') + print "TEMP INSTRUMENTING" + print type(target) + print target + new_buildings = utils.run_developer( typ.lower(), jobs, @@ -731,7 +748,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']) From 133841d8fb215b5c2a4251db9e571f30a06f4ee2 Mon Sep 17 00:00:00 2001 From: Sam Maurer Date: Mon, 17 Jun 2019 14:56:01 -0700 Subject: [PATCH 4/5] Removing error reporting --- baus/models.py | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/baus/models.py b/baus/models.py index 6296593a0..86d2f11a7 100644 --- a/baus/models.py +++ b/baus/models.py @@ -119,15 +119,6 @@ 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 - - print "TEMP INSTRUMENTING" - print type(need_more_jobs) - print type(drop) - print type(need_more_jobs.drop(drop)) - print need_more_jobs - print drop - print 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 @@ -520,10 +511,6 @@ def residential_developer(feasibility, households, buildings, parcels, year, # method below buildings = orca.get_table('buildings') - print "TEMP INSTRUMENTING" - print type(target) - print target - new_buildings = utils.run_developer( "residential", households, @@ -731,10 +718,6 @@ def office_developer(feasibility, jobs, buildings, parcels, year, # method below buildings = orca.get_table('buildings') - print "TEMP INSTRUMENTING" - print type(target) - print target - new_buildings = utils.run_developer( typ.lower(), jobs, From bafeef7d49dc743c17c487d2bd8bc3540be72e94 Mon Sep 17 00:00:00 2001 From: Sam Maurer Date: Mon, 17 Jun 2019 15:00:12 -0700 Subject: [PATCH 5/5] Updating PR reference --- baus/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/baus/utils.py b/baus/utils.py index 108dfb4c2..ff87b21eb 100644 --- a/baus/utils.py +++ b/baus/utils.py @@ -208,7 +208,7 @@ 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 #98 + # automatically, but explicit is safer - see PR #99 if isinstance(col_marginals, pd.Series): col_marginals = col_marginals.values