Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.

Commit ebd200a

Browse files
committed
Merge pull request #33 from lsst/bugfix/SIM-1339-squelch-sqlalchemy-warning
Bugfix/sim 1339 squelch sqlalchemy warning
2 parents 00067a6 + 22f8f64 commit ebd200a

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

python/lsst/sims/maf/db/Database.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os, warnings
22
from .Table import Table
33
import inspect
4+
from sqlalchemy import text
45

56
__all__ = ['DatabaseRegistry', 'Database']
67

@@ -119,6 +120,6 @@ def queryDatabase(self, tableName, sqlQuery):
119120
Returns numpy recarray with results.
120121
"""
121122
t = self.tables[tableName]
122-
results = t.engine.execute(sqlQuery)
123+
results = t.engine.execute(text(sqlQuery))
123124
data = t._postprocess_results(results.fetchall())
124125
return data

python/lsst/sims/maf/db/Table.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import numpy as np
44
from sqlalchemy.engine import url
5-
from sqlalchemy import func
5+
from sqlalchemy import func, text
66
from sqlalchemy.sql import expression
77

88
import warnings
@@ -91,7 +91,7 @@ def query_columns_Iterator(self, colnames=None, chunk_size=None, constraint=None
9191
doGroupBy = not groupByCol is None
9292
query = self._get_column_query(doGroupBy, colnames=colnames)
9393
if constraint is not None:
94-
query = query.filter(constraint)
94+
query = query.filter(text(constraint))
9595

9696
if doGroupBy:
9797
#Either group by a column that gives unique visits

python/lsst/sims/maf/db/opsimDatabase.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def fetchPropInfo(self):
193193
# Find the 'ScienceType' from the config table, to indicate DD/WFD/Rolling, etc.
194194
table = self.tables['Config']
195195
sciencetypes = table.query_columns_Array(colnames=['paramValue', 'nonPropID'],
196-
constraint="paramName like 'ScienceType'")
196+
constraint="paramName like 'ScienceType'")
197197
if len(sciencetypes) == 0:
198198
# Then this was an older opsim run without 'ScienceType' tags,
199199
# so fall back to trying to guess what proposals are WFD or DD.
@@ -225,7 +225,8 @@ def fetchRunLength(self, runLengthParam='nRun'):
225225
runLength = 10.0
226226
else:
227227
table = self.tables['Config']
228-
runLength = table.query_columns_Array(colnames=['paramValue'], constraint=" paramName = '%s'"%runLengthParam)
228+
runLength = table.query_columns_Array(colnames=['paramValue'],
229+
constraint=" paramName = '%s'"%runLengthParam)
229230
runLength = float(runLength['paramValue'][0]) # Years
230231
return runLength
231232

@@ -241,11 +242,14 @@ def fetchLatLonHeight(self):
241242
height = site.elev
242243
else:
243244
table = self.tables['Config']
244-
lat = table.query_columns_Array(colnames=['paramValue'], constraint="paramName = 'latitude'")
245+
lat = table.query_columns_Array(colnames=['paramValue'],
246+
constraint="paramName = 'latitude'")
245247
lat = float(lat['paramValue'][0])
246-
lon = table.query_columns_Array(colnames=['paramValue'], constraint="paramName = 'longitude'")
248+
lon = table.query_columns_Array(colnames=['paramValue'],
249+
constraint="paramName = 'longitude'")
247250
lon = float(lon['paramValue'][0])
248-
height = table.query_columns_Array(colnames=['paramValue'], constraint="paramName = 'height'")
251+
height = table.query_columns_Array(colnames=['paramValue'],
252+
constraint="paramName = 'height'")
249253
height = float(height['paramValue'][0])
250254
return lat, lon, height
251255

@@ -352,7 +356,7 @@ def fetchRequestedNvisits(self, propId=None):
352356
for pId, propType in zip(propData[self.propIdCol], propData[self.propNameCol]):
353357
perPropConfig = self.tables['Config'].query_columns_Array(colnames=['paramName', 'paramValue'],
354358
constraint = 'nonPropID = %d and paramName!="userRegion"'
355-
%(pId))
359+
%(pId))
356360
filterlist = self._matchParamNameValue(perPropConfig, 'Filter')
357361
if propType == 'WL':
358362
# For WL proposals, the simple 'Filter_Visits' == the requested number of observations.
@@ -533,7 +537,8 @@ def fetchConfig(self):
533537
# Grab the config information for each proposal and module.
534538
cols = ['paramName', 'paramValue', 'comment']
535539
for longmodname, modname in zip(moduledata['moduleName'], modulenames):
536-
config[modname] = table.query_columns_Array(colnames=cols, constraint='moduleName="%s"' %(longmodname))
540+
config[modname] = table.query_columns_Array(colnames=cols,
541+
constraint='moduleName="%s"' %(longmodname))
537542
config[modname] = config[modname][['paramName', 'paramValue', 'comment']]
538543
for propid, propname in zip(propdata[self.propIdCol], propnames):
539544
config[propname] = table.query_columns_Array(colnames=cols,

0 commit comments

Comments
 (0)