-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
While trying to read in a Latex table I copied-and-pasted from an arXiv paper, I learned an oddity: the Latex reader fails with an obscure error if you just put in the contents of a latex table (see stack trace at the end. I see no reason why it shouldn't be possible to have it parse Latex style tables without the \begin{table}/\begin{tabular}{ccccccccccc} and corresponding \end commands. It doesn't even seem to care how many markers you have in \tabular, so it's not using the header for anything. So it should be possible to just past in the table data and have it parse, rather than having to add the \begin \end commands around the content.
This could be construed as part of #1525, although that's a bit more wide-ranging and this is one particular thing in that direction.
Stack trace from attempting to Table.read(...,format='latex') just the content of a Latex table:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-43-e9b3cdb9f6d8> in <module>()
32 """.replace('~','').replace('\,', '').replace('$', '')
33
---> 34 k15_tab2 = table.Table.read(k15_tab2_data.split('\n'), format='latex', names=k15_tab2_colnames, guess=False)
35 k15_tab2
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astropy/table/table.pyc in read(cls, *args, **kwargs)
1896 passed through to the underlying data reader (e.g. `~astropy.io.ascii.read`).
1897 """
-> 1898 return io_registry.read(cls, *args, **kwargs)
1899
1900 def write(self, *args, **kwargs):
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astropy/io/registry.pyc in read(cls, *args, **kwargs)
330
331 reader = get_reader(format, cls)
--> 332 data = reader(*args, **kwargs)
333
334 if not isinstance(data, cls):
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astropy/io/ascii/connect.pyc in io_read(format, filename, **kwargs)
35 from .ui import read
36 format = re.sub(r'^ascii\.', '', format)
---> 37 return read(filename, format=format, **kwargs)
38
39
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astropy/io/ascii/ui.pyc in read(table, guess, **kwargs)
273 dat = reader.read(table)
274 else:
--> 275 dat = reader.read(table)
276
277 return dat
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astropy/io/ascii/core.pyc in read(self, table)
1038
1039 # Set self.data.data_lines to a slice of lines contain the data rows
-> 1040 self.data.get_data_lines(self.lines)
1041
1042 # Extract table meta values (e.g. keywords, comments, etc). Updates self.meta.
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astropy/io/ascii/core.pyc in get_data_lines(self, lines)
614 table data values."""
615 data_lines = self.process_lines(lines)
--> 616 start_line = _get_line_index(self.start_line, data_lines)
617 end_line = _get_line_index(self.end_line, data_lines)
618
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astropy/io/ascii/core.pyc in _get_line_index(line_or_func, lines)
399
400 if hasattr(line_or_func, '__call__'):
--> 401 return line_or_func(lines)
402 elif line_or_func:
403 if line_or_func >= 0:
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astropy/io/ascii/latex.pyc in start_line(self, lines)
151 return find_latex_line(lines, self.data_start)
152 else:
--> 153 return self.header.start_line(lines) + 1
154
155 def end_line(self, lines):
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'