Skip to content

Commit 2a89bf5

Browse files
Merge pull request #71 from python-thread/feature/dataframe-support
Feature: dataframe support
2 parents 49a9dcd + 23a2b1f commit 2a89bf5

File tree

13 files changed

+634
-69
lines changed

13 files changed

+634
-69
lines changed

CITATION.cff

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,12 @@ identifiers:
88
- type: doi
99
value: 10.5281/zenodo.10799219
1010
description: This is the collection of archived snapshots of all versions of thread.
11-
- type: doi
12-
value: 10.5281/zenodo.10808243
13-
description: This is the archived snapshot of version 1.0.1 of thread.
1411
- type: url
15-
value: https://github.com/python-thread/thread/releases/tag/v1.0.1
16-
description: The GitHub release URL of tag v1.0.1.
12+
value: https://github.com/python-thread/thread/releases/tag/v1.1.0
13+
description: The GitHub release URL of tag v1.1.0.
1714
- type: url
18-
value: https://pypi.org/project/thread/1.0.1
19-
description: The PyPI release URL of tag v1.0.1.
15+
value: https://pypi.org/project/thread/1.1.0
16+
description: The PyPI release URL of tag v1.1.0.
2017
cff-version: 1.2.0
2118
date-released: 2024-03-07
2219
keywords:
@@ -35,6 +32,6 @@ repository-code: https://github.com/python-thread/thread
3532
repository-artifact: https://pypi.org/project/thread
3633
title: thread
3734
type: software
38-
version: 1.0.1
35+
version: 1.1.0
3936
url: https://thread.ngjx.org
4037

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Our docs are [here!](https://thread.ngjx.org)
9898
<!-- ROADMAP -->
9999
## Roadmap
100100

101-
- [x] v1.0.0 Release
101+
- [x] v1.1.0 Release
102102
- [ ] Bug fixes
103103
- [ ] New features
104104
- [ ] Testing

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "thread"
3-
version = "1.0.1"
3+
version = "1.1.0"
44
description = "Threading module extension"
55
authors = ["Alex <[email protected]>"]
66
license = "BSD-3-Clause"

src/thread/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
## Thread Library
3-
Documentation at https://thread.ngjx.org/docs/v1.0.0
3+
Documentation at https://thread.ngjx.org/docs/v1.1.0
44
55
66
---
@@ -18,7 +18,7 @@
1818
"""
1919

2020

21-
__version__ = '1.0.1'
21+
__version__ = '1.1.0'
2222

2323

2424
# Export Core

src/thread/_types.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
"""
22
## Types
33
4-
Documentation: https://thread.ngjx.org/docs/v1.0.0
4+
Documentation: https://thread.ngjx.org/docs/v1.1.0
55
"""
66

7-
from typing import Any, Literal, Callable, Union
8-
from typing_extensions import ParamSpec, TypeVar, Concatenate
7+
from typing import Any, Literal, Callable, Union, Sized
8+
from typing_extensions import (
9+
ParamSpec,
10+
TypeVar,
11+
Concatenate,
12+
Protocol,
13+
runtime_checkable,
14+
)
915

1016

1117
# Descriptive Types
@@ -33,5 +39,26 @@
3339

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

36-
_Dataset_T = TypeVar('_Dataset_T')
42+
_Dataset_T = TypeVar('_Dataset_T', covariant=True)
3743
DatasetFunction = Callable[Concatenate[_Dataset_T, _Target_P], _Target_T]
44+
45+
46+
# Protocols
47+
@runtime_checkable
48+
class SupportsLength(Sized, Protocol):
49+
pass
50+
51+
52+
_SupportsGetItem_T = TypeVar('_SupportsGetItem_T')
53+
54+
55+
@runtime_checkable
56+
class SupportsGetItem(Protocol[_SupportsGetItem_T]):
57+
__getitem__: Callable[..., _SupportsGetItem_T]
58+
59+
60+
# Looks like having this inherit __getitem__ from SupportsGetItem breaks isinstance checks in python3.12
61+
# Thus we explicitly define it
62+
@runtime_checkable
63+
class SupportsLengthGetItem(Sized, Protocol[_SupportsGetItem_T]):
64+
__getitem__: Callable[..., _SupportsGetItem_T]

src/thread/decorators/_processor.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,50 @@
11
"""
22
## Processor
33
4-
Documentation: https://thread.ngjx.org/docs/v1.0.0
4+
Documentation: https://thread.ngjx.org/docs/v1.1.0
55
"""
66

77
from functools import wraps
88
from ..thread import ParallelProcessing
99

10-
from .._types import Overflow_In, Data_In
11-
from typing import Callable, Mapping, Sequence, Optional, Union, overload
10+
from .._types import (
11+
Overflow_In,
12+
Data_In,
13+
SupportsGetItem,
14+
SupportsLength,
15+
SupportsLengthGetItem,
16+
)
17+
from typing import Any, Callable, Mapping, Sequence, Optional, Union, overload
1218
from typing_extensions import ParamSpec, TypeVar, Concatenate
1319

1420

1521
_TargetT = TypeVar('_TargetT')
1622
_TargetP = ParamSpec('_TargetP')
1723
_DataT = TypeVar('_DataT')
1824
TargetFunction = Callable[Concatenate[_DataT, _TargetP], _TargetT]
25+
Dataset = Union[
26+
SupportsLengthGetItem[_DataT], SupportsGetItem[_DataT], SupportsLength, Any
27+
]
1928

2029

2130
NoParamReturn = Callable[
22-
Concatenate[Sequence[_DataT], _TargetP],
31+
Concatenate[Dataset[_DataT], _TargetP],
2332
ParallelProcessing[_TargetP, _TargetT, _DataT],
2433
]
2534
WithParamReturn = Callable[
2635
[TargetFunction[_DataT, _TargetP, _TargetT]],
2736
NoParamReturn[_DataT, _TargetP, _TargetT],
2837
]
2938
FullParamReturn = Callable[
30-
Concatenate[Sequence[_DataT], _TargetP],
39+
Concatenate[Dataset[_DataT], _TargetP],
3140
ParallelProcessing[_TargetP, _TargetT, _DataT],
3241
]
3342

3443

3544
@overload
3645
def processor(
3746
__function: TargetFunction[_DataT, _TargetP, _TargetT],
38-
) -> NoParamReturn[_DataT, _TargetP, _TargetT]:
39-
...
47+
) -> NoParamReturn[_DataT, _TargetP, _TargetT]: ...
4048

4149

4250
@overload
@@ -47,8 +55,7 @@ def processor(
4755
ignore_errors: Sequence[type[Exception]] = (),
4856
suppress_errors: bool = False,
4957
**overflow_kwargs: Overflow_In,
50-
) -> WithParamReturn[_DataT, _TargetP, _TargetT]:
51-
...
58+
) -> WithParamReturn[_DataT, _TargetP, _TargetT]: ...
5259

5360

5461
@overload
@@ -60,8 +67,7 @@ def processor(
6067
ignore_errors: Sequence[type[Exception]] = (),
6168
suppress_errors: bool = False,
6269
**overflow_kwargs: Overflow_In,
63-
) -> FullParamReturn[_DataT, _TargetP, _TargetT]:
64-
...
70+
) -> FullParamReturn[_DataT, _TargetP, _TargetT]: ...
6571

6672

6773
def processor(
@@ -106,8 +112,7 @@ def processor(
106112
107113
You can also pass keyword arguments to change the thread behaviour, it otherwise follows the defaults of `thread.Thread`
108114
>>> @thread.threaded(daemon = True)
109-
>>> def myfunction():
110-
... ...
115+
>>> def myfunction(): ...
111116
112117
Args will be ordered infront of function-parsed args parsed into `thread.Thread.args`
113118
>>> @thread.threaded(args = (1))
@@ -142,7 +147,7 @@ def wrapper(
142147

143148
@wraps(__function)
144149
def wrapped(
145-
data: Sequence[_DataT],
150+
data: Dataset[_DataT],
146151
*parsed_args: _TargetP.args,
147152
**parsed_kwargs: _TargetP.kwargs,
148153
) -> ParallelProcessing[_TargetP, _TargetT, _DataT]:

src/thread/decorators/_threaded.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
## Threaded
33
4-
Documentation: https://thread.ngjx.org/docs/v1.0.0
4+
Documentation: https://thread.ngjx.org/docs/v1.1.0
55
"""
66

77
from functools import wraps
@@ -23,8 +23,7 @@
2323

2424

2525
@overload
26-
def threaded(__function: TargetFunction[P, T]) -> NoParamReturn[P, T]:
27-
...
26+
def threaded(__function: TargetFunction[P, T]) -> NoParamReturn[P, T]: ...
2827

2928

3029
@overload
@@ -35,8 +34,7 @@ def threaded(
3534
ignore_errors: Sequence[type[Exception]] = (),
3635
suppress_errors: bool = False,
3736
**overflow_kwargs: Overflow_In,
38-
) -> WithParamReturn[P, T]:
39-
...
37+
) -> WithParamReturn[P, T]: ...
4038

4139

4240
@overload
@@ -48,8 +46,7 @@ def threaded(
4846
ignore_errors: Sequence[type[Exception]] = (),
4947
suppress_errors: bool = False,
5048
**overflow_kwargs: Overflow_In,
51-
) -> FullParamReturn[P, T]:
52-
...
49+
) -> FullParamReturn[P, T]: ...
5350

5451

5552
def threaded(
@@ -90,8 +87,7 @@ def threaded(
9087
9188
You can also pass keyword arguments to change the thread behaviour, it otherwise follows the defaults of `thread.Thread`
9289
>>> @thread.threaded(daemon = True)
93-
>>> def myfunction():
94-
... ...
90+
>>> def myfunction(): ...
9591
9692
Args will be ordered infront of function-parsed args parsed into `thread.Thread.args`
9793
>>> @thread.threaded(args = (1))

src/thread/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
## Thread Exceptions
33
4-
Documentation: https://thread.ngjx.org/docs/v1.0.0
4+
Documentation: https://thread.ngjx.org/docs/v1.1.0
55
"""
66

77
import traceback

0 commit comments

Comments
 (0)