Skip to content

Commit 33d412f

Browse files
committed
EHN: Add tex and __getitem__ docstring
1 parent 6543d0c commit 33d412f

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

labfis/uncertainty.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -252,27 +252,29 @@ def split(self) -> List[str]:
252252
m, u = self.__round__()
253253
return ["{:g}".format(m), "{:g}".format(u)]
254254

255-
def tex(self, precision: Union[Set[int], int] = None, round_p: int = 0) -> str:
255+
def tex(self, precision: Union[Tuple[float], float] = None, round_p: int = 0) -> str:
256256
"""Convert labfloat to string representation in LaTex format.
257257
258-
Precision and round_p is used to configure the display precision and round
259-
decimal places.
258+
The arguments precision and round_p are used to configure the display precision and round
259+
decimal places. The precision is a float in "0.0" format.
260260
261261
Args:
262-
precision (Union[Set[int], int], optional): [description]. Defaults to None.
263-
round_p (int, optional): [description]. Defaults to 0.
262+
precision (Union[Tuple[float], float], optional): A tuple containing the mean's and error's precision or only one string for both precisions. If no value are passed the default precision. Defaults to None.
263+
round_p (int, optional): Number of decimals to use when rounding. Defaults to 0.
264264
265265
Raises:
266-
LabFloatError: [description]
266+
LabFloatError: Error in parsing arguments, where the number of precision tuple is greater than 2.
267267
268268
Returns:
269-
str: [description]
269+
str: labfloat's strig representation in LaTex format.
270270
271271
"""
272-
if len(precision) > 2:
273-
raise LabFloatError(4, precision)
274-
275-
precision = [precision[0], precision[0]]
272+
if isinstance(precision, tuple):
273+
if len(precision) > 2:
274+
raise LabFloatError(4, precision)
275+
precision = (float(precision[0]), float(precision[1]))
276+
elif precision:
277+
precision = (float(precision), float(precision))
276278

277279
if self._uncertainty == 0:
278280
if precision:
@@ -337,7 +339,7 @@ def uncertainty(self) -> object:
337339
"""object: labfloat's error."""
338340
return self._uncertainty
339341

340-
def __getitem__(self, idx: int) -> Set[object]:
342+
def __getitem__(self, idx: int) -> Tuple[object]:
341343
"""Represent the labfloat as an tuple.
342344
343345
This method indexes the labfloat's attributes mean and erro as an tuple object.
@@ -347,7 +349,7 @@ def __getitem__(self, idx: int) -> Set[object]:
347349
idx (int): idex position of the labfis tuple representation
348350
349351
Returns:
350-
Set[object]: [description]
352+
Tuple[object]: A tuple with labfloat's mean and error.
351353
352354
Example:
353355
>>> a, b = labfloat(1,3)

0 commit comments

Comments
 (0)