Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.10"]
python-version: ["3.11"]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
uses: astral-sh/setup-uv@v4

- name: Set up Python
run: uv python install 3.10
run: uv python install 3.11

- name: Install dependencies
run: uv sync --group dev
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pypi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ "3.10" ]
python-version: [ "3.11" ]

name: Publish to PyPi
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
python-version: ["3.11", "3.12", "3.13", "3.14", "3.15"]

steps:
- uses: actions/checkout@v3
Expand Down
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
default_language_version:
python: python3.10
python: python3.11
repos:
- repo: https://github.com/psf/black
rev: 23.3.0
rev: 26.10.1
hooks:
- id: black
language_version: python3.10
language_version: python3.11
args: [--config=pyproject.toml, --diff, --color ]
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.264'
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.17.0'
hooks:
- id: ruff
- repo: https://github.com/adamchainz/blacken-docs
Expand Down
2 changes: 1 addition & 1 deletion packages/pynumaflow/docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Thank you for your interest in contributing to pynumaflow! This guide will help

### Prerequisites

- Python 3.10 or higher
- Python 3.11 or higher
- [uv](https://docs.astral.sh/uv/) for dependency management
- Git

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ async def submit_task(datum: Datum):
"""Submit a single message to worker pool."""
task_data = (datum.id, datum.keys, datum.value)
fut = loop.run_in_executor(self.executor, _process_single_message_task, task_data)
return await asyncio.wait_for(fut, timeout=30.0)
async with asyncio.timeout(30.0):
return await fut

# Wait for all results
results = await asyncio.gather(
Expand Down
4 changes: 2 additions & 2 deletions packages/pynumaflow/pynumaflow/_constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import os
from enum import Enum
from enum import StrEnum

from pynumaflow import setup_logging

Expand Down Expand Up @@ -73,7 +73,7 @@
_LOGGER.setLevel(logging.DEBUG)


class UDFType(str, Enum):
class UDFType(StrEnum):
"""
Enumerate the type of UDF.
"""
Expand Down
14 changes: 6 additions & 8 deletions packages/pynumaflow/pynumaflow/accumulator/_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
from dataclasses import dataclass, field
from datetime import datetime
from enum import IntEnum
from typing import TypeAlias, TypeVar
from typing import Self, TypeAlias
from collections.abc import AsyncIterable, Callable

from pynumaflow.shared.asynciter import NonBlockingIterator
from pynumaflow._constants import DROP
from pynumaflow._validate import _validate_message_fields

M = TypeVar("M", bound="Message")


class WindowOperation(IntEnum):
"""
Expand All @@ -37,13 +35,13 @@ class Datum:
Example usage
```py
from pynumaflow.accumulator import Datum
from datetime import datetime, timezone
from datetime import UTC, datetime

d = Datum(
keys=["test_key"],
value=b"test_mock_message",
event_time=datetime.fromtimestamp(1662998400, timezone.utc),
watermark=datetime.fromtimestamp(1662998460, timezone.utc),
event_time=datetime.fromtimestamp(1662998400, UTC),
watermark=datetime.fromtimestamp(1662998460, UTC),
headers={"key1": "value1", "key2": "value2"},
)
```
Expand Down Expand Up @@ -418,7 +416,7 @@ def __init__(
self._id = id or ""

@classmethod
def to_drop(cls: type[M], datum: Datum) -> M:
def to_drop(cls, datum: Datum) -> Self:
"""Creates a Message from the given Datum with the DROP tag set, so the message is not
forwarded to the next vertex but still allows the accumulator to advance the watermark
and release the tracked state.
Expand All @@ -431,7 +429,7 @@ def to_drop(cls: type[M], datum: Datum) -> M:
datum: The Datum to drop the results for.

Returns:
M: A Message instance with empty value and the DROP tag set, carrying the datum's
Message: A Message instance with empty value and the DROP tag set, carrying the datum's
watermark, event time, id and headers.
"""
return cls(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
from collections.abc import AsyncIterable
from datetime import datetime, timezone
from datetime import datetime, UTC

from google.protobuf import timestamp_pb2
from pynumaflow._constants import (
Expand Down Expand Up @@ -322,7 +322,7 @@ async def write_to_global_queue(
watermark_pb.FromDatetime(msg.watermark)

start_dt_pb = timestamp_pb2.Timestamp()
start_dt_pb.FromDatetime(datetime.fromtimestamp(0, tz=timezone.utc))
start_dt_pb.FromDatetime(datetime.fromtimestamp(0, tz=UTC))

end_dt_pb = timestamp_pb2.Timestamp()
end_dt_pb.FromDatetime(wm)
Expand Down Expand Up @@ -365,7 +365,7 @@ async def write_to_global_queue(
# stream_send_eof on SIGTERM): synthesize the window from epoch(0) and the
# latest watermark, preserving prior behavior.
start_eof_pb = timestamp_pb2.Timestamp()
start_eof_pb.FromDatetime(datetime.fromtimestamp(0, tz=timezone.utc))
start_eof_pb.FromDatetime(datetime.fromtimestamp(0, tz=UTC))

end_eof_pb = timestamp_pb2.Timestamp()
end_eof_pb.FromDatetime(wm)
Expand Down
8 changes: 4 additions & 4 deletions packages/pynumaflow/pynumaflow/batchmapper/_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from collections.abc import Iterator, Sequence
from dataclasses import dataclass
from datetime import datetime
from typing import TypeAlias, TypeVar
from typing import Self, TypeAlias, TypeVar
from collections.abc import AsyncIterable, Callable

from pynumaflow._constants import DROP, FAIL, NACK
Expand Down Expand Up @@ -42,17 +42,17 @@ def __init__(self, value: bytes, keys: list[str] | None = None, tags: list[str]

# returns the Message Object which will be dropped
@classmethod
def to_drop(cls: type[M]) -> M:
def to_drop(cls) -> Self:
return cls(b"", None, [DROP])

@classmethod
def to_nack(cls: type[M], opts: NackOptions | None = None) -> M:
def to_nack(cls, opts: NackOptions | None = None) -> Self:
m = cls(b"", None, [NACK])
m._nack_options = opts
return m

@classmethod
def to_fail(cls: type[M]) -> M:
def to_fail(cls) -> Self:
return cls(b"", None, [FAIL])

@property
Expand Down
10 changes: 5 additions & 5 deletions packages/pynumaflow/pynumaflow/info/types.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import os
from dataclasses import dataclass, field
from enum import Enum
from enum import StrEnum
from importlib.metadata import version
from typing import TypeVar

Expand Down Expand Up @@ -30,7 +30,7 @@
SI = TypeVar("SI", bound="ServerInfo")


class Protocol(str, Enum):
class Protocol(StrEnum):
"""
Enumerate grpc server connection protocol.
"""
Expand All @@ -39,15 +39,15 @@ class Protocol(str, Enum):
TCP = "tcp"


class Language(str, Enum):
class Language(StrEnum):
"""
Enumerate Numaflow SDK language.
"""

PYTHON = "python"


class MapMode(str, Enum):
class MapMode(StrEnum):
"""
Enumerate Map Mode to be enabled
"""
Expand All @@ -57,7 +57,7 @@ class MapMode(str, Enum):
BatchMap = "batch-map"


class ContainerType(str, Enum):
class ContainerType(StrEnum):
"""
Enumerate Numaflow container type.
"""
Expand Down
14 changes: 7 additions & 7 deletions packages/pynumaflow/pynumaflow/mapper/_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from collections.abc import Iterator, Sequence, Awaitable
from dataclasses import dataclass
from datetime import datetime
from typing import TypeAlias, TypeVar
from typing import Self, TypeAlias, TypeVar
from collections.abc import Callable
from warnings import warn

Expand Down Expand Up @@ -52,17 +52,17 @@ def __init__(

# returns the Message Object which will be dropped
@classmethod
def to_drop(cls: type[M]) -> M:
def to_drop(cls) -> Self:
return cls(b"", None, [DROP])

@classmethod
def to_nack(cls: type[M], opts: NackOptions | None = None) -> M:
def to_nack(cls, opts: NackOptions | None = None) -> Self:
m = cls(b"", None, [NACK])
m._nack_options = opts
return m

@classmethod
def to_fail(cls: type[M]) -> M:
def to_fail(cls) -> Self:
return cls(b"", None, [FAIL])

@property
Expand Down Expand Up @@ -144,13 +144,13 @@ class Datum:
Example usage
```py
from pynumaflow.mapper import Datum
from datetime import datetime, timezone
from datetime import UTC, datetime

d = Datum(
keys=["test_key"],
value=b'test_mock_message'
event_time=datetime.fromtimestamp(1662998400, timezone.utc),
watermark=datetime.fromtimestamp(1662998460, timezone.utc),
event_time=datetime.fromtimestamp(1662998400, UTC),
watermark=datetime.fromtimestamp(1662998460, UTC),
headers={"key1": "value1", "key2": "value2"},
)
```
Expand Down
14 changes: 7 additions & 7 deletions packages/pynumaflow/pynumaflow/mapstreamer/_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from collections.abc import Iterator, Sequence
from dataclasses import dataclass
from datetime import datetime
from typing import TypeAlias, TypeVar
from typing import Self, TypeAlias, TypeVar
from collections.abc import AsyncIterable, Callable
from warnings import warn

Expand Down Expand Up @@ -42,17 +42,17 @@ def __init__(self, value: bytes, keys: list[str] | None = None, tags: list[str]

# returns the Message Object which will be dropped
@classmethod
def to_drop(cls: type[M]) -> M:
def to_drop(cls) -> Self:
return cls(b"", None, [DROP])

@classmethod
def to_nack(cls: type[M], opts: NackOptions | None = None) -> M:
def to_nack(cls, opts: NackOptions | None = None) -> Self:
m = cls(b"", None, [NACK])
m._nack_options = opts
return m

@classmethod
def to_fail(cls: type[M]) -> M:
def to_fail(cls) -> Self:
return cls(b"", None, [FAIL])

@property
Expand Down Expand Up @@ -130,13 +130,13 @@ class Datum:
Example:
```py
from pynumaflow.mapstreamer import Datum
from datetime import datetime, timezone
from datetime import UTC, datetime

d = Datum(
keys=["test_key"],
value=b"test_mock_message",
event_time=datetime.fromtimestamp(1662998400, timezone.utc),
watermark=datetime.fromtimestamp(1662998460, timezone.utc),
event_time=datetime.fromtimestamp(1662998400, UTC),
watermark=datetime.fromtimestamp(1662998460, UTC),
headers={"key1": "value1", "key2": "value2"},
)
```
Expand Down
10 changes: 5 additions & 5 deletions packages/pynumaflow/pynumaflow/reducer/_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from dataclasses import dataclass
from datetime import datetime
from enum import IntEnum
from typing import TypeAlias, TypeVar
from typing import Self, TypeAlias, TypeVar
from collections.abc import AsyncIterable, Callable
from warnings import warn

Expand Down Expand Up @@ -56,7 +56,7 @@ def __init__(self, value: bytes, keys: list[str] | None = None, tags: list[str]

# returns the Message Object which will be dropped
@classmethod
def to_drop(cls: type[M]) -> M:
def to_drop(cls) -> Self:
return cls(b"", None, [DROP])

@property
Expand Down Expand Up @@ -130,13 +130,13 @@ class Datum:
Example usage
```py
from pynumaflow.reducer import Datum
from datetime import datetime, timezone
from datetime import UTC, datetime

d = Datum(
keys=["test_key"],
value=b"test_mock_message",
event_time=datetime.fromtimestamp(1662998400, timezone.utc),
watermark=datetime.fromtimestamp(1662998460, timezone.utc),
event_time=datetime.fromtimestamp(1662998400, UTC),
watermark=datetime.fromtimestamp(1662998460, UTC),
headers={"key1": "value1", "key2": "value2"},
)
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import asyncio
from datetime import datetime, timezone
from datetime import datetime, UTC
from collections.abc import AsyncIterable

from pynumaflow.exceptions import UDFError
Expand Down Expand Up @@ -153,8 +153,8 @@ async def __invoke_reduce(
new_instance = self.__reduce_handler

# Convert the window to a datetime object
start_dt = datetime.fromtimestamp(int(window.start.ToMilliseconds()) / 1e3, timezone.utc)
end_dt = datetime.fromtimestamp(int(window.end.ToMilliseconds()) / 1e3, timezone.utc)
start_dt = datetime.fromtimestamp(int(window.start.ToMilliseconds()) / 1e3, UTC)
end_dt = datetime.fromtimestamp(int(window.end.ToMilliseconds()) / 1e3, UTC)
interval_window = IntervalWindow(start_dt, end_dt)
md = Metadata(interval_window=interval_window)
# If the reduce handler is a class instance, create a new instance of it.
Expand Down
Loading
Loading