Esempio n. 1
0
def not_in(*list_values) -> Callable:
    list_values = update(list_values)

    def func(value: Any) -> bool:
        return value not in list_values

    return func
Esempio n. 2
0
 def func(*args) -> bool:
     args = update(args)
     assert len(
         args
     ) == 3, 'is_local_extreme.func(): Expected 3 arguments, got {}'.format(
         args)
     return nm.is_local_extreme(*args,
                                local_min=local_min,
                                local_max=local_max)
Esempio n. 3
0
def is_in(*list_values, or_none: bool = False) -> Callable:
    if list_values == (None, ) or not list_values:
        if or_none:
            return lambda v: True
        else:
            return lambda v: False
    list_values = update(list_values)

    def func(value: Any) -> bool:
        return value in list_values

    return func
Esempio n. 4
0
 def remove_fields(self,
                   *fields,
                   multiple: bool = False,
                   inplace: bool = True):
     removing_fields = update(fields)
     removing_field_names = get_names(removing_fields)
     existing_fields = self.get_fields()
     if inplace:
         for e in existing_fields:
             if get_name(e) in removing_field_names:
                 existing_fields.remove(e)
                 if not multiple:
                     break
     else:
         new_fields = [
             f for f in existing_fields
             if get_name(f) not in removing_field_names
         ]
         return self.make_new(new_fields)
Esempio n. 5
0
 def sort(self,
          *keys,
          reverse: bool = False,
          step: AutoCount = AUTO,
          verbose: AutoBool = True) -> Native:
     keys = update(keys)
     step = Auto.delayed_acquire(step, self.get_limit_items_in_memory)
     if len(keys) == 0:
         key_function = fs.same()
     else:
         key_function = fs.composite_key(keys)
     if self.can_be_in_memory(step=step) or step is None:
         stream = self.memory_sort(key_function,
                                   reverse=reverse,
                                   verbose=verbose)
     else:
         stream = self.disk_sort(key_function,
                                 reverse=reverse,
                                 step=step,
                                 verbose=verbose)
     return self._assume_native(stream)
Esempio n. 6
0
def get_composite_key(item,
                      keys_descriptions: list,
                      item_type=AUTO,
                      logger=None,
                      skip_errors=True) -> tuple:
    keys_descriptions = update(keys_descriptions)
    keys_descriptions = [
        d.get_field_names() if hasattr(d, 'get_field_names') else d
        for d in keys_descriptions
    ]
    result = list()
    for d in keys_descriptions:
        if isinstance(d, Callable):
            value = d(item)
        else:
            value = value_from_item(item,
                                    d,
                                    item_type=item_type,
                                    logger=logger,
                                    skip_errors=skip_errors)
        result.append(value)
    return tuple(result)
Esempio n. 7
0
 def sorted_join(
     self,
     right: Native,
     key: UniKey,
     how: How = JoinType.Left,
     sorting_is_reversed: bool = False,
 ) -> Native:
     keys = update([key])
     if not isinstance(how, JoinType):
         how = JoinType(how)
     joined_items = algo.sorted_join(
         iter_left=self.get_iter(),
         iter_right=right.get_iter(),
         key_function=fs.composite_key(keys),
         merge_function=fs.merge_two_items(),
         order_function=bf.is_ordered(reverse=sorting_is_reversed,
                                      including=True),
         how=how,
     )
     stream = self.stream(
         list(joined_items) if self.is_in_memory() else joined_items,
         **self.get_static_meta())
     return self._assume_native(stream)
Esempio n. 8
0
 def map_side_join(
     self,
     right: Native,
     key,
     how: How = JoinType.Left,
     right_is_uniq: bool = True,
     inplace: bool = False,
 ) -> Native:
     key = get_names(key)
     keys = update([key])
     if not isinstance(how, JoinType):
         how = JoinType(how)
     joined_items = map_side_join(
         iter_left=self.get_items(),
         iter_right=right.get_items(),
         key_function=fs.composite_key(keys),
         merge_function=fs.merge_two_items(),
         dict_function=fs.items_to_dict(),
         how=how,
         uniq_right=right_is_uniq,
     )
     if self.is_in_memory():
         joined_items = list(joined_items)
     return self.set_items(joined_items, inplace=inplace)
Esempio n. 9
0
 def add_fields(
     self,
     *fields,
     default_type: Optional[Type] = None,
     exclude_duplicates: bool = False,
     name: StructName = None,
     reassign_struct_name: bool = False,
     inplace: bool = False,
 ) -> Optional[Native]:
     fields = update(fields)
     if inplace:
         for f in fields:
             self.append(
                 f,
                 default_type=default_type,
                 exclude_duplicates=exclude_duplicates,
                 reassign_struct_name=reassign_struct_name,
                 inplace=True,
             )
     else:
         struct = self.make_new(fields=self.get_fields_descriptions() +
                                list(fields),
                                name=name)
         return self._assume_native(struct)