From aef1843f715088c5f5bd0fd0738eee30b0b168d5 Mon Sep 17 00:00:00 2001 From: Bryan Weber Date: Wed, 25 May 2022 04:55:49 -0400 Subject: [PATCH] [Doc] Add docstrings and versionadded for Units --- interfaces/cython/cantera/composite.py | 4 ++-- interfaces/cython/cantera/thermo.pyx | 4 ++-- interfaces/cython/cantera/units.pyx | 21 +++++++++++++++------ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/interfaces/cython/cantera/composite.py b/interfaces/cython/cantera/composite.py index cde50cddb5..6119aedd95 100644 --- a/interfaces/cython/cantera/composite.py +++ b/interfaces/cython/cantera/composite.py @@ -669,7 +669,7 @@ def ndim(self) -> int: def shape(self) -> tuple[int, ...]: """The shape of the SolutionArray. - .. versionadded: 3.0 + .. versionadded:: 3.0 :return: A tuple of integers with the number of elements in each dimension. """ @@ -679,7 +679,7 @@ def shape(self) -> tuple[int, ...]: def size(self) -> int: """The number of elements in the SolutionArray. - .. versionadded: 3.0 + .. versionadded:: 3.0 """ return np.prod(self.shape) diff --git a/interfaces/cython/cantera/thermo.pyx b/interfaces/cython/cantera/thermo.pyx index e00f0bb034..e2fed396fa 100644 --- a/interfaces/cython/cantera/thermo.pyx +++ b/interfaces/cython/cantera/thermo.pyx @@ -732,10 +732,10 @@ cdef class ThermoPhase(_SolutionBase): :param basis: Determines if ``fuel`` and ``oxidizer`` are given in mole fractions (``basis='mole'``) or mass fractions (``basis='mass'``) - :param: diluent: + :param diluent: Optional parameter. Required if dilution is used. Specifies the composition of the diluent in mole/mass fractions as a string, array or dict - :param: fraction: + :param fraction: Optional parameter. Dilutes the fuel/oxidizer mixture with the diluent according to ``fraction``. Fraction can refer to the fraction of diluent in the mixture (for example ``fraction="diluent:0.7`` will create a mixture diff --git a/interfaces/cython/cantera/units.pyx b/interfaces/cython/cantera/units.pyx index 4e6960baa3..54aa7925f2 100644 --- a/interfaces/cython/cantera/units.pyx +++ b/interfaces/cython/cantera/units.pyx @@ -19,20 +19,29 @@ cdef class Units: if name: self.units = CxxUnits(stringify(name), True) - def __repr__(self): - return f"" + def __repr__(self) -> str: + return f"" - def __str__(self): + def __str__(self) -> str: return pystr(self.units.str()) - def dimension(self, primary): + def dimension(self, primary: str) -> float: + """The dimension of the given unit component. + + .. versionadded:: 3.0 + + :param primary: + A string with the desired unit component. One of ``"mass"``, + ``"length"``, ``"time"``, ``"temperature"``, ``"current"``, or + ``"quantity"``. + """ return self.units.dimension(stringify(primary)) @property def dimensions(self) -> Dict[str, str]: """A dictionary of the primary unit components to their dimensions. - .. versionadded: 3.0 + .. versionadded:: 3.0 """ dimensions = ("mass", "length", "time", "temperature", "current", "quantity") return {d: self.dimension(d) for d in dimensions} @@ -41,7 +50,7 @@ cdef class Units: def factor(self) -> float: """The factor required to convert from this unit to Cantera's base units. - .. versionadded: 3.0 + .. versionadded:: 3.0 """ return self.units.factor()