Repository navigation
Change Table and Column meta to dict and enforce YAML output as ordered map - #16250
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 |
There was a problem hiding this comment.
Cosmology changes LGTM. This is reversing the effects of #15484 which had updated meta to be a dict in the table, resulting in the change. This PR effects Table and thus Cosmology.
There was a problem hiding this comment.
Thanks for the review. So this is making a little churn but should be OK.
mhvk
left a comment
There was a problem hiding this comment.
I like this approach! It puts the use of OrderedDict exactly where the problem lies, with yaml, and makes everything else easier. It is especially nice that order is now guaranteed to round-trip.
I assume it is on purpose that you do not (yet) change the default for meta itself?
Yes, but that's a great question. I was thinking about making that change as a separate PR. And as usual when you start poking at some code you see little problems. E.g. for some reason Quantity info is not enforcing that So anyway, maybe a follow-up PR that changes the default and fixes things like that? |
|
OK, let's just deal with getting YAML right here! |
mhvk
left a comment
There was a problem hiding this comment.
Had a look through everything again and basically this looks all great to me. Probably good to have a changelog entry!
0f4753e to
626844a
Compare
|
@mhvk - I've added changelog entries and a What's New. The expectation is that the What's New will be expanded to include the next PR to change the default to AFAIK this PR is complete and ready for review. (Of course CI often disagrees...) |
mhvk
left a comment
There was a problem hiding this comment.
Looks good! Main comments are to update a comment and docstring.
Also, the readthedocs failures may be related to 6.1 having been branched...:
/home/docs/checkouts/readthedocs.org/user_builds/astropy/checkouts/16250/docs/
index_getting_started.rst:7: WARNING: toctree contains reference to document 'whatsnew/6.1' that doesn't have a title: no link will be generated
| class BaseColumn(_ColumnGetitemShim, np.ndarray): | ||
| meta = MetaData(default_factory=OrderedDict) | ||
| meta = MetaData(default_factory=dict) | ||
| # It's important that the metadata is an OrderedDict so that the order of |
There was a problem hiding this comment.
Can you adjust this comment? Or perhaps just remove it?
| OrderedDict([('foo', 'bar'), ('mumble', 'quux'), ('baz', 'gorp')]) | ||
| """ | ||
| omap = OrderedDict() | ||
| omap = {} |
There was a problem hiding this comment.
I think the docstring needs to be adjusted here! Note that the doctest is skipped - I think that may be from a time when yaml was not a required dependency.
There was a problem hiding this comment.
I ended up removing the example entirely. It turns out that it didn't work as shown. First there were no imports so there was ambiguity about the yaml symbol (from astropy or pyyaml?). But more importantly it didn't show that this private function needs to be registered as a constructor in a custom Loader subclass. The comment now just refers to the astropy function where it is used and that should be fine.
626844a to
ec0d4e1
Compare
|
@mhvk - thanks for the quick review, your comments have been addressed. I just rebased again and with any luck the RTD will pass now. |
|
And as a reminder I prefer that this be squashed. |
| License: Unspecified | ||
|
|
||
| This is the same as SafeConstructor.construct_yaml_omap(), | ||
| except the data type is changed to OrderedDict() and setitem is |
mhvk
left a comment
There was a problem hiding this comment.
I'll approve now, so you can merge when tests pass, but see my single comment.
|
@pllim @saimn @astrofrog - I'm still seeing an RTD warning I rebased on |
|
Should be fixed with #16272. |
nstarman
left a comment
There was a problem hiding this comment.
Cosmology looks G2G. Thanks!
This pull request removes OrderedDict from files in io.ascii. The files are: core.py , daophot.py , ecsv.py , fastbasic.py , ipac.py and test_read.py. The OrderedDicts are normal dictionaries now.
ec0d4e1 to
81b3c81
Compare
|
I rebased on main which will hopefully fix the RTD failure. |
…ed map (#16250) * Use OrderedDict/omap sandwich in YAML * Removed OrderedDict from io.ascii This pull request removes OrderedDict from files in io.ascii. The files are: core.py , daophot.py , ecsv.py , fastbasic.py , ipac.py and test_read.py. The OrderedDicts are normal dictionaries now. * fixed indent error * Remove unused imports and ruff formatting * Use dict as default factory for meta instead of OrderedDict * Table and column meta default to dict, in YAML always !!omap * Make testing (esp ECSV) more robust for meta * Add change log entries * Add What's New entry * Minor doc updates --------- Co-authored-by: alexandrecesarba <[email protected]>
Description
This builds on top of #16240 (which built from #15496) to work toward removing
OrderedDictfrom astropy where possible. This PR does so in a number of places.Table
Table.metanow defaults todict.Column.metanow defaults todict.It is important to remember that these attributes can still be set to any mapping type (e.g.
t.meta = OrderedDict(...)), it is just the default type that is changed.YAML / ECSV
The machinery which helps to serialize
TableandColumnto YAML (and back) has been updated to always write the Table and Columnmetaattribute as an ordered map (!!omapin YAML). This change addresses a previous inconsistency: if the user initialized a Table liket = Table(data, meta={'a': 1})then the YAML would serializemetaas an unordered mapping. This was not the intent. The same held forColumn.meta. Now the behavior is consistent and this is reflected in changes to unit tests and docstrings. However, the order of items in the dict is not changed.This mostly just impacts ECSV. There should not be any issues with back-compatibility. The main change is just following the
Tablechange, namely that reading an ECSV file will always return a Table that hasdictmeta instead ofOrderedDictmeta (except of course that past behavior was inconsistent).Other
io.asciireader classesThese are somewhat unrelated to the more impacting changes but are useful nonetheless.
This PR should be squashed.
cc: @MridulS @nstarman