Skip to content

io.ascii: improve guessing when format is specified - #3418

Merged
taldcroft merged 7 commits into
astropy:masterfrom
taldcroft:io-ascii-guess
Feb 15, 2015
Merged

taldcroft merged 7 commits into
astropy:masterfrom
taldcroft:io-ascii-guess

Conversation

@taldcroft

Copy link
Copy Markdown
Member

When trying to read a large table yesterday I noticed that if I did:

t = Table.read('sometable.tbl', format='ascii.ipac')

io.ascii was still trying to guess the format and I had to use

t = Table.read('sometable.tbl', format='ascii.ipac', guess=False)

to prevent the guessing. Should specifying the format not disable guessing?

@taldcroft

Copy link
Copy Markdown
Member

@astrofrog - the format specifier is just a filter on one of the read parameters in the full guess list. Many of the basic formats have other parameters (e.g. delimiter, quotechar) that need to be guessed so you can't just turn off guessing in advance if format is provided.

The knowledge that a reader class doesn't have any additional guessable parameters is currently coded in the guess routine. We could refactor a bit so that the reader class knows how to guess itself and in that way disable guessing at the ui.read level.

@hamogu

hamogu commented Feb 8, 2015

Copy link
Copy Markdown
Member

For some formats there is also a fast and a slow reader. Guessing will try the fast reader first, if it exists.

If there is really only one reader and that trader has no options, then the reading still goes through the guess function, but that function should simply call the reader in question. I don't think that we gain any performance by implementing logic to decide if guessing is needed instead of iterating over a list of one reader.
What we could do, however, is the check how many readers are on the guess list and if it is only one, set guess=false because that gives a more meaningful error message if the reading fails.

Comment thread astropy/io/ascii/ui.py Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line eliminates duplicate guesses. It turns out in some cases the basic format could have 3 or 4 repeats.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder how thee repeats happen in the first case? I remember that I looked into the guessing a while ago when I changed the order in which formats are tried in guessing, and I definitely remember that this is no easy logic. I'm not oppsed to fixing it in ths way if that is the best solution, I just wonder if this points to some deeper problem or if you know why basic is in there multiple times.

@taldcroft

Copy link
Copy Markdown
Member

@astrofrog @hamogu - code attached.

At the beginning of _guess there was a code block that tries to read the
`table` input as a file or readable file object.  This was moved up one
level from _guess so that if there is just one guess_kwargs then the same
already-read `table` is used for the non-guess reading path.
Comment thread astropy/io/ascii/ui.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is only one format, why should we return None? It is possible that an imcomplete set of options (delimiter etc.) is passed into guess and guess substituted default values for other options. In that case, _guess did something and I would expect it to return something.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see why you did it and I think itś a clever way to do it, but its logic might need a comment or two to explain.

@taldcroft

Copy link
Copy Markdown
Member

@hamogu - good idea with better docs and comments, since I am regularly confused by what's happening each time I look at the code after a break. I took a crack at this in 899d70c.

@taldcroft

Copy link
Copy Markdown
Member

@hamogu - see also 7d0bbc4, which in the end seemed more clear when I tried to write docstrings.

@hamogu

hamogu commented Feb 15, 2015 via email

Copy link
Copy Markdown
Member

@taldcroft taldcroft changed the title io.ascii: why is guessing used even if format is specified? io.ascii: improve guessing when format is specified Feb 15, 2015
taldcroft added a commit that referenced this pull request Feb 15, 2015
io.ascii: improve guessing when format is specified
@taldcroft
taldcroft merged commit 68a95f7 into astropy:master Feb 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants