Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#Get existing tables
existing_tables = tables_in_schema(schema)
# set the search path, otherwise won't find ST_DWithin()
cur = con.cursor()
cur.execute("SET search_path TO {schema}, public;".format(schema=schema))
# make a new table that contains one row for every parcel in Cincinnati
# this table has three columns: parcel_id, inspection_date, viol_outcome
# inspection_date is the one given as a parameter and
# is the same for all parcels
if 'parcels_inspections' not in existing_tables:
logger.info('Creating parcels_inspections table...')
if inspection_date is None:
inspections = outcome.generate_labels()
else:
if insp_set=='all_inspections':
inspections = outcome.make_fake_inspections_all_parcels_cincy(inspection_date)
elif insp_set=='field_test':
inspections = outcome.load_inspections_from_field_test(inspection_date)
inspections.to_sql("parcels_inspections", engine, chunksize=50000,
if_exists='fail', index=False, schema=schema)
logging.debug("... table has {} rows".format(len(inspections)))
#Create an index to make joins with events_Xmonths_* tables faster
cur.execute('CREATE INDEX ON parcels_inspections (parcel_id);')
cur.execute('CREATE INDEX ON parcels_inspections (inspection_date);')
cur.execute('CREATE INDEX ON parcels_inspections (parcel_id, inspection_date);')
con.commit()
else:
logger.info('parcels_inspections table already exists, skipping...')