Skip to content

Commit

Permalink
[Doc] Add docstrings and versionadded for Units
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanwweber committed May 26, 2022
1 parent 0b60720 commit fe2dd53
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions interfaces/cython/cantera/units.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations
# This file is part of Cantera. See License.txt in the top-level directory or
# at https://cantera.org/license.txt for license and copyright information.
from __future__ import annotations

cdef class Units:
"""
Expand All @@ -19,23 +20,38 @@ cdef class Units:
if name:
self.units = CxxUnits(stringify(name), True)

def __repr__(self):
return f"<Units({pystr(self.units.str())}) at {id(self):0x}>"
def __repr__(self) -> str:
return f"<Units({str(self)}) at {id(self):0x}>"

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 dimensions:
def __get__(self):
dimensions = ("mass", "length", "time", "temperature", "current", "quantity")
return {d: self.units.dimension(stringify(d)) for d in dimensions}
@property
def dimensions(self) -> dict[str, str]:
"""A dictionary of the primary unit components to their dimensions.

property factor:
def __get__(self):
return self.units.factor()
.. versionadded:: 3.0
"""
dimensions = ("mass", "length", "time", "temperature", "current", "quantity")
return {d: self.dimension(d) for d in dimensions}

@property
def factor(self) -> float:
"""The factor required to convert from this unit to Cantera's base units.

.. versionadded:: 3.0
"""
return self.units.factor()

@staticmethod
cdef copy(CxxUnits other):
Expand Down

0 comments on commit fe2dd53

Please sign in to comment.