-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move optypes into separate file * Rename ChainStart to Chain and StreamStart to Stream * Add .then and pipe operations, as aliases to flat_map * Bump version to 0.3 * Remove functions in chain, move to a more functional approach of modifying the functions * Remove .map, .filter etc functions in Stream, moving to a more functional approach * Rename batching to batched
- Loading branch information
Showing
15 changed files
with
309 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api" | |
|
||
[tool.poetry] | ||
name = "pipedata" | ||
version = "0.2.2" | ||
version = "0.3" | ||
description = "Framework for building pipelines for data processing" | ||
authors = ["Simon Wicks <[email protected]>"] | ||
readme = "README.md" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
__version__ = "0.2.2" | ||
__version__ = "0.3" | ||
|
||
__all__ = [ | ||
"__version__", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
from .chain import Chain, ChainStart | ||
from .stream import Stream, StreamStart | ||
from .chain import Chain, ChainType | ||
from .stream import Stream, StreamType | ||
|
||
__all__ = [ | ||
"ChainType", | ||
"Chain", | ||
"ChainStart", | ||
"StreamType", | ||
"Stream", | ||
"StreamStart", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from typing import ( | ||
Callable, | ||
Generic, | ||
Iterator, | ||
Optional, | ||
Tuple, | ||
TypeVar, | ||
) | ||
|
||
TStart = TypeVar("TStart") | ||
TEnd = TypeVar("TEnd") | ||
TOther = TypeVar("TOther") | ||
|
||
|
||
class CountingIterator(Iterator[TStart]): | ||
def __init__(self, iterator: Iterator[TStart]) -> None: | ||
self._iterator = iterator | ||
self._count = 0 | ||
|
||
def __iter__(self) -> Iterator[TStart]: | ||
return self | ||
|
||
def __next__(self) -> TStart: | ||
self._count += 1 | ||
try: | ||
return next(self._iterator) | ||
except StopIteration as err: | ||
self._count -= 1 | ||
raise StopIteration from err | ||
|
||
def get_count(self) -> int: | ||
return self._count | ||
|
||
|
||
class ChainLink(Generic[TStart, TEnd]): | ||
def __init__( | ||
self, | ||
func: Callable[[Iterator[TStart]], Iterator[TEnd]], | ||
) -> None: | ||
self._func = func | ||
self._input: Optional[CountingIterator[TStart]] = None | ||
self._output: Optional[CountingIterator[TEnd]] = None | ||
|
||
@property | ||
def __name__(self) -> str: # noqa: A003 | ||
return self._func.__name__ | ||
|
||
def __call__(self, input_iterator: Iterator[TStart]) -> Iterator[TEnd]: | ||
self._input = CountingIterator(input_iterator) | ||
self._output = CountingIterator(self._func(self._input)) | ||
return self._output | ||
|
||
def get_counts(self) -> Tuple[int, int]: | ||
return ( | ||
0 if self._input is None else self._input.get_count(), | ||
0 if self._output is None else self._output.get_count(), | ||
) |
Oops, something went wrong.