How to use the lineflow.core.DatasetMixin function in lineflow

To help you get started, we’ve selected a few lineflow examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tofunlp / lineflow / tests / test_core.py View on Github external
def test_dunder_iter(self):
        class ImplementedIter(DatasetMixin):
            def __iter__(self):
                return super(ImplementedIter, self).__iter__()

            def get_example(self): ...

            def __len__(self): ...

        d = ImplementedIter()
        self.assertListEqual([], list(d))
github tofunlp / lineflow / tests / test_core.py View on Github external
def test_dunder_len(self):
        class ImplementedLen(DatasetMixin):
            def __iter__(self): ...

            def get_example(self, i): ...

            def __len__(self):
                return super(ImplementedLen, self).__len__()

        d = ImplementedLen()
        self.assertEqual(len(d), 0)
github tofunlp / lineflow / tests / test_core.py View on Github external
def test_get_example(self):
        class ImplementedGetExample(DatasetMixin):
            def __iter__(self): ...

            def get_example(self, i):
                return super(ImplementedGetExample, self).get_example(i)

            def __len__(self):
                return 1

        d = ImplementedGetExample()
        with self.assertRaises(IndexError):
            d[0]
github tofunlp / lineflow / tests / test_core.py View on Github external
def test_acts_list(self):
        self.assertIsInstance([], DatasetMixin)
github tofunlp / lineflow / tests / test_core.py View on Github external
def test_dunder_subclasshook(self):
        class Dummy(DatasetMixin):
            def __iter__(self): ...

            def get_example(self, i): ...

            def __len__(self): ...
        self.assertEqual(Dummy.__subclasshook__(Dummy),
                         NotImplemented)
github tofunlp / lineflow / tests / test_core.py View on Github external
def test_acts_tuple(self):
        self.assertIsInstance((), DatasetMixin)
github tofunlp / lineflow / lineflow / core.py View on Github external
def __len__(self) -> int:
        return 0

    @classmethod
    def __subclasshook__(cls, C):
        if cls is DatasetMixin:
            return _check_methods(C, '__iter__', 'get_example', '__len__')
        return NotImplemented


DatasetMixin.register(Sequence)
DatasetMixin.register(easyfile.TextFile)
DatasetMixin.register(easyfile.CsvFile)


class Dataset(DatasetMixin):
    """Dataset wrapping ``DatasetMixin`` object.

    Args:
        dataset (DatasetMixin): ``Sequence``, ``easyfile.TextFile``, or ``easyfile.CsvFile`` object.
    """

    def __init__(self,
                 dataset: DatasetMixin) -> None:
        assert isinstance(dataset, DatasetMixin)

        self._dataset = dataset
        self._length = None

    def __iter__(self) -> Iterator[Any]:
        yield from self._dataset
github tofunlp / lineflow / lineflow / core.py View on Github external
raise IndexError

    @abstractmethod
    def __len__(self) -> int:
        return 0

    @classmethod
    def __subclasshook__(cls, C):
        if cls is DatasetMixin:
            return _check_methods(C, '__iter__', 'get_example', '__len__')
        return NotImplemented


DatasetMixin.register(Sequence)
DatasetMixin.register(easyfile.TextFile)
DatasetMixin.register(easyfile.CsvFile)


class Dataset(DatasetMixin):
    """Dataset wrapping ``DatasetMixin`` object.

    Args:
        dataset (DatasetMixin): ``Sequence``, ``easyfile.TextFile``, or ``easyfile.CsvFile`` object.
    """

    def __init__(self,
                 dataset: DatasetMixin) -> None:
        assert isinstance(dataset, DatasetMixin)

        self._dataset = dataset
        self._length = None
github tofunlp / lineflow / lineflow / core.py View on Github external
def __subclasshook__(cls, C):
        if cls is DatasetMixin:
            return _check_methods(C, '__iter__', 'get_example', '__len__')
        return NotImplemented
github tofunlp / lineflow / lineflow / core.py View on Github external
def __init__(self, *datasets: List[DatasetMixin]) -> None:
        assert all(isinstance(d, DatasetMixin) for d in datasets)
        self._datasets = datasets
        self._length = None