Exemple #1
0
 def __init__(
     self,
     name,
     field_type=arg.AUTO,
     nullable=False,
     aggr_hint=None,
 ):
     field_type = arg.acquire(field_type, FieldType.Any)
     if field_type is None:
         field_type = FieldType.detect_by_name(name)
     else:
         field_type = FieldType(field_type)
     super().__init__(name=name, field_type=field_type)
     assert isinstance(nullable, bool)
     self.nullable = nullable
     self.aggr_hint = aggr_hint
Exemple #2
0
def detect_schema_by_title_row(title_row: Iterable) -> StructInterface:
    struct = LegacyStruct([])
    for name in title_row:
        field_type = FieldType.detect_by_name(name)
        assert isinstance(field_type, FieldType)
        struct.append_field(LegacyField(name, field_type))
    return struct
Exemple #3
0
 def set_types(self, dict_field_types=None, inplace=False, **kwargs):
     for field_name, field_type in list(
         (dict_field_types or {}).items()) + list(kwargs.items()):
         field_description = self.get_field_description(field_name)
         assert isinstance(field_description, FieldInterface)
         canonic_type = FieldType.get_canonic_type(field_type)
         assert isinstance(canonic_type, FieldType)
         field_description.set_type(canonic_type, inplace=True)
     if not inplace:
         return self
Exemple #4
0
 def _get_struct_detected_by_title_row(
     cls,
     title_row: Iterable,
     types: Union[dict, Auto, None] = None,
 ) -> StructInterface:
     struct_class = cls._get_struct_class()
     if not Auto.is_defined(types):
         types = dict()
     detected_struct = struct_class([])
     for name in title_row:
         if name in types:
             field_type = FieldType.convert(types[name])
         else:
             field_type = FieldType.detect_by_name(name)
         detected_struct.append_field(name,
                                      default_type=field_type,
                                      exclude_duplicates=False,
                                      inplace=True)
     return detected_struct
Exemple #5
0
 def _get_struct_detected_by_title_row(
         cls, title_row: Iterable) -> StructInterface:
     struct_class = cls._get_struct_class()
     detected_struct = struct_class([])
     for name in title_row:
         field_type = FieldType.detect_by_name(name)
         # struct.append_field(AdvancedField(name, field_type))
         detected_struct.append_field(name,
                                      default_type=field_type,
                                      inplace=True)
     return detected_struct
Exemple #6
0
 def types(self,
           dict_field_types: Optional[dict] = None,
           **kwargs) -> Native:
     for field_name, field_type in list(
         (dict_field_types or {}).items()) + list(kwargs.items()):
         field = self.get_field_description(field_name)
         assert hasattr(
             field, 'set_type'
         ), 'Expected SimpleField or FieldDescription, got {}'.format(field)
         field.set_type(FieldType.detect_by_type(field_type), inplace=True)
     return self
Exemple #7
0
 def get_fields_tuples(self) -> Iterable[tuple]:  # (name, type, caption)
     for f in self.get_fields():
         if isinstance(f, AdvancedField):
             field_name = f.get_name()
             field_type_name = f.get_type_name()
             field_caption = f.get_caption() or ''
             field_is_valid = str(f.is_valid())
             group_name = f.get_group_name()
             group_caption = f.get_group_caption()
         elif isinstance(f, tuple) and len(f) == 2:  # old-style FieldDescription
             field_name = f[0]
             field_type_name = FieldType(f[1]).get_name()
             field_is_valid = '?'
             field_caption, group_name, group_caption = '', '', ''
         else:
             field_name = str(f)
             field_type_name = FieldType.get_default()
             field_caption, field_is_valid, group_name, group_caption = '', '', '', ''
         str_field_is_valid = DICT_VALID_SIGN.get(field_is_valid, field_is_valid[0])
         yield field_name, field_type_name, field_caption, str_field_is_valid, group_name, group_caption
Exemple #8
0
 def __init__(self,
              name: str,
              field_type: FieldType = FieldType.Any,
              properties=None):
     field_type = Auto.delayed_acquire(field_type,
                                       FieldType.detect_by_name,
                                       field_name=name)
     field_type = FieldType.get_canonic_type(field_type,
                                             ignore_missing=True)
     assert isinstance(
         field_type,
         FieldType), 'Expected FieldType, got {}'.format(field_type)
     self._type = field_type
     super().__init__(name=name, data=properties)
Exemple #9
0
 def get_struct_detected_by_title_row(title_row: Iterable) -> Native:
     struct = FlatStruct([])
     for name in title_row:
         field_type = FieldType.detect_by_name(name)
         struct.append_field(AdvancedField(name, field_type))
     return struct
Exemple #10
0
 def __init__(self, name: str, field_type: FieldType = FieldType.Any, properties=None):
     field_type = arg.acquire(field_type, FieldType.detect_by_name, field_name=name)
     field_type = FieldType.get_canonic_type(field_type)
     assert isinstance(field_type, FieldType)
     self._type = field_type
     super().__init__(name=name, data=properties)
Exemple #11
0
 def _detect_field_type_by_name(field_name) -> FieldType:
     field_type = FieldType.detect_by_name(field_name)
     assert isinstance(field_type, FieldType)
     return field_type