"OverflowError: Python int too large to convert to C long" with astropy.table -
i want read simple table, using astropy.table. first element of line large integer. fails, error message: "overflowerror: python int large convert c long". how can avoid this?
details:
the table in test.cat. simple, 1 line: 81421100001 2 1 1 37.5991 1.0213 785.364 539.291
here code use:
import numpy np astropy.table import table catalog_filename = 'test.cat' t = table.read(catalog_filename, format='ascii')
i receive following error:
traceback (most recent call last): file "catread.py", line 15, in <module> t = table.read(catalog_filename, format='ascii') file "/usr/local/lib/python2.7/dist-packages/astropy/table/table.py", line 2561, in read return io_registry.read(cls, *args, **kwargs) file "/usr/local/lib/python2.7/dist-packages/astropy/io/registry.py", line 319, in read table = reader(*args, **kwargs) file "/usr/local/lib/python2.7/dist-packages/astropy/io/ascii/connect.py", line 18, in read_asciitable return read(filename, **kwargs) file "/usr/local/lib/python2.7/dist-packages/astropy/io/ascii/ui.py", line 154, in read dat = _guess(table, new_kwargs) file "/usr/local/lib/python2.7/dist-packages/astropy/io/ascii/ui.py", line 196, in _guess dat = reader.read(table) file "/usr/local/lib/python2.7/dist-packages/astropy/io/ascii/core.py", line 872, in read table = self.outputter(cols, self.meta) file "/usr/local/lib/python2.7/dist-packages/astropy/io/ascii/core.py", line 670, in __call__ self._convert_vals(cols) file "/usr/local/lib/python2.7/dist-packages/astropy/io/ascii/core.py", line 652, in _convert_vals col.data = converter_func(col.str_vals) file "/usr/local/lib/python2.7/dist-packages/astropy/io/ascii/core.py", line 611, in converter return numpy.array(vals, numpy_type) overflowerror: python int large convert c long
as mentioned above, astropy issue (https://github.com/astropy/astropy/issues/2234) , there proposed fix automatically fall string in case of overflow. in meantime can instruct ascii.read
function use specific numpy dtype converting column text string final table column. use converters
keyword arg below.
>>> ascii.read(['8142110000100000000 1 2 3'], converters={'col1': [ascii.convert_numpy(np.int64)]}) <table rows=1 names=('col1','col2','col3','col4')> array([(8142110000100000000, 1, 2, 3)], dtype=[('col1', '<i8'), ('col2', '<i8'), ('col3', '<i8'), ('col4', '<i8')]) >>> ascii.read(['8142110000100000000 1 2 3'], converters={'col1': [ascii.convert_numpy(np.float)]}) <table rows=1 names=('col1','col2','col3','col4')> array([(8.1421100001e+18, 1, 2, 3)], dtype=[('col1', '<f8'), ('col2', '<i8'), ('col3', '<i8'), ('col4', '<i8')])
Comments
Post a Comment