Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pint.errors.DimensionalityError: Cannot convert from 'meter' to 'dimensionless' #31

Closed
tve opened this issue Apr 28, 2022 · 1 comment
Closed

Comments

@tve
Copy link

tve commented Apr 28, 2022

When using a gpx file...

Traceback (most recent call last):
  File "/home/tve/Projects/Navigation/gopro-overlay/bin/gopro-dashboard.py", line 124, in <module>
    timeseries.process_deltas(timeseries_process.calculate_gradient(), skip=10)
  File "/home/Projects/Navigation/gopro-overlay/bin/../gopro_overlay/timeseries.py", line 186, in process_deltas
    updates = processor(self.entries[a], self.entries[b], skip)
  File "/home/Projects/Navigation/gopro-overlay/bin/../gopro_overlay/timeseries_process.py", line 64, in accept
    gain = b.alt - a.alt
  File "/usr/lib/python3.10/site-packages/pint/quantity.py", line 1095, in __rsub__
    return -self._add_sub(other, operator.sub)
  File "/usr/lib/python3.10/site-packages/pint/quantity.py", line 115, in wrapped
    return f(self, *args, **kwargs)
  File "/usr/lib/python3.10/site-packages/pint/quantity.py", line 984, in _add_sub
    raise DimensionalityError(self._units, "dimensionless")
pint.errors.DimensionalityError: Cannot convert from 'meter' to 'dimensionless'

Debug:

def calculate_gradient():
    def accept(a, b, c):
        try:
            gain = b.alt - a.alt
            if a.odo and b.odo:
                dist = b.odo - a.odo
                if dist and dist.magnitude > 0:
                    return {"grad": (gain / dist) * 100.0}
        except Exception: print(b.alt, a.alt)

Output:

Processing....
None -0.8 meter
None -0.8 meter
None -0.8 meter
None -0.8 meter
None -0.8 meter
None -0.8 meter
-0.4 meter None
-0.4 meter None
-0.4 meter None
-0.4 meter None
-0.6 meter None
-0.6 meter None
None -0.4 meter
None -0.4 meter
None -0.4 meter
None -0.6 meter
None -0.6 meter
None -0.6 meter
None -0.6 meter
...

Fix:

def calculate_gradient():
    def accept(a, b, c):
        if a.alt is None or b.alt is None:
            return {"grad": 0.0}
        gain = b.alt - a.alt
        if a.odo and b.odo:
            dist = b.odo - a.odo
            if dist and dist.magnitude > 0:
                return {"grad": (gain / dist) * 100.0}

    return accept
time4tea added a commit that referenced this issue Jun 11, 2022
other places (e.g. widgets) should accept missing gradient and render something sensible
@time4tea
Copy link
Owner

Fixed in 0.47.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants