Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix registry for min in buitlins #242

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

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion quantities/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ def __getitem__(self, string):
all_builtins.remove("bytes")
# have to deal with octet as well
all_builtins.remove("oct")
# have to remove min which is short for minute
all_builtins.remove("min")
for builtin in all_builtins:
if builtin in string:
raise RuntimeError(f"String parsing error for {string}. Enter a string accepted by quantities")
raise RuntimeError(f"String parsing error for `{string}`. Enter a string accepted by quantities")

try:
return eval(string, self.__context)
Expand Down
6 changes: 6 additions & 0 deletions quantities/tests/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ def test_addition(self):
[1, 2, 3]*pq.hp + [1, 2, 3]*pq.hp,
[2, 4, 6]*pq.hp
)
# add in test with 'min' since this caused issues
# see https://github.com/python-quantities/python-quantities/issues/243
self.assertQuantityEqual(
Quantity(1, 'min') + Quantity(1, 'min'),
2*pq.min
)

self.assertRaises(ValueError, op.add, pq.kPa, pq.lb)
self.assertRaises(ValueError, op.add, pq.kPa, 10)
Expand Down
4 changes: 4 additions & 0 deletions quantities/tests/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ def test_default_system(self):
self.assertQuantityEqual(pq.kg.simplified, 1000*pq.g)
self.assertQuantityEqual(pq.m.simplified, 1000*pq.mm)

# test a time default as well as mass and weight
pq.set_default_units('SI')
self.assertQuantityEqual(pq.min.simplified, 60*pq.sec)

class TestUnitInformation(TestCase):

def test_si(self):
Expand Down
2 changes: 1 addition & 1 deletion quantities/units/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
60*s,
symbol='min',
aliases=['minutes']
)
) # min is function in python
h = hr = hour = UnitTime(
'hour',
60*min,
Expand Down
Loading