Skip to content

Commit 4786798

Browse files
committed
Getting rid of unnecessary string formatting, probably some of the str() are also unnecessary, but leaving them for the future
1 parent 5d93949 commit 4786798

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

astroquery/cosmosim/core.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def run_sql_query(self, query_string, tablename=None, queue=None,
221221
result = self._request('POST', CosmoSim.QUERY_URL,
222222
auth=(self.username, self.password),
223223
data={'query': query_string,
224-
'table': '{}'.format(tablename),
224+
'table': str(tablename),
225225
'phase': 'run', 'queue': queue},
226226
cache=cache)
227227
self._existing_tables()
@@ -251,7 +251,7 @@ def _existing_tables(self):
251251
for i in soup.find_all("uws:jobref"):
252252
jobid = i.get('xlink:href').split('/')[-1]
253253
if jobid in completed_jobs:
254-
self.table_dict[jobid] = '{}'.format(i.get('id'))
254+
self.table_dict[jobid] = str(i.get('id'))
255255

256256
def check_job_status(self, jobid=None):
257257
"""
@@ -328,7 +328,7 @@ def check_all_jobs(self, phase=None, regex=None, sortby=None):
328328
self.job_dict['{0}'.format(i.get('xlink:href')
329329
.split('/')[-1])] = i_phase
330330
else:
331-
self.job_dict['{}'.format(i.get('id'))] = i_phase
331+
self.job_dict[str(i.get('id'))] = i_phase
332332

333333
if phase:
334334
phase = [phase[i].upper() for i in range(len(phase))]
@@ -630,8 +630,8 @@ def _starttime_dict(self):
630630
for i in range(len(response_list))]
631631
self.starttime_dict = {}
632632
for i in range(len(soups)):
633-
self.starttime_dict['{}'.format(completed_ids[i])] = (
634-
'{}'.format(soups[i].find('uws:starttime').string))
633+
self.starttime_dict[str(completed_ids[i])] = str(
634+
soups[i].find('uws:starttime').string)
635635

636636
def general_job_info(self, jobid=None, output=False):
637637
"""
@@ -836,16 +836,16 @@ def _generate_schema(self):
836836
data = response.json()
837837
self.db_dict = {}
838838
for i in range(len(data['databases'])):
839-
self.db_dict['{}'.format(data['databases'][i]['name'])] = {}
839+
self.db_dict[str(data['databases'][i]['name'])] = {}
840840

841-
sstr = '{}'.format(data['databases'][i]['name'])
842-
sid = '{}'.format(data['databases'][i]['id'])
841+
sstr = str(data['databases'][i]['name'])
842+
sid = str(data['databases'][i]['id'])
843843
self.db_dict[sstr]['id'] = sid
844-
sdesc = '{}'.format(data['databases'][i]['description'])
844+
sdesc = str(data['databases'][i]['description'])
845845
self.db_dict[sstr]['description'] = sdesc
846846
self.db_dict[sstr]['tables'] = {}
847847
for j in range(len(data['databases'][i]['tables'])):
848-
sstr2 = '{}'.format(data['databases'][i]['tables'][j]['name'])
848+
sstr2 = str(data['databases'][i]['tables'][j]['name'])
849849
self.db_dict[sstr]['tables'][sstr2] = {}
850850
sdata = data['databases'][i]['tables'][j]['id']
851851
self.db_dict[sstr]['tables'][sstr2]['id'] = sdata
@@ -856,7 +856,7 @@ def _generate_schema(self):
856856
for k in range(tmpval):
857857
sdata2 = data['databases'][i]['tables'][j]['columns'][k]
858858
sdata2_id = sdata2['id']
859-
sstr3 = '{}'.format(sdata2['name'])
859+
sstr3 = str(sdata2['name'])
860860

861861
sdesc3 = sdata2['description']
862862
self.db_dict[sstr]['tables'][sstr2]['columns'][sstr3] = {
@@ -900,7 +900,7 @@ def explore_db(self, db=None, table=None, col=None):
900900
proj_list += (['@ {}'.format(proj)] +
901901
['' for i in range(size - 1)] +
902902
['-' * (largest + 2)])
903-
tmp_largest = max([len('{}'.format(key))
903+
tmp_largest = max([len(str(key))
904904
for key in self.db_dict[proj].keys()])
905905
attr_list += (['@ {}'.format(key)
906906
if isinstance(self.db_dict[proj][key], dict)
@@ -926,7 +926,7 @@ def explore_db(self, db=None, table=None, col=None):
926926
# db specified
927927
if db:
928928
try:
929-
size1 = len(self.db_dict['{}'.format(db)].keys())
929+
size1 = len(self.db_dict[str(db)].keys())
930930
slist = [self.db_dict[db][key].keys()
931931
if isinstance(self.db_dict[db][key], dict)
932932
else key
@@ -967,7 +967,7 @@ def explore_db(self, db=None, table=None, col=None):
967967
if (isinstance(self.db_dict[db][key], dict) and
968968
(len(self.db_dict[db][key].keys()) !=
969969
len(self.db_dict[db]['tables'].keys())))
970-
else '{}'.format(key)
970+
else str(key)
971971
for key in self.db_dict[db].keys()] +
972972
['' for i in range(size2 - size1)])
973973
# if only db is specified
@@ -977,12 +977,12 @@ def explore_db(self, db=None, table=None, col=None):
977977
t['Tables'] = ['@ {}'.format(i)
978978
if isinstance(self.db_dict[db]['tables'][i],
979979
dict)
980-
else '{}'.format(i)
980+
else str(i)
981981
for i in reordered]
982982
# if table has been specified
983983
else:
984984
reordered = (
985-
['{}'.format(table)] +
985+
[str(table)] +
986986
sorted([key for key in self.db_dict[db]['tables'].keys()
987987
if key != table], key=len))
988988
t['Tables'] = (
@@ -992,7 +992,7 @@ def explore_db(self, db=None, table=None, col=None):
992992
else '@ {}'.format(i)
993993
if (i != table and
994994
isinstance(self.db_dict[db]['tables'][i], dict))
995-
else '{}'.format(i)
995+
else str(i)
996996
for i in reordered] +
997997
['' for j in range(size2 - len(reordered))])
998998

@@ -1005,7 +1005,7 @@ def explore_db(self, db=None, table=None, col=None):
10051005
['' for j in range(size2 - len(tblcols_dict))])
10061006
col_dict = (self.db_dict[db]['tables'][table]
10071007
['columns'].keys())
1008-
reordered = (['{}'.format(col)] +
1008+
reordered = ([str(col)] +
10091009
[i for i in col_dict if i != col])
10101010

10111011
temp_columns = []
@@ -1020,7 +1020,7 @@ def explore_db(self, db=None, table=None, col=None):
10201020
elif isinstance(c, dict) and i != col:
10211021
temp_columns.append('@ {}'.format(i))
10221022
else:
1023-
temp_columns.append('{}'.format(i))
1023+
temp_columns.append(str(i))
10241024

10251025
if len(col_dict) < size2:
10261026
size_diff = size2 - len(col_dict)
@@ -1049,15 +1049,15 @@ def explore_db(self, db=None, table=None, col=None):
10491049
else '{}:'.format(i) for i in tblcols_dict] +
10501050
['' for i in range(size_diff)])
10511051
t['Table Info'] = (
1052-
['{}'.format(tmp_table[i])
1052+
[str(tmp_table[i])
10531053
if not isinstance(tmp_table[i], dict)
10541054
else '' for i in tblcols_dict] +
10551055
['' for i in range(size_diff)])
10561056
if len(col_dict) < size2:
10571057
t['Columns'] = (
10581058
['@ {}'.format(i)
10591059
if isinstance(tmp_table['columns'][i], dict)
1060-
else '{}'.format(i)
1060+
else str(i)
10611061
for i in reordered] +
10621062
['' for i in range(size2 - len(col_dict))])
10631063
else:
@@ -1098,7 +1098,7 @@ def download(self, jobid=None, filename=None, format=None, cache=True):
10981098
"this session.")
10991099
return
11001100

1101-
if self.job_dict['{}'.format(jobid)] == 'COMPLETED':
1101+
if self.job_dict[str(jobid)] == 'COMPLETED':
11021102
if not format:
11031103
warnings.warn("Must specify a format:")
11041104
t = Table()
@@ -1199,7 +1199,7 @@ def _check_phase(self, jobid):
11991199
return
12001200

12011201
else:
1202-
phase = self.job_dict['{}'.format(jobid)]
1202+
phase = self.job_dict[str(jobid)]
12031203
return phase
12041204

12051205
def _mail(self, to, subject, text, *attach):
@@ -1255,8 +1255,8 @@ def _text(self, fromwhom, number, text):
12551255
server = smtplib.SMTP("smtp.gmail.com", 587)
12561256
server.starttls()
12571257
server.login(self._smsaddress, self._smspw)
1258-
server.sendmail('{}'.format(fromwhom), '{}@vtext.com'.format(number),
1259-
'{}'.format(text))
1258+
server.sendmail(str(fromwhom), '{}@vtext.com'.format(number),
1259+
str(text))
12601260
server.quit()
12611261

12621262
def _initialize_alerting(self, jobid, mail=None, text=None):

0 commit comments

Comments
 (0)