Skip to content

Commit 4fbb856

Browse files
authored
feat(types): add datetime.date and datetime.datetime support for Tag values (ITL-45) (#188)
1 parent a047970 commit 4fbb856

8 files changed

Lines changed: 728 additions & 14 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ dependencies = [
2020
"graphviz>=0.21",
2121
"gitpython>=3.1.45",
2222
"universal-pathlib>=0.3.8",
23-
"starfix~=0.3.0",
23+
"starfix~=0.4.0",
2424
"pygraphviz>=1.14",
2525
"tzdata>=2024.1",
2626
"uuid-utils>=0.11.1",

src/orcapod/semantic_types/universal_converter.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import types
1818
import typing
1919
from collections.abc import Callable, Iterable, Mapping
20-
from datetime import datetime, timezone
20+
from datetime import date, datetime, timezone
2121

2222
# Handle generic types
2323
from typing import TYPE_CHECKING, Any, TypedDict, get_args, get_origin
@@ -89,6 +89,7 @@ def _get_python_to_arrow_map() -> dict:
8989
"date": pa.date32(),
9090
"datetime": pa.timestamp("us", tz="UTC"),
9191
datetime: pa.timestamp("us", tz="UTC"),
92+
date: pa.date32(),
9293
}
9394

9495
# Add numpy types if available
@@ -1201,6 +1202,8 @@ def _convert_arrow_to_python(self, arrow_type: pa.DataType) -> type | Any:
12011202
else:
12021203
return typing.Union[tuple(child_types)]
12031204

1205+
elif pa.types.is_date(arrow_type):
1206+
return date
12041207
elif pa.types.is_timestamp(arrow_type):
12051208
return datetime
12061209

src/orcapod/types.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import uuid
1717
from collections.abc import Collection, Iterator, Mapping
1818
from dataclasses import dataclass
19-
from datetime import datetime
19+
from datetime import date, datetime
2020
from enum import Enum
2121
from types import UnionType
2222
from typing import TYPE_CHECKING, Any, Generic, Self, TypeAlias, TypeVar
@@ -42,20 +42,19 @@
4242
"""Convenience alias for any filesystem-path-like object (``str`` or
4343
``os.PathLike``)."""
4444

45-
# TODO: accomodate other common data types such as datetime
46-
TagValue: TypeAlias = int | str | None | Collection["TagValue"]
47-
"""A tag metadata value: an int, string, ``None``, or an arbitrarily nested
48-
collection thereof. Tags are used to label and organise data and
49-
datagrams."""
45+
TagValue: TypeAlias = int | str | date | datetime | None | Collection["TagValue"]
46+
"""A tag metadata value: an int, string, date, datetime, ``None``, or an
47+
arbitrarily nested collection thereof. Tags are used to label and organise
48+
data and datagrams."""
5049

5150
PathSet: TypeAlias = PathLike | Collection[PathLike | None]
5251
"""A single path or an arbitrarily nested collection of paths (with optional
5352
``None`` entries). Used when operations need to address multiple files at
5453
once, e.g. batch hashing."""
5554

56-
SupportedNativePythonData: TypeAlias = str | int | float | bool | bytes
55+
SupportedNativePythonData: TypeAlias = str | int | float | bool | bytes | date | datetime
5756
"""The simple Python scalar types that have a direct Arrow / Polars
58-
correspondence."""
57+
correspondence, including temporal types (date and datetime)."""
5958

6059
ExtendedSupportedPythonData: TypeAlias = SupportedNativePythonData | PathSet
6160
"""Native scalar types extended with filesystem paths."""

0 commit comments

Comments
 (0)