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

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Mon Mar 21 16:00:03 PDT 2016


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/de823c10fed9/
Changeset:   de823c10fed9
Branch:      yt
User:        ngoldbaum
Date:        2016-03-21 22:59:57+00:00
Summary:     Merged in MatthewTurk/yt (pull request #2060)

Make latex_repr a property, computed on-demand.
Affected #:  1 file

diff -r bed01b2c838c2b3a19b4c90c04bacc9e057abf07 -r de823c10fed9f0b5fd4acf0512c45fc7d9cc491a yt/units/unit_object.py
--- a/yt/units/unit_object.py
+++ b/yt/units/unit_object.py
@@ -133,7 +133,7 @@
 
     # Extra attributes
     __slots__ = ["expr", "is_atomic", "base_value", "base_offset", "dimensions",
-                 "registry", "latex_repr"]
+                 "registry", "_latex_repr"]
 
     def __new__(cls, unit_expr=sympy_one, base_value=None, base_offset=0.0,
                 dimensions=None, registry=None, latex_repr=None, **assumptions):
@@ -223,8 +223,6 @@
             # check that dimensions is valid
             if dimensions is not None:
                 validate_dimensions(dimensions)
-            if latex_repr is None:
-                latex_repr = get_latex_representation(unit_expr, registry)
         else:
             # lookup the unit symbols
             unit_data = _get_unit_data_from_expr(unit_expr, registry.lut)
@@ -235,7 +233,6 @@
                 latex_repr = unit_data[3]
             else:
                 base_offset = 0.0
-                latex_repr = get_latex_representation(unit_expr, registry)
 
         # Create obj with superclass construct.
         obj = Expr.__new__(cls, **assumptions)
@@ -246,7 +243,7 @@
         obj.base_value = base_value
         obj.base_offset = base_offset
         obj.dimensions = dimensions
-        obj.latex_repr = latex_repr
+        obj._latex_repr = latex_repr
         obj.registry = registry
 
         if unit_key is not None:
@@ -256,6 +253,14 @@
 
         return obj
 
+    _latex_expr = None
+    @property
+    def latex_repr(self):
+        if self._latex_repr is not None:
+            return self._latex_repr
+        self._latex_repr = get_latex_representation(self.expr, self.registry)
+        return self._latex_repr
+
     ### Some sympy conventions
     def __getnewargs__(self):
         return (self.expr, self.is_atomic, self.base_value, self.dimensions,

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