_UnitRegistry doesn't know about physical types of composite units
See original GitHub issueI just found a bug in astropy.units that significantly hampers the functionality added in #3847 …
Apparently, the _UnitRegistry object doesn’t know about physical types of composite units:
>>> from astropy.units import get_current_unit_registry
>>> ureg = get_current_unit_registry()
>>> ureg.get_units_with_physical_type(u.m)
{Unit("ym"),
Unit("zm"),
Unit("am"),
Unit("yearthRad"),
Unit("yjupiterRad"),
Unit("ysolRad"),
...etc
But doing the same for, e.g.,:
>>> ureg.get_units_with_physical_type(u.m/u.s)
set()
>>> ureg.get_units_with_physical_type(u.kg/u.m**3)
set()
I think the concept of “physical type” could use an overhaul, but that is a big change and should probably get pushed to v3.0. But for v2.0, we need to find a solution to support these physical type lookups from the unit registry. This might require some hacking of the _UnitRegistry.add_enabled_units() method.
BTW: We didn’t see this in the tests for #3847 because the physical types I used all resolved to irreducible units.
cc @mhvk
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Units and Quantities (astropy.units) — Astropy v5.2
astropy.units does not know spherical geometry or sexagesimal (hours, min, sec): if you want to ... Superclass for Quantities of specific physical type....
Read more >Tutorial — pint 0.10.1 documentation
In this code distance and time are physical quantity objects ( Quantity ). ... As unit registry knows about the relationship between different...
Read more >Source code for gala.units
This class behaves like a dictionary with keys set by physical types. If a unit for a particular physical type is not specified...
Read more >Units and Quantities (astropy.units) — Astropy v1.0.4
Examples of physical quantities are meters, seconds, Hz, etc. astropy.units does not know spherical geometry or sexagesimal (hours, min, sec): if you want ......
Read more >astropy/core.py at main - units - GitHub
Get all units in the registry with the same physical type as. the given unit. Parameters ... Adds to the set of equivalencies...
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 Free
Top 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

p.s. I don’t really know what to do about the larger question: as you write, it becomes a combinatorial explosion. My own sense is that it is better first to get the systems in place, so that it becomes possible to get a preferred unit for a given physical type. I have never found myself needing a list of possible units…
closing given the combinatorial explosion mentioned in-line