Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating print statements for Python 3 compatibility #101

Merged
merged 17 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions baus.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import print_function

import os
import sys
import time
Expand Down Expand Up @@ -110,8 +112,8 @@
run_num = orca.get_injectable("run_number")

if LOGS:
print '***The Standard stream is being written to /runs/run{0}.log***'\
.format(run_num)
print('***The Standard stream is being written to /runs/run{0}.log***'
.format(run_num))
sys.stdout = sys.stderr = open("runs/run%d.log" % run_num, 'w')

if RANDOM_SEED:
Expand Down Expand Up @@ -373,11 +375,12 @@ def run_models(MODE, SCENARIO):
raise "Invalid mode"


print "Started", time.ctime()
print "Current Branch : ", BRANCH.rstrip()
print "Current Commit : ", CURRENT_COMMIT.rstrip()
print "Current Scenario : ", orca.get_injectable('scenario').rstrip()
print "Random Seed : ", RANDOM_SEED

print("Started", time.ctime())
print("Current Branch : ", BRANCH.rstrip())
print("Current Commit : ", CURRENT_COMMIT.rstrip())
print("Current Scenario : ", orca.get_injectable('scenario').rstrip())
print("Random Seed : ", RANDOM_SEED)


if SLACK:
Expand All @@ -391,7 +394,7 @@ def run_models(MODE, SCENARIO):
run_models(MODE, SCENARIO)

except Exception as e:
print traceback.print_exc()
print(traceback.print_exc())
if SLACK:
slack.chat.post_message(
'#sim_updates',
Expand All @@ -401,7 +404,7 @@ def run_models(MODE, SCENARIO):
raise e
sys.exit(0)

print "Finished", time.ctime()
print("Finished", time.ctime())

if MAPS:

Expand Down
24 changes: 13 additions & 11 deletions baus/datasources.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import print_function

import numpy as np
import pandas as pd
import os
Expand Down Expand Up @@ -91,7 +93,7 @@ def limits_settings(policy, scenario):
d = policy['development_limits']

if scenario in d.keys():
print "Using limits for scenario: %s" % scenario
print("Using limits for scenario: %s" % scenario)
assert "default" in d

d_scen = d[scenario]
Expand All @@ -102,7 +104,7 @@ def limits_settings(policy, scenario):

return d

print "Using default limits"
print("Using default limits")
return d["default"]


Expand All @@ -115,24 +117,24 @@ def inclusionary_housing_settings(policy, scenario):

if (scenario in ["11", "12", "15"]) and\
(scenario not in policy["inclusionary_fr2_enable"]):
print "Using Futures Round 1 (PBA40) inclusionary settings"
print("Using Futures Round 1 (PBA40) inclusionary settings")
fr1 = str(int(scenario) - 10)
s = s[fr1]

elif scenario in s.keys():
print "Using inclusionary settings for scenario: %s" % scenario
print("Using inclusionary settings for scenario: %s" % scenario)
s = s[scenario]

elif "default" in s.keys():
print "Using default inclusionary settings"
print("Using default inclusionary settings")
s = s["default"]

d = {}
for item in s:
# this is a list of cities with an inclusionary rate that is the
# same for all the cities in the list
print "Setting inclusionary rates for %d cities to %.2f" %\
(len(item["values"]), item["amount"])
print("Setting inclusionary rates for %d cities to %.2f" %
(len(item["values"]), item["amount"]))
# this is a list of inclusionary rates and the cities they apply
# to - need tro turn it in a map of city names to rates
for juris in item["values"]:
Expand Down Expand Up @@ -225,7 +227,7 @@ def fetch_from_s3(settings):
file = os.path.join("data", file)
if os.path.exists(file):
continue
print "Downloading " + file
print("Downloading " + file)
key = bucket.get_key(file, validate=False)
key.get_contents_to_filename(file)

Expand Down Expand Up @@ -618,7 +620,7 @@ def get_dev_projects_table(scenario, parcels):

cnts = df.geom_id.isin(parcels.geom_id).value_counts()
if False in cnts.index:
print "%d MISSING GEOMIDS!" % cnts.loc[False]
print("%d MISSING GEOMIDS!" % cnts.loc[False])

df = df[df.geom_id.isin(parcels.geom_id)]

Expand Down Expand Up @@ -669,10 +671,10 @@ def development_projects(parcels, mapping, scenario):
df = df.dropna(subset=["year_built"])
df = df[df.action.isin(["add", "build"])]

print "Describe of development projects"
print("Describe of development projects")
# this makes sure dev projects has all the same columns as buildings
# which is the point of this method
print df[orca.get_table('buildings').local_columns].describe()
print(df[orca.get_table('buildings').local_columns].describe())

return df

Expand Down
15 changes: 9 additions & 6 deletions baus/earthquake.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import print_function

import orca
import numpy as np
import pandas as pd
Expand Down Expand Up @@ -259,7 +261,8 @@ def earthquake_demolish(parcels, parcels_tract, tracts_earthquake, buildings,
# created with scripts/parcel_tract_assignment.py
census_tract = pd.Series(parcels_tract['census_tract'],
parcels_tract.index)
print "Number of parcels with census tracts is: %d" % len(census_tract)
print("Number of parcels with census tracts is: %d" %
len(census_tract))
orca.add_column('parcels', 'tract', census_tract)

# group parcels by their census tract
Expand All @@ -274,7 +277,7 @@ def earthquake_demolish(parcels, parcels_tract, tracts_earthquake, buildings,
key=itemgetter(0)):
tract_parcels_grp.append(list(parcels))
tracts.append(tract)
print "Number of census tract groups is: %d" % len(tract_parcels_grp)
print("Number of census tract groups is: %d" % len(tract_parcels_grp))

# for the parcels in each tract, destroy X% of parcels in that tract
tracts_earthquake = tracts_earthquake.to_frame()
Expand Down Expand Up @@ -373,8 +376,8 @@ def earthquake_demolish(parcels, parcels_tract, tracts_earthquake, buildings,
fire_buildings.extend(buildings_fire)
eq_buildings.extend(buildings_fire)

print "Total number of buildings being destroyed is: %d" \
% len(eq_buildings)
print("Total number of buildings being destroyed is: %d" %
len(eq_buildings))

orca.add_injectable("eq_buildings", eq_buildings)
orca.add_injectable("existing_buildings", existing_buildings)
Expand All @@ -386,7 +389,7 @@ def earthquake_demolish(parcels, parcels_tract, tracts_earthquake, buildings,
eq_demolish = buildings.local[buildings.index.isin
(eq_buildings)]
orca.add_table("eq_demolish", eq_demolish)
print "Demolishing %d buildings" % len(eq_demolish)
print("Demolishing %d buildings" % len(eq_demolish))

households = households.to_frame()
hh_unplaced = households[households["building_id"] == -1]
Expand Down Expand Up @@ -416,4 +419,4 @@ def earthquake_demolish(parcels, parcels_tract, tracts_earthquake, buildings,

orca.add_table("buildings", buildings)
buildings = orca.get_table("buildings")
print "Demolished %d buildings" % (l1 - len(buildings))
print("Demolished %d buildings" % (l1 - len(buildings)))
Loading