Repository navigation
Better docs and infrastructure for unified read/write functions - #8255
Conversation
|
|
||
| return dat | ||
|
|
||
| read.__doc__ = core.READ_DOCSTRING |
There was a problem hiding this comment.
Needed to avoid circular import.
|
Yes to having this information! A possible alternative implementation might be to have To implement this, One advantage would be that it is more discoverable. Arguably, it is also a bit more pythonic, but it may well be too tricky to get right... Certainly your implementation here has the benefit of simplicity! |
|
@mhvk - very nice idea, I like it on every level! The main question is whether the implementation can be kept manageable. Mostly I think it isn't too bad, but there is the issue of the hierarchy of readers, namely: So presumably a At that point one starts to think about solving the whole issue where the table |
|
Yes, indeed, I do worry about the implementation. Though I don't think there is a need to "pre-import" too much - that can be done in the The recursion may be trickier, as one wants to be sure not to reimplement things that python and/or the io registry already do - indeed, this is partially why I wondered if we could push part of this up to |
astrofrog
left a comment
There was a problem hiding this comment.
I don't think using attribute notation would necessarily work since some formats (defined outside astropy) may not have Python-variable-compliant names?
In any case, this here is much better than the current situation, so I would actually propose that we consider merging this and then consider making more substantial changes if we really want.
This should be mentioned in the unified I/O docs though (and anywhere Table.read is mentioned and in the Table.read docstring)
| if format and not args and not kwargs: | ||
| reader = io_registry.get_reader(format, cls) | ||
| reader_doc = ('Table.read() general documentation\n' | ||
| '==================================\n') |
There was a problem hiding this comment.
The headings don't look quite right - the top heading seems a bit 'stuck' to the Table.read call - maybe try with heading lines above too? (since I guess we don't need to be ReST compliant here?)
|
Good points @astrofrog. I suspect in the wild there are not many (probably zero) user-defined formats that have a name that doesn't work as an attribute. The most likely problem is But the issue of just getting something that works without going crazy (given the reality of time constraints) is well-taken. I can clean this implementation up a bit, include the writers, and we'll see where it goes. |
astrofrog
left a comment
There was a problem hiding this comment.
@taldcroft - this looks great! In addition to the in-line comments, one thing I was wondering was whether when a user does:
Table.read.help('ascii')
it would make sense to just show the format-specific docs, but to include a sentence saying that for general information about the read method, just to do Table.read.help()? As a user, I feel like the workflow I might follow is to first check the help for Table.read, then to find out that I can do Table.read.help('ascii') so I don't necessarily want to see the general docs again. Alternatively, you could swap the order to have the format-specific docs first?
| see: https://github.com/astropy/astropy-APEs/blob/master/APE6.rst. | ||
| """ECSV (Enhanced Character Separated Values) format table. | ||
|
|
||
| Th ECSV format allows for specification of key table and column meta-data, in |
| This parameter is ignored when the ``output`` arg is not a string | ||
| (e.g., a file object). | ||
| Writer : ``Writer`` | ||
| Writer class (DEPRECATED). |
There was a problem hiding this comment.
I wonder if it's time to finally remove Reader/Writer?
| output : str, file_like | ||
| Output [filename, file-like object]. Defaults to``sys.stdout``. | ||
| format : str | ||
| Output table format. Defaults to 'basic'. |
There was a problem hiding this comment.
I wonder whether when this docstring is used for a specific format it would make sense to not list format? In other words, maybe that is a keyword that is specific to the generic read and write methods?
There was a problem hiding this comment.
Good point but I can't think of a clean and easy way to handle this. For now I'd just say to live with this.
| Get help on the writer for a particular format (e.g. 'fits') using the | ||
| ``help()`` method:: | ||
|
|
||
| >>> CCDData.write.help('fits') # Get detailed help on FITS writer |
There was a problem hiding this comment.
I wonder if we should also provide a way and document how to get a list of available format
| details on the implementation see :ref:`io_registry`. | ||
|
|
||
| Getting started with Image I/O | ||
| ============================== |
There was a problem hiding this comment.
What is the rationale for having this section here? Should it not be in the CCDData docs?
There was a problem hiding this comment.
The rationale was that the Unified I/O was never supposed to be just for Table, so I'm trying to make the docs more inclusive / symmetric with Table.
| .format(cls.__name__, method_name)) | ||
| reader_doc = re.sub('.', '=', header) | ||
| reader_doc += header | ||
| reader_doc += re.sub('.', '=', header) |
There was a problem hiding this comment.
Can you add a newline after the heading? That is,
================================
Table.read general documentation
================================
Read and parse a data table and return as a Table.
instead of
================================
Table.read general documentation
================================
Read and parse a data table and return as a Table.
|
|
||
| Notes | ||
| ----- | ||
|
|
There was a problem hiding this comment.
Maybe remove the newline here? At the moment this has too many newlines in some cases:
Notes
-----
The available built-in formats are:
|
@astrofrog - I think I have addressed all your comments. |
bsipocz
left a comment
There was a problem hiding this comment.
My main comment is that using intersphinx linking rather than hard wired urls is preferable.
The other comment is whether it's possible to change the order of the doc, so the format specific part comes up before the generic one.
The rest is then just nitpicking.
| ---------- | ||
| table : str, file-like, list, pathlib.Path object | ||
| Input table as a file name, file-like object, list of strings, | ||
| single newline-separated string or pathlib.Path object . |
|
|
||
| Reader : `~astropy.io.ascii.BaseReader` | ||
| Reader class (DEPRECATED) | ||
| encoding: str |
There was a problem hiding this comment.
| encoding: str | |
| encoding : str |
| table for each chunk. The default is to return a single stacked table | ||
| for all the chunks. | ||
|
|
||
| Reader : `~astropy.io.ascii.BaseReader` |
There was a problem hiding this comment.
I think we normally remove the deprecated parameters from the docstring when they get deprecated. Same for Writer below.
|
|
||
| See also: | ||
|
|
||
| - http://docs.astropy.org/en/stable/io/ascii/ |
There was a problem hiding this comment.
same here, if possible use intersphinx instead
|
@bsipocz - comments all addressed, I think. |
Codecov Report
@@ Coverage Diff @@
## master #8255 +/- ##
=========================================
Coverage ? 86.89%
=========================================
Files ? 399
Lines ? 59197
Branches ? 1100
=========================================
Hits ? 51442
Misses ? 7114
Partials ? 641
Continue to review full report at Codecov.
|
|
Thanks @taldcroft! |
|
Please rebase to resolve conflicts. |
|
Rebased, this should be now good to go. |
This PR is a decent-sized update to the unified I/O infrastructure, with the main driver being to make it possible to get format-specific documentation in a simple way. This is done with (e.g.):
This prints output to the console via a pager (
pydoc.pager) and includes the generic read/write interface help and format-specific docs.In order to make the
read.helpandwrite.helpmethods in a clean way I ended up with some new general-purpose infrastructure for defining read and write methods as class descriptors. Along the way I cleaned up theio.asciidocs to make them more consistent within this framework.I also did cleanup of the Table registry by removing the custom-installed 'ascii' and 'csv' entry points in favor of generic mechanisms now in place.
NOTE for future readers: the comments up through #8255 (comment) are mostly overtaken by the new code.