Repository navigation
Conversation
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
|
👋 Thank you for your draft pull request! Do you know that you can use |
7b5722c to
b1b0ee1
Compare
b1b0ee1 to
b1e192c
Compare
|
I'm not convinced that failures are related. In anywise I don't reproduce them locally. Might have something to do with pytest 8.0.0... |
b1e192c to
370c2e1
Compare
eerovaher
left a comment
There was a problem hiding this comment.
I am not doing a thorough review, I'm just commenting on a few things that stood out to me.
| # Deal with a subset of the columns, if requested. | ||
| if not columns: | ||
| colnumbers = list(range(len(fields))) | ||
| colnumbers = list(range(len(all_fields))) |
There was a problem hiding this comment.
Why is the conversion from range to list necessary?
There was a problem hiding this comment.
because range() produces a 1-time consumable iterator, but this variable is definitely used more than once.
There was a problem hiding this comment.
There is no limit to how many times a range instance can be iterated over:
>>> one_to_three = range(1, 4)
>>> for i in one_to_three:
... for j in one_to_three:
... print(i, j)
...
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3There was a problem hiding this comment.
Oh I didn't know that. Was it always true ?
There was a problem hiding this comment.
As far as I know this was true even for xrange in Python 2 (but I can't claim to know Python 2 very well).
I am willing to guess that quite a few people might believe a range to be single-use because they know that range does lazy evaluation and from that they conclude (mistakenly) that range must be a generator.
There was a problem hiding this comment.
that would make sense, I probably fell in that trap too.
| Only output user-requested columns in ``votable.parse``. | ||
| Previously, unselected columns would just be masked (and unallocated). |
There was a problem hiding this comment.
The recommended way to read VOTables is through the unified I/O interface, so I'd expect the change log entry to describe how that is affected.
|
@eerovaher This is far from redu for review (I actually left it in the middle of a refactor). I'll answer your questions tomorrow when I'm back at my desk ! |
63fd1ee to
cab61cf
Compare
|
It took me a while to complete, but I'm almost done with refactoring my initial wonky patch. After I'm sure that the refactor still survives CI, I'll squash my history. Next thing on the list is to make sure that |
19cddb9 to
5a26dbd
Compare
|
Okay I think this should now be ready for review. |
5a26dbd to
3bbb6d2
Compare
|
@eerovaher, do you have any other suggestions or requests ? also pinging @pllim as a package expert ! |
|
This would affect PyVO world the most, so I am asking a review from Tom D and maybe ping @lmichel too as a stakeholder. |
|
The MIVOT annotation readout in Astropy does not care about the table columns at all. It is a simple extension to the resource parsing that extracts a piece of XML. |
Co-authored-by: P. L. Lim <[email protected]>
84a5c05 to
8865d51
Compare
|
rebased ! |
| fields = self.fields | ||
| for i, field in enumerate(self.all_fields): | ||
| if i in colnumbers and field not in self.fields: | ||
| self.fields.append(field) |
There was a problem hiding this comment.
If this method is called repeatedly with different colnumbers, self.fields could end up out of order and with fields not in colnumbers. Also, for future protection if we lock down public access to self.fields, the append should probably be on self._fields (e.g., if later we do something like replace .append() with .add_field()).
If we do anything to fix this now, it should probably be to totally rebuild self.fields from colnumbers, but I'm uncomfortable with these side effects. Ideally creating arrays shouldn't modify any attributes of the table but also ideally the encapsulation (public vs. private) aspects of constructing a table could be cleaned up quite a bit, so I'm hesitant to do anything radical in this PR.
There was a problem hiding this comment.
good point. Reconstructing self._fields entirely seems safer and isn't really more complicated. How about this ?
diff --git a/astropy/io/votable/tree.py b/astropy/io/votable/tree.py
index 08dade28db..5df03cdf0e 100644
--- a/astropy/io/votable/tree.py
+++ b/astropy/io/votable/tree.py
@@ -2607,9 +2607,12 @@ class TableElement(
if colnumbers is None:
colnumbers = list(range(len(self.all_fields)))
- for i, field in enumerate(self.all_fields):
- if i in colnumbers and field not in self.fields:
- self.fields.append(field)
+ selected_fields = HomogeneousList(
+ Field,
+ values=[f for i, f in enumerate(self.all_fields) if i in colnumbers],
+ )
+ if self._fields != selected_fields:
+ self._fields = selected_fields
fields = self.all_fieldsWe could also add a warning if reconstruction is triggered.
There was a problem hiding this comment.
That implementation looks reasonable to me. It's interesting (and fine) that references to all_fields ensure that all_fields is caught up with anything in fields just prior to syncing in the other direction. (I'm not a huge fan of properties since they make such side-effects non-obvious, but that's my own hangup.)
I can see the motivation for a warning in that it would be an usual and possibly unexpected circumstance, but I also wonder if we could come up with succinct wording that a user could understand and act on. Unless the reconstruction happens due to a logic error we haven't noticed, the user would be doing some fairly unusual things to trigger this (as we'll see if you add a test case for this), so I think a warning is probably not worth the effort.
There was a problem hiding this comment.
I pushed it as is. Thank you so much for your thoughtful review !
There was a problem hiding this comment.
Thank you for doing the work and being so responsive to questions and comments! Could you go ahead and create an issue for the proposed follow-on deprecation patch?
There was a problem hiding this comment.
It's getting late, but this will be top of my task list for tomorrow !
There was a problem hiding this comment.
No worries. I opened #16314 for you. Feel free to add details there tomorrow as you see fit. Thanks!
|
Thanks, all! |
* TST: add a regression test for bug 14943 * TST: adjust existing tests * API: only output user-requested columns in votable.parse * raise an error when encountering a 'FITS' table while requesting specific columns (unsupported case) * TST: add a test case for parsing VOTable as binary with selected columns * BUG: fix support for parting VOTable as binary with selected columns * RFC: remove 'fields' argument from TableElement._parse_* private methods (use the internal state instead) * TST: replace repetition with parametrization * remove unnecessary type annotation * CLN: cleanup unneeded __future__ import * RFC: fix a broken reference name * fix typo * keep all_fields in sync with fields attribute as much as possible * consistent use of del Co-authored-by: P. L. Lim <[email protected]> * improve comment * update docstring and changelog * a more robust impl of TableElement.create_arrays --------- Co-authored-by: P. L. Lim <[email protected]>
msdemlei
left a comment
There was a problem hiding this comment.
Disclaimer: I don't know enough about astropy's VOTable implementation to confidently say I could spot subtle issues, and I certainly would not have thought about the problem with the column order in all_fields. Having said that, I agree with this PR's intent, and the implementation is sane and reasonably clear.
I also agree that appending to fields should be deprecated. For incrementally building table contents, there's astropy.Table itself, and I don't see an overriding reason to enable this in VOTable. There are certainly good reasons to keep VOTable metadata mutable elsewhere (PARAM-s, GROUP-s, INFO-s, etc). But since mutability is a curse, we should not have it where there are good alternatives.
|
On Tue, Aug 20, 2024 at 12:10:00AM -0700, Clément Robert wrote:
> I also agree that appending to fields should be deprecated.
@msdemlei maybe you meant to comment directly on #16316 ?
Not really; I had not bothered to check whether this one was already
merged, and I was asked to review it. If there's any dissent about
the deprecation, I'll be happy to repeat my endorsement there...
|
|
Thanks for the comments. Would help for future reference regardless. |
Description
Fixes #14943
I took me a couple hours to pass my test and all other tests locally, so I'm opening the PR while iron is hot, but I expect I'll probably want to refactor a bit before I open to review.
Since I needed to adjust existing tests which were actively checking for previous behaviour, I'm marking this as an API change, but in my opinion it's borderline a bug fix. In other words, I'm aiming astropy 6.1.0, not 6.0.1.