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

Add alternate names with µ for micro instead of u #142

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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: 2 additions & 2 deletions scimath/units/electromagnetism.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
###############################################################################

micro_farad = micro * farad
micro_farad.label = 'uf'
mf = micro_farad
micro_farad.label = 'µf'
µf = uf = micro_farad

pico_farad = pico * farad
pico_farad.label = 'pf'
Expand Down
4 changes: 2 additions & 2 deletions scimath/units/geo_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,5 @@
###############################################################################
# psonic
###############################################################################
us_per_ft = microsecond / foot
us_per_ft.label = 'us/ft'
µs_per_ft = us_per_ft = microsecond / foot
µs_per_ft.label = 'µs/ft'
2 changes: 1 addition & 1 deletion scimath/units/length.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@

m = meter
nm = nanometer
um = micrometer
µm = um = micrometer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably worth adding a test that both µm (using MICRO SIGN) and μm (using GREEK SMALL LETTER MU) are parsed correctly with this definition. They are right now, but that could change if we move away from using eval at some point in the future.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, and somewhat surprisingly, Unicode TR 25 says that GREEK SMALL LETTER MU is the preferred character here. (See section 2.5 of http://www.unicode.org/reports/tr25/)

micron = micrometer
mm = millimeter
cm = centimeter
Expand Down
8 changes: 7 additions & 1 deletion scimath/units/tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,18 @@ def test_unit_parser_non_python(self):
angle.grad,
angle.minutes,
acceleration.m_per_s2,
electromagnetism.mf,
electromagnetism.uf,
volume.cm3,
]
for u in odd_units:
self.assertEqual(parse(u.label), u)

def test_unit_parser_micro_sign(self):
parse = lambda s: unit_parser.parse_unit(s, suppress_unknown=False)
micrometer_symbols = ["\N{MICRO SIGN}m", "\N{GREEK SMALL LETTER MU}m"]
for symbol in micrometer_symbols:
self.assertEqual(parse(symbol), length.µm)

def test_unit_parser_offsets(self):
parse = lambda s: unit_parser.parse_unit(s, suppress_unknown=False)
offset_units = [
Expand Down
2 changes: 1 addition & 1 deletion scimath/units/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
s = sec = second
ps = picosecond
ns = nanosecond
us = usec = microsecond
µs = µsec = us = usec = microsecond
ms = msec = millisecond

# plural aliases
Expand Down