[yt-svn] commit/yt: ngoldbaum: Merged in ngoldbaum/yt (pull request #1782)

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Mon Oct 5 11:13:00 PDT 2015


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/e624dbb8e008/
Changeset:   e624dbb8e008
Branch:      yt
User:        ngoldbaum
Date:        2015-10-05 18:12:41+00:00
Summary:     Merged in ngoldbaum/yt (pull request #1782)

Refactor base units transformation to avoid expensive as_coeff_exponent() calls
Affected #:  2 files

diff -r 4cbd4de67d20e65e062507ed6fa0dee102ac9ea8 -r e624dbb8e008780dfae3293256b67802b9463f0e yt/units/tests/test_ytarray.py
--- a/yt/units/tests/test_ytarray.py
+++ b/yt/units/tests/test_ytarray.py
@@ -467,6 +467,13 @@
     yield assert_equal, str(em3.in_mks().units), 'kg/(m*s**2)'
     yield assert_equal, str(em3.in_cgs().units), 'g/(cm*s**2)'
 
+    dimless = YTQuantity(1.0, "")
+    yield assert_equal, dimless.in_cgs(), dimless
+    yield assert_equal, dimless.in_cgs(), 1.0
+    yield assert_equal, dimless.in_mks(), dimless
+    yield assert_equal, dimless.in_mks(), 1.0
+    yield assert_equal, str(dimless.in_cgs().units), "dimensionless"
+
 def test_temperature_conversions():
     """
     Test conversions between various supported temperatue scales.

diff -r 4cbd4de67d20e65e062507ed6fa0dee102ac9ea8 -r e624dbb8e008780dfae3293256b67802b9463f0e yt/units/unit_object.py
--- a/yt/units/unit_object.py
+++ b/yt/units/unit_object.py
@@ -394,9 +394,15 @@
         # Use sympy to factor the dimensions into base CGS unit symbols.
         units = []
         my_dims = self.dimensions.expand()
-        for dim in base_units:
+        if my_dims is dimensionless:
+            return ""
+        for factor in my_dims.as_ordered_factors():
+            dim = list(factor.free_symbols)[0]
             unit_string = base_units[dim]
-            power_string = "**(%s)" % my_dims.as_coeff_exponent(dim)[1]
+            if factor.is_Pow:
+                power_string = "**(%s)" % factor.as_base_exp()[1]
+            else:
+                power_string = ""
             units.append("".join([unit_string, power_string]))
         return " * ".join(units)

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