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
cosmo: to/from table #12213
cosmo: to/from table #12213
Conversation
Hello @nstarman 👋! It looks like you've made some changes in your pull request, so I've checked the code again for style. There are no PEP8 style issues with this pull request - thanks! 🎉 Comment last updated at 2021-10-29 12:35:13 UTC |
7441ce3
to
dc65c18
Compare
b67343c
to
f8818c5
Compare
f8818c5
to
4fddf3e
Compare
99f08df
to
2bc0700
Compare
@nstarman - is this ready? I see it is still showing as a Draft. |
It's ready for review, but it's dependent on another PR (see top comment), which needs to be merged first. |
2bc0700
to
c4b3e68
Compare
d4f1b77
to
8ac2902
Compare
One big picture comment at this point. I went to the current RTD for this PR and was see that neither JSON nor ECSV formats are registered by default. I thought that was the main driver of this whole long journey, to provide an interoperable serialization format for cosmology. The code for JSON is already in the example, and there used to be code for ECSV (and it's trivial anyway), so is that planned for the next quick PR before 5.0? Other comments on the docs:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll take another pass, but for now I didn't see anything obviously off in the code and the testing looks quite solid.
I just saw the Cosmology, the Expansion project. Wow, amazing work and great to see your ambitious plans laid out like this. (And clever project title). But I don't see ECSV in there except as a closed WIP from early on. |
8ac2902
to
c1cd0c1
Compare
Good spot. Yes, that is still the plan. In the (now-closed) omnibus PR #11559 one of the important topics of discussion was https://xkcd.com/927/ on competing standards. I spent a while looking over different formats, e.g. Cobaya versus Cosmosis, versus MontePython and they are all a bit confusing and muddled and depend entirely on their internal units.
Yes for the ECSV. Not yet for the JSON, for the above reasons.
I actually think pickle is a good way to serialize a cosmology for short-term storage. ie passing an object between threads. I think I'll just note that there are superior solutions for persistent storage.
Good point! now operational. not tested in the docs, but thoroughly elsewhere.
A good point. I'll try moving it. Edit: See #12321 for fixes to the above. |
77103db
to
c1cd0c1
Compare
@nstarman - your replies above all look good to me. I see a merge conflict just popped up... |
a0f583a
to
bc3cafb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! My comments can be safely ignored...
astropy/cosmology/io/table.py
Outdated
if not table.indices: # no indexing column, find by string match | ||
index = np.where(table['name'] == index)[0][0] | ||
else: # has indexing column | ||
index = table.loc_indices[index] # need to convert to row index (int) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In principle, one could index by other things than str
- maybe reverse this? E.g.,
if index is not None:
try:
index = operator.index(index)
except TypeError:
if table.indices:
index = table.loc_indices[index]
else:
table = table[table['name'] == index]
index = None
(Note different suggestion for finding the name - for duplicates, I think one should fail)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, on second thought all of this seems too much duplication of table indexing. Not sure any is really necessary, but if doing it I'd keep it really simple and just allow the selection by name and perhaps a simple numerical index (though I'd personally sooner allow input of Row
objects and let people do table[num]
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a Row reader PR scheduled for v5.1! though if this PR goes in soon maybe we can get that one in as well. It's ready, I just have too many PRs for v5.0 😰
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are not public API and are discouraged from use, in favor of | ||
``Cosmology.to/from_format(..., format="<format>")``, but should be tested | ||
regardless b/c 3rd party packages might use these in their Cosmology I/O. | ||
Also, it's cheap to test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, yes, but do remember these tests get run many times, so energy use may not be quite negligible (though incomparably less than bitcoin for incomparably more value!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I realized that boilerplate comment is also wrong. I use the private functions across the cosmology/io
subpackage and this is also one of the few places the built in Cosmology realizations are specifically tested. Actually quite useful!
dcac4cb
to
2404228
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NB the Python 3.10 failure looks unrelated. |
Signed-off-by: Nathaniel Starkman (@nstarman) <nstarkman@protonmail.com>
Signed-off-by: Nathaniel Starkman (@nstarman) <nstarkman@protonmail.com>
Allows for ``Table(cosmo)``. Signed-off-by: Nathaniel Starkman (@nstarman) <nstarkman@protonmail.com>
Signed-off-by: Nathaniel Starkman (@nstarman) <nstarkman@protonmail.com>
2404228
to
3e8ba26
Compare
Rebased on fixes to most of the CI just to check everything's kosher. Thanks @taldcroft and @mhvk for the reviews! |
Registers Astropy Table into Cosmology's
to/from_format
I/O, allowinga Cosmology instance to be parsed from or converted to a Table instance.
Also adds the
__astropy_table__
method allowingTable(cosmology)
.Requires #12209Merged!Checklist for package maintainer(s)
This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.
Extra CI
label.no-changelog-entry-needed
label. If this is a manual backport, use theskip-changelog-checks
label unless special changelog handling is necessary.astropy-bot
check might be missing; do not let the green checkmark fool you.backport-X.Y.x
label(s) before merge.