Refactor I/O framework#659
Conversation
|
Ooh, I do like this. In the long term I intend to build this functionality into pyfits/io.fits directly. But in the meantime this could serve as a workaround. This could also add a format recognition method. So that |
|
Also, personally I might prefer to call the |
|
@iguananaut - actually there is already I don't think this should be a workaround for now in terms of the infrastructure (the FITS example I showed isn't actually in the code). This is intended to be long term code so that |
|
By the way, here's the docs for the current infrastructure (which lives in http://docs.astropy.org/en/latest/table/io.html#creating-a-custom-reader-writer it shows you can define 'identifier' functions. |
|
I've moved the docs for the I/O registry to |
|
+1 from me on the main idea of this PR! A few organizational thoughts, though: I definitely think it makes sense to have Regardless, @astrofrog - I'm not so sure about a separate "advanced" TOC... It's not clear to me what should go where. After all, users may well need to know some things about the configuration system (e.g., it might be useful to know runtime tricks once #556 gets merged). I had been thinking we indicate "advanced" by implication with something being lower down in the TOC (advanced or just niche, which is basically the same thing). |
|
@eteq - I agree with the idea of having a more-general top-level class, though I think for clarity there would be at least two files ( Of course, maybe having and this module could also contain the I/O. But is it too late to change that? (if we're going to do it, we should do it for 0.2). And would it be too messy inside that module? We could still keep most of the code inside say @eteq @wkerzendorf @taldcroft - what do you think? |
|
@eteq The |
|
@eteq @iguananaut - maybe the name |
|
Thinking of |
|
@taldcroft @iguananaut - I agree that it can be a mixin, in which case this layout is fine, but I was suggesting instead that we re-organized into a more traditional class hierarchy. With just what's here now that doesn't necessarily give us much, which is why I was suggesting adding the bit about I'm also concerned that a mixin is actually a somewhat advanced way of using OO, and a lot of our poor users who aren't quite as up-to-snuff on their design patterns might not understand what it's doing (and users will be interacting with these classes). That's not a reason on its own not to do this, but if we already have a reason (as I've implied above with So with that in mind, I like @astrofrog's suggestion of subsuming If we opt not to do this and stick with a mixin, it should be noted as such in the |
|
It is a true superclass, it's just not a strict superclass. I see no harm in educating users on multiple inheritance :) In any case most of them wouldn't even be aware of it--how many users are checking what base classes something has? I think everyone here would enjoy it, if you can find a spare 30 minutes at some point, to watch Raymond Hettinger's talk on subclassing from last year's PyCon: http://pyvideo.org/video/879/the-art-of-subclassing It seems very basic, and it is, but I but I found it very eye-opening nonetheless. It was definitely one of the most memorable for me. |
|
(note that @astrofrog has wisely moved the discussion of reorganizing |
|
I've now rebased this, and got rid of the base class for now. I think this is ready for a final review. |
|
This will have to be rebased again it looks like. |
|
Will do! |
…ss. This will allow it to be used for the NDData class as well as any other classes in future.
…ly to the Table and NDData classes.
|
I've rebased this! |
|
Okay. Finally ready to merge it looks like :) |
|
Awesome, thanks! |
Refactor I/O framework Conflicts: CHANGES.rst
Refactor I/O framework Conflicts: CHANGES.rst
Astropy Strategic Planning Committee Beta-Year Members
Astropy has two main data containers,
Table, andNDData, which are equivalent to structured and normal arrays in Numpy. It makes sense for these two objects to behave in a similar way - yet, the current I/O functionality is only implemented forTable.This PR takes the I/O code out of
Tableand instead puts it inastropy.io.registry. ADataIOclass is defined, and bothNDDataandTablethen inherit from it (as @taldcroft suggested off list, I think we need a better name thanDataIO). This made it very easy to extend the I/O stuff toNDData, although no readers/writers are defined inside Astropy currently. Here's an example of defining a (dumb) FITS reader:with the result:
The documentation still needs to be updated (the I/O page would be moved out of Table and moved to
io/registry.rst) but I wanted to first get some feedback on this.@eteq @taldcroft @iguananaut @mdboom - what do you think?
@iguananaut - I've tagged this 0.3. Of course, if it gets finalized soon, I don't see a reason it can't be put in 0.2 instead.