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.

units: 's / m' and 's / m' are not convertible

See original GitHub issue

To paraphrase from https://github.com/PlasmaPy/PlasmaPy/issues/587, exceptions like astropy.units.core.UnitConversionError: 's / m' and 's / m' are not convertible (and a few other cases with first, second and third powers of second over meter, curiously) started popping up in our travis tests as seen at https://travis-ci.org/PlasmaPy/PlasmaPy/jobs/466396211 .

For a brief overview, running python setup.py test -d and getting into plasmapy.physics.distribution.Maxwellian_1D:

(Pdb) distFunc
<Quantity 5.91632969e-07 s / m>
(Pdb) p u.s / u.m
Unit("s / m")
(Pdb) p distFunc
<Quantity 5.91632969e-07 s / m>
(Pdb) p distFunc.unit
Unit("s / m")
(Pdb) p distFunc.to(u.s / u.m)
*** astropy.units.core.UnitConversionError: 's / m' and 's / m' are not convertible

I’ve managed to figure out that this is localized to astropy 3.1. As suggested by @astrofrog on slack, I ran git bisect with pytest --doctest-modules $PLASMAPY/plasmapy/physics/distribution.py and I was able to identify the first bad commit as

3a478ca29e86144d6c5a0305dde86169a647ff63 is the first bad commit
commit 3a478ca29e86144d6c5a0305dde86169a647ff63
Author: Marten van Kerkwijk <mhvk@astro.utoronto.ca>
Date:   Thu Jul 12 21:01:28 2018 -0700

    Further short-cuts for single-unit CompositeUnit initialization.

:040000 040000 1ba7cb9440215ab641197f91ef1623ad9bb39378 5c02db4ede9146ec12f84f57a0382f4900777544 M      astropy

I’m currently trying to find out the exact cause of this bug in that commit, but I figured it’s best to submit this issue here before I accidentally close this tab or something.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
mhvkcommented, Dec 11, 2018

OK, here is an astropy-only version (proving it is purely an astropy bug):

import astropy.units as u
v2 = 1*u.m**2/u.s**2
(v2 ** (-1/2)).to(u.s/u.m)
# UnitConversionError: 's / m' and 's / m' are not convertible
2reactions
StanczakDominikcommented, Dec 11, 2018

I think I’ve got something. At the end of the problematic Maxwellian_1D function, we have a return distFunc.to(u.s / u.m). In what follows, unit is the unit of distFunc and other is u.s / u.m:

(plasmapy-tests) 18:07:23 dominik: ~/Code/PlasmaPy/PlasmaPy $ pytest --doctest-modules --pdb plasmapy/physics/distribution.py  
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.7.0, pytest-4.0.1, py-1.7.0, pluggy-0.8.0
rootdir: /home/dominik/Code/PlasmaPy/PlasmaPy, inifile: setup.cfg
plugins: remotedata-0.3.1, openfiles-0.3.1, doctestplus-0.2.0, arraydiff-0.2
collected 8 items                                                                                                                                                          

plasmapy/physics/distribution.py F
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> traceback >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
098         \equiv \frac{1}{\sqrt{\pi v_{Th}^2}} e^{-(v - v_{drift})^2 / v_{Th}^2}
099 
100     where :math:`v_{Th} = \sqrt{2 k_B T / m}` is the thermal speed
101 
102     Examples
103     --------
104     >>> from plasmapy.physics import Maxwellian_1D
105     >>> from astropy import units as u
106     >>> v=1*u.m/u.s
107     >>> Maxwellian_1D(v=v, T=30000 * u.K, particle='e', v_drift=0 * u.m / u.s)
UNEXPECTED EXCEPTION: UnitConversionError("'s / m' and 's / m' are not convertible")
Traceback (most recent call last):

  File "/home/dominik/.miniconda3/envs/plasmapy-tests/lib/python3.7/doctest.py", line 1329, in __run
    compileflags, 1), test.globs)

  File "<doctest plasmapy.physics.distribution.Maxwellian_1D[3]>", line 1, in <module>

  File "/home/dominik/Code/PlasmaPy/PlasmaPy/plasmapy/physics/distribution.py", line 142, in Maxwellian_1D
    return distFunc.to(u.s / u.m)

  File "/home/dominik/Code/astropy/astropy/units/quantity.py", line 669, in to
    return self._new_view(self._to_value(unit, equivalencies), unit)

  File "/home/dominik/Code/astropy/astropy/units/quantity.py", line 641, in _to_value
    equivalencies=equivalencies)

  File "/home/dominik/Code/astropy/astropy/units/core.py", line 984, in to
    return self._get_converter(other, equivalencies=equivalencies)(value)

  File "/home/dominik/Code/astropy/astropy/units/core.py", line 915, in _get_converter
    raise exc

  File "/home/dominik/Code/astropy/astropy/units/core.py", line 901, in _get_converter
    self, other, self._normalize_equivalencies(equivalencies))

  File "/home/dominik/Code/astropy/astropy/units/core.py", line 885, in _apply_equivalencies
    unit_str, other_str))

astropy.units.core.UnitConversionError: 's / m' and 's / m' are not convertible

/home/dominik/Code/PlasmaPy/PlasmaPy/plasmapy/physics/distribution.py:107: UnexpectedException
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> entering PDB >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> /home/dominik/Code/astropy/astropy/units/core.py(885)_apply_equivalencies()
-> unit_str, other_str))
(Pdb) p vars(unit)
{'_bases': [Unit("m"), Unit("s")], '_powers': [-1.0, 1.0], '_scale': 1.0, '_decomposed_cache': Unit("s / m")}
(Pdb) p vars(other)
{'_scale': 1.0, '_bases': [Unit("s"), Unit("m")], '_powers': [1, -1], '_decomposed_cache': Unit("s / m")}

So I think this has something to do with that the fact that _powers are floats in one case and ints in another. It may also have to do with the fact that _bases don’t have the same ordering and thus you can’t simply (as I assume this does somewhere… haven’t been able to track it down) cast powers to a common numeric type and check if they agree. They have to be sorted with the same ordering that sorts _bases first.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Equivalencies — Astropy v5.2
Normally these units are not convertible, but when understood as representing light, they are convertible in certain contexts. Here we describe how to...
Read more >
Rules | The Nasdaq Stock Market
(c) The minimum unit of trading in the Nasdaq Bond Exchange is one non-convertible bond unless the issuer otherwise specifies a larger minimum...
Read more >
SM Energy Company (SM) Convertible Senior Notes Due 2021
SM Energy Company announced today it was issuing $100 million principal amount of 2.0% senior unsecured convertible notes due 2021.
Read more >
Unit of measure PC is not convertible to stockkeeping unit PPM
Hello, I get an Exception "Unit of measure PC is not convertible to stockkeeping unit PPM" from BAPI_GOODSMVT_CREATE. Regards Vladislav.
Read more >
Citroën SM - Wikipedia
The Citroën SM is a high-performance coupé produced by the French manufacturer Citroën from 1970 to 1975. The SM placed third in the...
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