[yt-svn] commit/yt: brittonsmith: Merged in ngoldbaum/yt (pull request #1822)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Mon Oct 26 11:36:59 PDT 2015
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/commits/7a2cc5af89cf/
Changeset: 7a2cc5af89cf
Branch: yt
User: brittonsmith
Date: 2015-10-26 18:34:34+00:00
Summary: Merged in ngoldbaum/yt (pull request #1822)
Fix bad unit labels for compound units
Affected #: 2 files
diff -r a5d76f647fbb9a740e21cf5d8269660aea6736cc -r 7a2cc5af89cf0911fbdb5460963ee3844ba3de7b yt/units/tests/test_units.py
--- a/yt/units/tests/test_units.py
+++ b/yt/units/tests/test_units.py
@@ -454,7 +454,7 @@
assert_raises(InvalidUnitOperation, operator.mul, u1, u2)
assert_raises(InvalidUnitOperation, operator.truediv, u1, u2)
-def test_comoving_and_code_unit_labels():
+def test_latex_repr():
ds = fake_random_ds(64, nprocs=1)
# create a fake comoving unit
@@ -471,3 +471,6 @@
test_unit = Unit('code_mass/code_length**3', registry=ds.unit_registry)
assert_equal(test_unit.latex_repr,
'\\frac{\\rm{code\\ mass}}{\\rm{code\\ length}^{3}}')
+
+ test_unit = Unit('cm**-3', base_value=1.0, registry=ds.unit_registry)
+ assert_equal(test_unit.latex_repr, '\\frac{1}{\\rm{cm}^{3}}')
diff -r a5d76f647fbb9a740e21cf5d8269660aea6736cc -r 7a2cc5af89cf0911fbdb5460963ee3844ba3de7b yt/units/unit_object.py
--- a/yt/units/unit_object.py
+++ b/yt/units/unit_object.py
@@ -104,7 +104,10 @@
def get_latex_representation(expr, registry):
symbol_table = {}
for ex in expr.free_symbols:
- symbol_table[ex] = registry.lut[str(ex)][3]
+ try:
+ symbol_table[ex] = registry.lut[str(ex)][3]
+ except:
+ symbol_table[ex] = r"\rm{" + str(ex).replace('_', '\ ') + "}"
latex_repr = latex(expr, symbol_names=symbol_table, mul_symbol="dot",
fold_frac_powers=True, fold_short_frac=True)
if latex_repr == '1':
@@ -214,7 +217,7 @@
if dimensions is not None:
validate_dimensions(dimensions)
if latex_repr is None:
- latex_repr = r"\rm{" + str(unit_expr).replace('_', '\ ') + "}"
+ latex_repr = get_latex_representation(unit_expr, registry)
else:
# lookup the unit symbols
unit_data = _get_unit_data_from_expr(unit_expr, registry.lut)
Repository URL: https://bitbucket.org/yt_analysis/yt/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the yt-svn
mailing list