cpg_flow.targets.types
This module defines the Sex
enumeration, which represents the sex of an individual as specified in the PED format.
Classes: Sex (Enum): An enumeration representing the sex of an individual with values UNKNOWN, MALE, and FEMALE.
Methods:
Sex.parse(sex: str | int | None) -> Sex:
Parses a string or integer into a Sex
object. Accepts 'm', 'male', '1', 1 for MALE, 'f', 'female', '2', 2 for FEMALE, and 'u', 'unknown', '0', 0 for UNKNOWN. Raises a ValueError for unrecognized values.
Sex.__str__() -> str:
Returns the name of the `Sex` enumeration member as a string.
1""" 2This module defines the `Sex` enumeration, which represents the sex of an individual as specified in the PED format. 3 4Classes: 5 Sex (Enum): An enumeration representing the sex of an individual with values UNKNOWN, MALE, and FEMALE. 6 7Methods: 8 Sex.parse(sex: str | int | None) -> Sex: 9 Parses a string or integer into a `Sex` object. Accepts 'm', 'male', '1', 1 for MALE, 'f', 'female', '2', 2 for FEMALE, and 'u', 'unknown', '0', 0 for UNKNOWN. Raises a ValueError for unrecognized values. 10 11 Sex.__str__() -> str: 12 Returns the name of the `Sex` enumeration member as a string. 13 14""" 15 16from enum import Enum 17 18 19class Sex(Enum): 20 """ 21 Sex as in PED format 22 """ 23 24 UNKNOWN = 0 25 MALE = 1 26 FEMALE = 2 27 28 @staticmethod 29 def parse(sex: str | int | None) -> 'Sex': 30 """ 31 Parse a string into a Sex object. 32 """ 33 if sex: 34 _sex = sex.lower() if isinstance(sex, str) else sex 35 if _sex in ('m', 'male', '1', 1): 36 return Sex.MALE 37 if _sex in ('f', 'female', '2', 2): 38 return Sex.FEMALE 39 if _sex in ('u', 'unknown', '0', 0): 40 return Sex.UNKNOWN 41 raise ValueError(f'Unrecognised sex value {sex}') 42 return Sex.UNKNOWN 43 44 def __str__(self): 45 return self.name
class
Sex(enum.Enum):
20class Sex(Enum): 21 """ 22 Sex as in PED format 23 """ 24 25 UNKNOWN = 0 26 MALE = 1 27 FEMALE = 2 28 29 @staticmethod 30 def parse(sex: str | int | None) -> 'Sex': 31 """ 32 Parse a string into a Sex object. 33 """ 34 if sex: 35 _sex = sex.lower() if isinstance(sex, str) else sex 36 if _sex in ('m', 'male', '1', 1): 37 return Sex.MALE 38 if _sex in ('f', 'female', '2', 2): 39 return Sex.FEMALE 40 if _sex in ('u', 'unknown', '0', 0): 41 return Sex.UNKNOWN 42 raise ValueError(f'Unrecognised sex value {sex}') 43 return Sex.UNKNOWN 44 45 def __str__(self): 46 return self.name
Sex as in PED format
UNKNOWN =
<Sex.UNKNOWN: 0>
MALE =
<Sex.MALE: 1>
FEMALE =
<Sex.FEMALE: 2>
29 @staticmethod 30 def parse(sex: str | int | None) -> 'Sex': 31 """ 32 Parse a string into a Sex object. 33 """ 34 if sex: 35 _sex = sex.lower() if isinstance(sex, str) else sex 36 if _sex in ('m', 'male', '1', 1): 37 return Sex.MALE 38 if _sex in ('f', 'female', '2', 2): 39 return Sex.FEMALE 40 if _sex in ('u', 'unknown', '0', 0): 41 return Sex.UNKNOWN 42 raise ValueError(f'Unrecognised sex value {sex}') 43 return Sex.UNKNOWN
Parse a string into a Sex object.