Skip to content

Commit 878ba33

Browse files
committed
Simplify converting simbad results to Table
`SimbadBibcodeResult.table` and `SimbadObjectIDsResult.table` have been simplified. Most importantly they no longer construct the required `Table` row-by-row because adding rows to a `Table` is expensive.
1 parent d487aaa commit 878ba33

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

astroquery/simbad/core.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -202,25 +202,20 @@ class SimbadBibcodeResult(SimbadResult):
202202
"""Bibliography-type Simbad result"""
203203
@property
204204
def table(self):
205-
bibcode_match = bibcode_regex.search(self.script)
206-
splitter = bibcode_match.group(2)
207-
ref_list = [splitter + ref for ref in self.data.split(splitter)][1:]
208-
max_len = max([len(r) for r in ref_list])
209-
table = Table(names=['References'], dtype=['U%i' % max_len])
210-
for ref in ref_list:
211-
table.add_row([ref])
212-
return table
205+
splitter = bibcode_regex.search(self.script).group(2)
206+
ref_list = [[splitter + ref] for ref in self.data.split(splitter)[1:]]
207+
max_len = max(len(r[0]) for r in ref_list)
208+
return Table(rows=ref_list, names=['References'], dtype=[f"U{max_len}"])
213209

214210

215211
class SimbadObjectIDsResult(SimbadResult):
216212
"""Object identifier list Simbad result"""
217213
@property
218214
def table(self):
219-
max_len = max([len(i) for i in self.data.splitlines()])
220-
table = Table(names=['ID'], dtype=['S%i' % max_len])
221-
for id in self.data.splitlines():
222-
table.add_row([id.strip()])
223-
return table
215+
split_lines = self.data.splitlines()
216+
ids = [[id.strip()] for id in split_lines]
217+
max_len = max(map(len, split_lines))
218+
return Table(rows=ids, names=['ID'], dtype=[f"S{max_len}"])
224219

225220

226221
class SimbadBaseQuery(BaseQuery):

0 commit comments

Comments
 (0)