question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

_UnitRegistry doesn't know about physical types of composite units

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
mhvkcommented, May 18, 2017

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…

0reactions
mhvkcommented, Apr 12, 2021

closing given the combinatorial explosion mentioned in-line

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found