Skip to content

Commit

Permalink
Merge pull request #71 from python-thread/feature/dataframe-support
Browse files Browse the repository at this point in the history
Feature: dataframe support
  • Loading branch information
caffeine-addictt committed Mar 16, 2024
2 parents 49a9dcd + 23a2b1f commit 2a89bf5
Show file tree
Hide file tree
Showing 13 changed files with 634 additions and 69 deletions.
13 changes: 5 additions & 8 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@ identifiers:
- type: doi
value: 10.5281/zenodo.10799219
description: This is the collection of archived snapshots of all versions of thread.
- type: doi
value: 10.5281/zenodo.10808243
description: This is the archived snapshot of version 1.0.1 of thread.
- type: url
value: https://github.com/python-thread/thread/releases/tag/v1.0.1
description: The GitHub release URL of tag v1.0.1.
value: https://github.com/python-thread/thread/releases/tag/v1.1.0
description: The GitHub release URL of tag v1.1.0.
- type: url
value: https://pypi.org/project/thread/1.0.1
description: The PyPI release URL of tag v1.0.1.
value: https://pypi.org/project/thread/1.1.0
description: The PyPI release URL of tag v1.1.0.
cff-version: 1.2.0
date-released: 2024-03-07
keywords:
Expand All @@ -35,6 +32,6 @@ repository-code: https://github.com/python-thread/thread
repository-artifact: https://pypi.org/project/thread
title: thread
type: software
version: 1.0.1
version: 1.1.0
url: https://thread.ngjx.org

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Our docs are [here!](https://thread.ngjx.org)
<!-- ROADMAP -->
## Roadmap

- [x] v1.0.0 Release
- [x] v1.1.0 Release
- [ ] Bug fixes
- [ ] New features
- [ ] Testing
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "thread"
version = "1.0.1"
version = "1.1.0"
description = "Threading module extension"
authors = ["Alex <contact@ngjx.org>"]
license = "BSD-3-Clause"
Expand Down
4 changes: 2 additions & 2 deletions src/thread/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
## Thread Library
Documentation at https://thread.ngjx.org/docs/v1.0.0
Documentation at https://thread.ngjx.org/docs/v1.1.0
---
Expand All @@ -18,7 +18,7 @@
"""


__version__ = '1.0.1'
__version__ = '1.1.0'


# Export Core
Expand Down
35 changes: 31 additions & 4 deletions src/thread/_types.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
"""
## Types
Documentation: https://thread.ngjx.org/docs/v1.0.0
Documentation: https://thread.ngjx.org/docs/v1.1.0
"""

from typing import Any, Literal, Callable, Union
from typing_extensions import ParamSpec, TypeVar, Concatenate
from typing import Any, Literal, Callable, Union, Sized
from typing_extensions import (
ParamSpec,
TypeVar,
Concatenate,
Protocol,
runtime_checkable,
)


# Descriptive Types
Expand Down Expand Up @@ -33,5 +39,26 @@

HookFunction = Callable[[_Target_T], Union[Any, None]]

_Dataset_T = TypeVar('_Dataset_T')
_Dataset_T = TypeVar('_Dataset_T', covariant=True)
DatasetFunction = Callable[Concatenate[_Dataset_T, _Target_P], _Target_T]


# Protocols
@runtime_checkable
class SupportsLength(Sized, Protocol):
pass


_SupportsGetItem_T = TypeVar('_SupportsGetItem_T')


@runtime_checkable
class SupportsGetItem(Protocol[_SupportsGetItem_T]):
__getitem__: Callable[..., _SupportsGetItem_T]


# Looks like having this inherit __getitem__ from SupportsGetItem breaks isinstance checks in python3.12
# Thus we explicitly define it
@runtime_checkable
class SupportsLengthGetItem(Sized, Protocol[_SupportsGetItem_T]):
__getitem__: Callable[..., _SupportsGetItem_T]
33 changes: 19 additions & 14 deletions src/thread/decorators/_processor.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,50 @@
"""
## Processor
Documentation: https://thread.ngjx.org/docs/v1.0.0
Documentation: https://thread.ngjx.org/docs/v1.1.0
"""

from functools import wraps
from ..thread import ParallelProcessing

from .._types import Overflow_In, Data_In
from typing import Callable, Mapping, Sequence, Optional, Union, overload
from .._types import (
Overflow_In,
Data_In,
SupportsGetItem,
SupportsLength,
SupportsLengthGetItem,
)
from typing import Any, Callable, Mapping, Sequence, Optional, Union, overload
from typing_extensions import ParamSpec, TypeVar, Concatenate


_TargetT = TypeVar('_TargetT')
_TargetP = ParamSpec('_TargetP')
_DataT = TypeVar('_DataT')
TargetFunction = Callable[Concatenate[_DataT, _TargetP], _TargetT]
Dataset = Union[
SupportsLengthGetItem[_DataT], SupportsGetItem[_DataT], SupportsLength, Any
]


NoParamReturn = Callable[
Concatenate[Sequence[_DataT], _TargetP],
Concatenate[Dataset[_DataT], _TargetP],
ParallelProcessing[_TargetP, _TargetT, _DataT],
]
WithParamReturn = Callable[
[TargetFunction[_DataT, _TargetP, _TargetT]],
NoParamReturn[_DataT, _TargetP, _TargetT],
]
FullParamReturn = Callable[
Concatenate[Sequence[_DataT], _TargetP],
Concatenate[Dataset[_DataT], _TargetP],
ParallelProcessing[_TargetP, _TargetT, _DataT],
]


@overload
def processor(
__function: TargetFunction[_DataT, _TargetP, _TargetT],
) -> NoParamReturn[_DataT, _TargetP, _TargetT]:
...
) -> NoParamReturn[_DataT, _TargetP, _TargetT]: ...


@overload
Expand All @@ -47,8 +55,7 @@ def processor(
ignore_errors: Sequence[type[Exception]] = (),
suppress_errors: bool = False,
**overflow_kwargs: Overflow_In,
) -> WithParamReturn[_DataT, _TargetP, _TargetT]:
...
) -> WithParamReturn[_DataT, _TargetP, _TargetT]: ...


@overload
Expand All @@ -60,8 +67,7 @@ def processor(
ignore_errors: Sequence[type[Exception]] = (),
suppress_errors: bool = False,
**overflow_kwargs: Overflow_In,
) -> FullParamReturn[_DataT, _TargetP, _TargetT]:
...
) -> FullParamReturn[_DataT, _TargetP, _TargetT]: ...


def processor(
Expand Down Expand Up @@ -106,8 +112,7 @@ def processor(
You can also pass keyword arguments to change the thread behaviour, it otherwise follows the defaults of `thread.Thread`
>>> @thread.threaded(daemon = True)
>>> def myfunction():
... ...
>>> def myfunction(): ...
Args will be ordered infront of function-parsed args parsed into `thread.Thread.args`
>>> @thread.threaded(args = (1))
Expand Down Expand Up @@ -142,7 +147,7 @@ def wrapper(

@wraps(__function)
def wrapped(
data: Sequence[_DataT],
data: Dataset[_DataT],
*parsed_args: _TargetP.args,
**parsed_kwargs: _TargetP.kwargs,
) -> ParallelProcessing[_TargetP, _TargetT, _DataT]:
Expand Down
14 changes: 5 additions & 9 deletions src/thread/decorators/_threaded.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
## Threaded
Documentation: https://thread.ngjx.org/docs/v1.0.0
Documentation: https://thread.ngjx.org/docs/v1.1.0
"""

from functools import wraps
Expand All @@ -23,8 +23,7 @@


@overload
def threaded(__function: TargetFunction[P, T]) -> NoParamReturn[P, T]:
...
def threaded(__function: TargetFunction[P, T]) -> NoParamReturn[P, T]: ...


@overload
Expand All @@ -35,8 +34,7 @@ def threaded(
ignore_errors: Sequence[type[Exception]] = (),
suppress_errors: bool = False,
**overflow_kwargs: Overflow_In,
) -> WithParamReturn[P, T]:
...
) -> WithParamReturn[P, T]: ...


@overload
Expand All @@ -48,8 +46,7 @@ def threaded(
ignore_errors: Sequence[type[Exception]] = (),
suppress_errors: bool = False,
**overflow_kwargs: Overflow_In,
) -> FullParamReturn[P, T]:
...
) -> FullParamReturn[P, T]: ...


def threaded(
Expand Down Expand Up @@ -90,8 +87,7 @@ def threaded(
You can also pass keyword arguments to change the thread behaviour, it otherwise follows the defaults of `thread.Thread`
>>> @thread.threaded(daemon = True)
>>> def myfunction():
... ...
>>> def myfunction(): ...
Args will be ordered infront of function-parsed args parsed into `thread.Thread.args`
>>> @thread.threaded(args = (1))
Expand Down
2 changes: 1 addition & 1 deletion src/thread/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
## Thread Exceptions
Documentation: https://thread.ngjx.org/docs/v1.0.0
Documentation: https://thread.ngjx.org/docs/v1.1.0
"""

import traceback
Expand Down

0 comments on commit 2a89bf5

Please sign in to comment.