Exemplo n.º 1
0
 def unit(self, field):
     """Unit for values in a given field"""
     mainfield, _, subfield = field.partition(".")
     try:
         return self._fields[mainfield].unit(subfield)
     except KeyError:
         raise exceptions.FieldDoesNotExistError(f"Field {mainfield!r} does not exist") from None
Exemplo n.º 2
0
 def set_unit(self, field, new_unit):
     """Update the unit of a given field"""
     mainfield, _, subfield = field.partition(".")
     try:
         return self._fields[mainfield].set_unit(subfield, new_unit)
     except KeyError:
         raise exceptions.FieldDoesNotExistError(f"Field {mainfield!r} does not exist") from None
Exemplo n.º 3
0
 def field(self, fieldname: str) -> "FieldType":
     """Return the field matching the given fieldname"""
     mainfield, _, subfield = fieldname.partition(".")
     try:
         field = self._fields[mainfield]
     except KeyError:
         raise exceptions.FieldDoesNotExistError(f"Field {mainfield!r} does not exist") from None
     if subfield:
         field_data = field.data
         try:
             # Recursive call for collections
             field = field_data.field(subfield)
         except AttributeError:
             # field_data does not have a function field
             # Only collections should have this function
             pass
     return field
Exemplo n.º 4
0
    def unit(cls, field: str = "") -> Tuple[str, ...]:
        """Unit of field"""
        mainfield, _, subfield = field.partition(".")

        # Units of direction array
        if not field:
            return cls._units
        # Unit of columns in direction array
        elif field in cls.column_names:
            return (cls._units[cls.column_names.index(field)], )
        # Units of properties
        elif field in _UNITS:
            return _UNITS[field]
        # Units of systems
        elif mainfield in _SYSTEMS:
            return _SYSTEMS[mainfield].unit(subfield)
        else:
            raise exceptions.FieldDoesNotExistError(
                f"Field {mainfield!r} does not exist") from None