Unit roundtrips do not always work
See original GitHub issueDescription
Not sure whether this is an issue, however it would probably nice to have it fixed:
Expected behavior
I would expect that any roundtrip for unicode
format works. i.e. for all units unit
:
format='unicode'
assert u.Unit(unit.to_string(format=format), format=format) == unit
should work. I would expect the same for the other formatters; at least for generic
and fits
.
Actual behavior
For Angstrom, it works when not giving unicode
as format in the u.Unit()
constructor, but not when this is given:
>>> u.Unit(u.Angstrom.to_string(format='unicode')) == u.Angstrom
True
>>> u.Unit(u.Angstrom.to_string(format='unicode'), format='unicode') == u.Angstrom
[…]
ValueError: 'Å' did not parse as unicode unit: Can not parse Unicode If this […]
The second exception comes for any unit; unicode
seems not be supported as parsing format.
For the solar mass, the first one does not work as well:
>>> u.Unit(u.solMass.to_string(format='unicode')) == u.solMass
[…]
ValueError: 'M⊙' did not parse as unit: At col 0, M is not a valid unit. Did you […]
I would assume that
- the “unicode” parse format is identical to the “generic” format (as we usually use unicode in strings)
- Unicode output is also parseable, as the generic input
System Details
The tests were done with Astropy 4.2
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (13 by maintainers)
Top Results From Across the Web
One Way vs Round Trip Ticket - Issues? - Air Travel Forum
A seat is a seat is a seat, right? One of them should incur less cost than two, correct? Maybe not half as...
Read more >What is round-trip time? | RTT definition - Cloudflare
It's important to keep in mind that round-trip time is an estimate and not a guarantee; the pathway between the two locations can...
Read more >What is a "fare component" when buying an airline ticket?
A round trip consists of two components; one outbound and one return. The fare for each component is the same. If different fares...
Read more >Pricing Diagnostics/Fare Construction Theory
In domestic U.S. fare selection, Worldspan always uses Headline fares. This may or may not be the actual direction of travel. If domestic...
Read more >What is Round Trip Time (RTT) | Behind the Ping | CDN Guide
Round trip time is a key factor for measuring network latency and page load times. Find out what influences RTT and how CDNs...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Finding them is simple:
This shows all unique but the prefixed units that raise the error:
Looks not overwhelming to me. Maybe I will have a look myself, if this is agreed to be useful…
OK, I made a fix to the parsing issue, see #11827.
For the parsing with ‘unicode’, it needs a better error message indeed, which I think is easier to deal with as a separate issue, so I raised #11828.
@maxnoe - indeed, you are right, we are now free to try to implement the module
__getattr__
idea!