Skip to content

Commit 4241d61

Browse files
committed
FIX: improved detection of ascii fast_reader in non-fast parsers and guess
With the fast_reader arg explicitly set in io.ascii.read make _get_reader raise a ParameterError if called for a slow reader, and in _guess always call fast versions first. Have kwargs always updated from a safe copy in the _guess loop to avoid getting dictionary args wiped out or overwritten. C parser now generally working without forcing `guess=False` and with autodetection of most formats, updated docs accordingly. Tests for Fortran-exponent options and new fast_reader behaviour extended. Added `rtol` and `atol` kwargs to `assert_table_equal` and `assert_almost_equal` to override the rather lax `np.allclose` defaults.
1 parent 63f148f commit 4241d61

7 files changed

Lines changed: 250 additions & 87 deletions

File tree

‎astropy/io/ascii/core.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1345,8 +1345,17 @@ def _get_reader(Reader, Inputter=None, Outputter=None, **kwargs):
13451345
kwargs['Inputter'] = Inputter
13461346
return Reader(**kwargs)
13471347

1348+
# If user explicitly passed a fast reader with 'force' or with non-default
1349+
# options for the fast reader, raise an error for slow readers
13481350
if 'fast_reader' in kwargs:
1349-
del kwargs['fast_reader'] # ignore fast_reader parameter for slow readers
1351+
if kwargs['fast_reader'] == 'force' or \
1352+
isinstance(kwargs['fast_reader'] , dict):
1353+
raise ParameterError('fast_reader required with ' +
1354+
'{0}, but this is a slow reader: {1}'
1355+
.format(kwargs['fast_reader'], Reader))
1356+
else:
1357+
del kwargs['fast_reader'] # otherwise ignore fast_reader parameter
1358+
13501359
reader_kwargs = dict([k, v] for k, v in kwargs.items() if k not in extra_reader_pars)
13511360
reader = Reader(**reader_kwargs)
13521361

‎astropy/io/ascii/cparser.pyx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,12 @@ cdef class CParser:
386386
data_end = max(self.data_end - self.data_start, 0) # read nothing if data_end < 0
387387

388388
if tokenize(self.tokenizer, data_end, 0, <int>len(self.names)) != 0:
389-
self.raise_error("an error occurred while parsing table data")
389+
if self.tokenizer.code in (NOT_ENOUGH_COLS, TOO_MANY_COLS):
390+
raise core.InconsistentTableError("Number of header columns " +
391+
"({0}) inconsistent with data columns in data line {1}"
392+
.format(self.tokenizer.num_cols, self.tokenizer.num_rows))
393+
else:
394+
self.raise_error("an error occurred while parsing table data")
390395
elif self.tokenizer.num_rows == 0: # no data
391396
return ([np.array([], dtype=np.int_)] * self.width, [])
392397
self._set_fill_values()

0 commit comments

Comments
 (0)