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

Operations with "empty" Arrays can cause UnboundLocalError #55

Open
prusse-martin opened this issue Apr 27, 2021 · 0 comments
Open

Operations with "empty" Arrays can cause UnboundLocalError #55

prusse-martin opened this issue Apr 27, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@prusse-martin
Copy link
Member

  • Barril version: 1.10.0 (build py_0 from conda-forge)
  • Python version: Python 3.6.7 (build he025d50_1008_cpython from conda-forge)
  • Operating System: Microsoft Windows 10 Pro (10.0.19041 N/A Build 19041)

Description

Operating with empty Arrays (values are an empty list or tuple) barril will raise an UnboundLocalError.
When using an empty numpy.ndarray as values there is no error and an empty Array is returned (this is the workaround we are using, force the relevant Arrays to hold numpy.ndarrays).

What I Did

>>> from barril.units import Array
>>> Array([1, 2], 's') / 2
Array(time, [0.5, 1.0], s)
>>> 2 / Array([1, 2], 's')
Array(1 / time, [2.0, 1.0], 1/s)
>>> Array([1], 's') / 2
Array(time, [0.5], s)
>>> Array([], 's') / 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "W:\alfasim\envs\_alfasim_gui-win64-py36\lib\site-packages\barril\units\_array.py", line 286, in __truediv__
    return self._DoOperation(self, other, "Divide")
  File "W:\alfasim\envs\_alfasim_gui-win64-py36\lib\site-packages\barril\units\_array.py", line 360, in _DoOperation
    return self.__class__.CreateWithQuantity(q, result)
UnboundLocalError: local variable 'q' referenced before assignment
>>> 2 / Array([], 's')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "W:\alfasim\envs\_alfasim_gui-win64-py36\lib\site-packages\barril\units\_array.py", line 302, in __rtruediv__
    return self._DoOperation(other, self, "Divide")
  File "W:\alfasim\envs\_alfasim_gui-win64-py36\lib\site-packages\barril\units\_array.py", line 360, in _DoOperation
    return self.__class__.CreateWithQuantity(q, result)
UnboundLocalError: local variable 'q' referenced before assignment
>>>
@prusse-martin prusse-martin added the bug Something isn't working label Apr 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant