<commit_before>from __future__ import absolute_import, division, print_function

from .bitmap import bitmap
from .index_update import IndexUpdate
from .changemanager_base import BaseChangeManager
from .slot import Slot


class BitmapChangeManager(BaseChangeManager):
    """
    Manage changes that occured in a DataFrame between runs.
    """
    def __init__(self,
                 slot,
                 buffer_created=True,
                 buffer_updated=False,
                 buffer_deleted=True,
                 manage_columns=False):
        super(BitmapChangeManager, self).__init__(
            slot,
            buffer_created,
            buffer_updated,
            buffer_deleted,
            manage_columns)
        self._last_bm = None

    def reset(self, mid=None):
        super(BitmapChangeManager, self).reset(mid)
        self._last_bm = None

    def compute_updates(self, data):
        last_bm = self._last_bm
        changes = IndexUpdate()
        if last_bm is None:
            if self.created.buffer:
                changes.created.update(data)
        else:
            if self.created.buffer:
                changes.created.update(data-last_bm)
            if self.deleted.buffer:
                changes.deleted.update(last_bm-data)
        self._last_bm = bitmap(data)
        return changes

    def update(self, run_number, data, mid=None):
        # pylint: disable=unused-argument
        assert isinstance(data, bitmap)
        if data is None or (run_number != 0 and
                            run_number <= self._last_update):
            return

        changes = self.compute_updates(data)
        self._last_update = run_number
        self._row_changes.combine(changes,
                                  self.created.buffer,
                                  self.updated.buffer,
                                  self.deleted.buffer)


Slot.add_changemanager_type(bitmap, BitmapChangeManager)<commit_msg>add cleanup prameter for compatibility<commit_after>from __future__ import absolute_import, division, print_function

from .bitmap import bitmap
from .index_update import IndexUpdate
from .changemanager_base import BaseChangeManager
from .slot import Slot


class BitmapChangeManager(BaseChangeManager):
    """
    Manage changes that occured in a DataFrame between runs.
    """
    def __init__(self,
                 slot,
                 buffer_created=True,
                 buffer_updated=False,
                 buffer_deleted=True,
                 manage_columns=False):
        super(BitmapChangeManager, self).__init__(
            slot,
            buffer_created,
            buffer_updated,
            buffer_deleted,
            manage_columns)
        self._last_bm = None

    def reset(self, mid=None):
        super(BitmapChangeManager, self).reset(mid)
        self._last_bm = None

    def compute_updates(self, data):
        last_bm = self._last_bm
        changes = IndexUpdate()
        if last_bm is None:
            if self.created.buffer:
                changes.created.update(data)
        else:
            if self.created.buffer:
                changes.created.update(data-last_bm)
            if self.deleted.buffer:
                changes.deleted.update(last_bm-data)
        self._last_bm = bitmap(data)
        return changes

    def update(self, run_number, data, mid=None, cleanup=True):
        # pylint: disable=unused-argument
        assert isinstance(data, bitmap)
        if data is None or (run_number != 0 and
                            run_number <= self._last_update):
            return

        changes = self.compute_updates(data)
        self._last_update = run_number
        self._row_changes.combine(changes,
                                  self.created.buffer,
                                  self.updated.buffer,
                                  self.deleted.buffer)


Slot.add_changemanager_type(bitmap, BitmapChangeManager)
{'fraction_non_alphanumeric': 0.07086813464945584, 'fraction_numerical': 0.0005062009617818274, 'mean_word_length': 1.822857142857143, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '920613', 'n_tokens_mistral': 1027, 'n_tokens_neox': 1008, 'n_words': 228}