fix: parsing of jyear and byear times from ASDF - #326
Conversation
The schema allows `value: JXXXX.X` with `format: jyear` and likewise for Bessellian years. Astropy is a bit overly strict in requiring the 'jyear_str' and 'byear_str' Time formats for these when instantiating a Time with a known format. After experimenting with different approaches it seems, ufortunately, most reliable to refuse to guess, and instead take a test value (if the node value is an array or quantity) and check if it is a string starting with the appropriate prefix.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #326 +/- ##
==========================================
- Coverage 99.06% 98.84% -0.23%
==========================================
Files 71 71
Lines 2572 2594 +22
==========================================
+ Hits 2548 2564 +16
- Misses 24 30 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
I'm not sure we should consider as something we want to support since t's inconsistent with respect to the typical time formatting (where which is no longer |
|
I don't think It's a good point about the round-tripping question though. But I think that could also be fixed in coordination with Astropy. Let me think about it... |
|
In either case the schema is not strictly correct, or rather, overly permissive. It just has: properties:
value:
description: |
The value(s) of the time.
anyOf:
- $ref: "#/definitions/string_formats"
- $ref: "#/definitions/array_of_strings"
- $ref: "../core/ndarray-1.1.0"
- type: number
format:
description: |
The format used to save the time in ASDF
If not provided, the the format should be guessed from the
string from among the following unambiguous options:
`iso`, `byear`, `jyear` and `yday`.
$ref: "#/definitions/format"which actually allows complete mismatches between oneOf:
- value: {$ref: "#/definitions/iso_time"}
format: iso
- value: {$ref: "#/definitions/byear"}
format: byearand so on. The I also noticed while hacking on the time parser in libasdf that some of these regular expressions seem to be trying to encode too much information, like: I simplified it to just: |
The comment about For the other issues about the time schema would you open an asdf-standard issue? What's preventing updating libasdf to write out times matching what asdf-astropy currently does? |
|
See discussion in astropy/astropy-APEs#134 ; clearly need to think more about what to do here. I still posit that |
The schema allows
value: JXXXX.Xwithformat: jyearand likewise for Bessellian years. Astropy is a bit overly strict in requiring the 'jyear_str' and 'byear_str' Time formats for these when instantiating a Time with a known format.After experimenting with different approaches it seems, ufortunately, most reliable to refuse to guess, and instead take a test value (if the node value is an array or quantity) and check if it is a string starting with the appropriate prefix.
This came up in asdf-format/libasdf#201 , as libasdf allows writing a time like:
which is valid within the schema.
Arguably Astropy's behavior here is finicky and misleading:
The error message is misleading because it says the input may be a "string", which it was. But what it's looking for here is a bare decimal string like
2000.0.I can see why, for serialization purposes, Astropy has separate
'jyear'and'jyear_str'formats (though arguably the latter should be a subformat of the former). But I think it could stand to be a little more flexible on this too when there's no ambiguity.Also fixed a bit of what appeared to be copy/paste detritus in one of the other existing test cases.