Skip to content

Feature: dataframe support #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 40 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
7f7e0ba
fix: self.ident can be None
caffeine-addictt Mar 15, 2024
1d559f3
revert: Remove unused paramspec
caffeine-addictt Mar 15, 2024
e139891
style: Formatting
caffeine-addictt Mar 15, 2024
c6c238c
feat: Make datasetT covariant
caffeine-addictt Mar 15, 2024
1d453e0
feat: Include protocols
caffeine-addictt Mar 15, 2024
7bcba2a
feat: Overloading ParallelProcessing init
caffeine-addictt Mar 15, 2024
c3bb83b
feat: Add dataset typing
caffeine-addictt Mar 15, 2024
1e39cec
feat: Validate and write length
caffeine-addictt Mar 15, 2024
bd51de3
feat: Enforcing arguments
caffeine-addictt Mar 15, 2024
5292f2e
feat: Update signature
caffeine-addictt Mar 15, 2024
142624d
revert: Remove Dataset type
caffeine-addictt Mar 16, 2024
5d4da34
feat: Drop explicit Sequence support
caffeine-addictt Mar 16, 2024
ba1dad3
feat: Impose requirements
caffeine-addictt Mar 16, 2024
9ee7299
refactor: Use the new values
caffeine-addictt Mar 16, 2024
fa3e82c
style: Unused variable
caffeine-addictt Mar 16, 2024
21165c4
test: Setup for testing compatibility support
caffeine-addictt Mar 16, 2024
5f8c5d6
feat: Support non __len__ and non __getitem__
caffeine-addictt Mar 16, 2024
1f44e8b
style: Remove unused import
caffeine-addictt Mar 16, 2024
50b4c85
test: Refactor to use typing.Any
caffeine-addictt Mar 16, 2024
818ec36
test: Add dummy unlike sequences
caffeine-addictt Mar 16, 2024
2ce9922
test: Add tests for datasets with only __len__
caffeine-addictt Mar 16, 2024
1377933
refactor: Update __getitem__ compatibility with all
caffeine-addictt Mar 16, 2024
370d827
refactor: raise useful errors
caffeine-addictt Mar 16, 2024
f076795
test: Add test for 0
caffeine-addictt Mar 16, 2024
16301ff
test: Catch ValueError instead of AssertionError
caffeine-addictt Mar 16, 2024
87a939f
fix: Protocol methods not inherited in python12
caffeine-addictt Mar 16, 2024
8d2ee1d
test: Disable verbosity when testing
caffeine-addictt Mar 16, 2024
f677b53
refactor: Update errors
caffeine-addictt Mar 16, 2024
d5f14bd
test: Add tests for __getitem__ only
caffeine-addictt Mar 16, 2024
ca758d4
fix: Update signature to Any
caffeine-addictt Mar 16, 2024
5ab1f68
test: Add tests for Sequence-Like datasets
caffeine-addictt Mar 16, 2024
cd8c861
fix: Any is not subscriptable
caffeine-addictt Mar 16, 2024
766090d
fix: _length as a function not supported for UnlikeSequences
caffeine-addictt Mar 16, 2024
2974c6b
test: Add tests for unlike sequences
caffeine-addictt Mar 16, 2024
0aa73c4
feat: Update thread.processor to support the new dataset typing
caffeine-addictt Mar 16, 2024
7072c87
test: Resolve unused variable warning
caffeine-addictt Mar 16, 2024
d06e0c6
style: Resolve linting
caffeine-addictt Mar 16, 2024
3d5714b
chore: Remove version-specific DOI
caffeine-addictt Mar 16, 2024
864c1fc
chore: Increment to v1.1.0
caffeine-addictt Mar 16, 2024
23a2b1f
style: Formatting
caffeine-addictt Mar 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading