Ejemplo n.º 1
0
    def _init_by_arrow(self, values, dtype: ArrowDtype = None, copy=False):
        if isinstance(values, (pd.Index, pd.Series)):
            # for pandas Index and Series,
            # convert to PandasArray
            values = values.array

        if isinstance(values, type(self)):
            arrow_array = values._arrow_array
        elif isinstance(values, ExtensionArray):
            # if come from pandas object like index,
            # convert to pandas StringArray first,
            # validation will be done in construct
            arrow_array = pa.chunked_array(
                [pa.array(values, from_pandas=True)])
        elif isinstance(values, pa.ChunkedArray):
            arrow_array = values
        elif isinstance(values, pa.Array):
            arrow_array = pa.chunked_array([values])
        else:
            arrow_array = pa.chunked_array(
                [pa.array(values, type=dtype.arrow_type)])

        if copy:
            arrow_array = copy_obj(arrow_array)

        self._use_arrow = True
        self._arrow_array = arrow_array
        self._dtype = dtype
Ejemplo n.º 2
0
def queue_mutants(*, progress, config, mutants_queue, mutations_by_file):
    from mutmut.cache import get_cached_mutation_statuses

    try:
        index = 0
        for filename, mutations in mutations_by_file.items():
            cached_mutation_statuses = get_cached_mutation_statuses(filename, mutations, config.hash_of_tests)
            with open(filename) as f:
                source = f.read()
            for mutation_id in mutations:
                cached_status = cached_mutation_statuses.get(mutation_id)
                if cached_status != UNTESTED:
                    progress.register(cached_status)
                    continue
                context = Context(
                    mutation_id=mutation_id,
                    filename=filename,
                    dict_synonyms=config.dict_synonyms,
                    config=copy_obj(config),
                    source=source,
                    index=index,
                )
                mutants_queue.put(('mutant', context))
                index += 1
    finally:
        mutants_queue.put(('end', None))
Ejemplo n.º 3
0
    def __init__(self, values, copy=False):
        if isinstance(values, (pd.Index, pd.Series)):
            # for pandas Index and Series,
            # convert to PandasArray
            values = values.array

        if isinstance(values, type(self)):
            arrow_array = values._arrow_array
        elif isinstance(values, ExtensionArray):
            # if come from pandas object like index,
            # convert to pandas StringArray first,
            # validation will be done in construct
            arrow_array = pa.chunked_array(
                [pa.array(values, from_pandas=True)])
        elif isinstance(values, pa.ChunkedArray):
            arrow_array = values
        elif isinstance(values, pa.StringArray):
            arrow_array = pa.chunked_array([values])
        else:
            arrow_array = pa.chunked_array(
                [pa.array(values, type=pa.string())])

        if copy:
            arrow_array = copy_obj(arrow_array)

        self._arrow_array = arrow_array
        self._dtype = ArrowStringDtype()

        # for test purpose
        self._force_use_pandas = False
Ejemplo n.º 4
0
def validate_attr(schema, value):
    new = copy_obj(value)

    for attr, schema in schema.schema.items():
        if not _hasattr(value, attr):
            raise ValueError("Attribute '{0}' not found on object '{1}'".format(
                attr, value
            ))

        setattr(new, attr, validate(schema, _getattr(value, attr)))

    return new
Ejemplo n.º 5
0
def validate_attr(schema, value):
    new = copy_obj(value)

    for attr, schema in schema.schema.items():
        if not _hasattr(value, attr):
            raise ValueError("Attribute '{0}' not found on object '{1}'".format(
                attr, value
            ))

        setattr(new, attr, validate(schema, _getattr(value, attr)))

    return new
Ejemplo n.º 6
0
 def event_marker(self, event):
     try:
         if self.player.time_elapsed > self.player.last_mark_time:
             byte_position = (self.player.wpl.byte_pos['data'] /
                              self.player.wpl.rel_pos['data']
                              ) * self.player.wpl.rel_pos['video']
             if 'start' in self.player.current_mark:
                 if self.player.time_elapsed > self.player.total_time - 2.0:
                     end_time = self.player.total_time
                     end_byte = -1.0
                 else:
                     end_time = self.player.time_elapsed
                     end_byte = byte_position
                 self.player.current_mark.setdefault(
                     'end', dict(byte=end_byte, time=end_time))
                 tmp_mark = copy_obj(self.player.current_mark)
                 self.player.current_mark.clear()
                 self.player.mark_list.append(tmp_mark)
                 self.player.last_mark_time = self.player.time_elapsed
                 new_bar = Image(repository=config.themes_dir +
                                 '/wybox/images/players/progressbar/',
                                 image_or_file='rec-progress.png')
                 new_bar.set_keep_real_size(False)
                 player_obj = pygui_globs['display'].get_obj_by_name(
                     'recedit_player')
                 mark_list_obj = player_obj.get_obj_by_name('mark_list')
                 mark_list_obj.add_child(new_bar,
                                         name='mark_bar',
                                         top='0%',
                                         left='100%',
                                         height='100%',
                                         width='0%',
                                         aspect=False)
             else:
                 if self.player.time_elapsed > 2.0:
                     start_time = self.player.time_elapsed
                     start_byte = byte_position
                 else:
                     start_time = 0.0
                     start_byte = 0.0
                 self.player.current_mark.setdefault(
                     'start', dict(byte=start_byte, time=start_time))
                 self.player.last_mark_time = self.player.time_elapsed
             sleep(1)
         else:
             MessageWindow(
                 title=_('Error'),
                 text=_('Enable to add mark before other')).show(timeout=3)
     except:
         print 'Enable to add mark'
     return True
Ejemplo n.º 7
0
 def copy(self):
     if self._use_arrow:
         return type(self)(copy_obj(self._arrow_array))
     else:
         return type(self)(self._ndarray.copy())
Ejemplo n.º 8
0
 def copy(self):
     return type(self)(copy_obj(self._arrow_array))