Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for QTable #384

Merged
merged 3 commits into from
Jan 16, 2023
Merged

Added support for QTable #384

merged 3 commits into from
Jan 16, 2023

Conversation

andamian
Copy link
Contributor

@andamian andamian commented Nov 1, 2022

@andamian andamian added this to the v1.5 milestone Nov 1, 2022
@codecov
Copy link

codecov bot commented Nov 1, 2022

Codecov Report

Merging #384 (cf511b2) into main (a7f247f) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main     #384   +/-   ##
=======================================
  Coverage   78.55%   78.56%           
=======================================
  Files          47       47           
  Lines        5564     5565    +1     
=======================================
+ Hits         4371     4372    +1     
  Misses       1193     1193           
Impacted Files Coverage Δ
pyvo/dal/query.py 84.84% <100.00%> (+0.07%) ⬆️
pyvo/utils/vocabularies.py 65.51% <0.00%> (-1.15%) ⬇️
pyvo/registry/rtcons.py 97.67% <0.00%> (-0.02%) ⬇️
pyvo/dal/adhoc.py 66.27% <0.00%> (ø)
pyvo/dal/params.py 86.38% <0.00%> (ø)
pyvo/registry/regtap.py 78.94% <0.00%> (ø)
pyvo/utils/prototype.py 100.00% <0.00%> (ø)
pyvo/utils/protofeature.py 100.00% <0.00%> (ø)
pyvo/utils/xml/elements.py 93.77% <0.00%> (ø)
pyvo/io/vosi/vodataservice.py 87.02% <0.00%> (ø)
... and 1 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@andamian andamian marked this pull request as ready for review November 1, 2022 23:46
Copy link
Contributor

@msdemlei msdemlei left a comment

Choose a reason for hiding this comment

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

Looks fine, thanks!

Copy link
Member

@bsipocz bsipocz left a comment

Choose a reason for hiding this comment

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

I still wonder why not change to_table to return a QTable?

#381 (comment)

@msdemlei
Copy link
Contributor

msdemlei commented Nov 2, 2022 via email

@bsipocz
Copy link
Member

bsipocz commented Nov 2, 2022

If you're reasonably sure Table-expecting code won't break when faced with QTable

QTable is a subclass of Table, so it all should be fine. There is certainly an overhead of creating the mixin columns, but I don't think it would be a significant factor for the use cases here.

However, one issue could be is there are columns with non-valid units, those may throw warnings or are rendered as unknown. But IMO those are all upstream issues, ideally, VO services return valid VO units only.

@bsipocz
Copy link
Member

bsipocz commented Nov 2, 2022

I'm pinging @taldcroft here, he can comment more on the nuances.

@andamian
Copy link
Contributor Author

andamian commented Nov 2, 2022

@bsipocz the return types are not compatible anymore and might break existing client code. For example:

res.to_table()[0]['s_ra'] > 1
True
res.to_qtable()[0]['s_ra'] > 1
{UnitConversionError}Can only apply 'greater' function to dimensionless quantities when other argument is not a quantity (unless the latter is all zero/infinity/nan)

@bsipocz
Copy link
Member

bsipocz commented Nov 2, 2022

on the other hand, all of those s_ra columns have a unit (does it fixed in the standard, or could be different for different services?), so raising that exception may not be that bad of a feature, but a way to prevent a possible bug for erroneous user assumptions.

@msdemlei
Copy link
Contributor

msdemlei commented Nov 2, 2022 via email

@bsipocz
Copy link
Member

bsipocz commented Nov 2, 2022

code that's arguably not unreasonable.

I would argue that this is exactly the case of an unreasonable code, after all, space probes got lost due to false unit assumptions. If we must support such a use case, I would make it opt-in, e.g. adding a no_units kwarg to to_table(). I know that it's a significant API change, to both change its return of a QTable, and adding a kwarg, but I think it would be worth it.

Also, I don't share the notion that methods are cheap. Adding more methods is complexifying the API which in the long run leads to not so great user experience (think of the mpl or pandas API).

@andamian
Copy link
Contributor Author

andamian commented Nov 2, 2022

@bsipocz I see your point and I agree with you but we can't just break user code without giving them a warning at least. They might already handle the units by looking at the unit of the column in their code. Other units like ObsCore.s_ra are standardized so it was legit to compare it against a scalar that represents that unit.

We could add to_qtable() and deprecate to_table() if we want to emphasize the importance of using units which I support.

@bsipocz
Copy link
Member

bsipocz commented Nov 2, 2022

We could add to_qtable() and deprecate to_table() if we want to emphasize the importance of using units which I support.

I like this idea as a good middle ground.

@andamian
Copy link
Contributor Author

andamian commented Nov 2, 2022

These are just convenience methods which should encourage (make it easy) to do things the right way. It is still easy to get a simple Table if someone really needs that functionality - it's just not provided.

I'll proceed with the changes if we are all in agreement.

@taldcroft
Copy link
Member

Since I was looped in, I'll express my opinion that the to_table() method should not even be deprecated and both methods should be available as options. Not everyone is using astropy to design a satellite and I firmly believe that users should be allowed to decide freely how they want to do their analysis.

@funbaker
Copy link
Contributor

funbaker commented Nov 3, 2022

I think the reason not to return QTable back then was that a service may return invalid units

@andamian
Copy link
Contributor Author

andamian commented Nov 3, 2022

I think the reason not to return QTable back then was that a service may return invalid units

It's probably still the case sometimes. Warnings are issued when the value cannot be parsed and that could be annoying enough for users to push the service providers to fix them.
When the value can be parsed but the unit is wrong, well that's a more subtle service bug, but still a bug.

@andamian
Copy link
Contributor Author

@bsipocz - how should proceed with this? It sounds like the question now is whether to deprecate to_table or not.

@bsipocz
Copy link
Member

bsipocz commented Dec 12, 2022

I can't recall any serious limitations of a QTable as opposed to a Table in the contect of VO, or table sizes served by VO (as opposed to big data tables read in from parquet, or being process with spark or dask, for those I don't think either Table or QTable would work anyway, but one should go with a flavour of dataframes and forget about astropy and units and etc), so personally I would deprecate it rather than having both.
If @taldcroft feels that users should have both, then maybe we should just show in the docs how to convert that Table to a QTable than complicate the API with another method doing almost the same.

@taldcroft
Copy link
Member

That documentation fix sounds ok to me but I'm really peripheral here.

@andamian
Copy link
Contributor Author

I'd rather have it added to the API than just mentioning it into the docs. One, because I think it's the better method (and was requested by our users) and two because the IDE will always show it as an option as opposed to having to remember about the conversion method from the docs.

@bsipocz
Copy link
Member

bsipocz commented Dec 13, 2022

Yes, I think it's also the better option, and in the context of pyvo folks should use qtables. the only thing I don't like is to have both. But it's not a big deal.

@andamian
Copy link
Contributor Author

andamian commented Jan 5, 2023

OK, I prefer consensus but if there are no vetos I would need to merge this.

@andamian andamian merged commit 979276d into astropy:main Jan 16, 2023
@andamian andamian deleted the CADC-11957 branch January 16, 2023 20:11
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.

None yet

5 participants