calc-flow-python 4.0.0__cp313-abi3-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
calc_flow/store.py ADDED
@@ -0,0 +1,138 @@
1
+ from __future__ import annotations
2
+
3
+ import asyncio
4
+ import json
5
+ import os
6
+ from collections.abc import Awaitable, Callable, Mapping
7
+ from typing import Any
8
+
9
+ from calc_flow import _native
10
+ from calc_flow.config import ProjectDocument, _validate_json_value
11
+
12
+
13
+ def _run_blocking[T](factory: Callable[[], Awaitable[T]], async_method: str) -> T:
14
+ try:
15
+ asyncio.get_running_loop()
16
+ except RuntimeError:
17
+
18
+ async def invoke() -> T:
19
+ return await factory()
20
+
21
+ return asyncio.run(invoke())
22
+ message = (
23
+ "blocking store operation cannot run inside an event loop; "
24
+ f"await {async_method}()"
25
+ )
26
+ raise RuntimeError(message)
27
+
28
+
29
+ def _copy_json_value(value: object, *, root_mapping: bool, label: str) -> Any:
30
+ if root_mapping and type(value) is not dict:
31
+ raise TypeError(f"{label} must be a JSON-compatible dict")
32
+ _validate_json_value(value)
33
+ try:
34
+ encoded = json.dumps(
35
+ value, allow_nan=False, separators=(",", ":"), sort_keys=True
36
+ )
37
+ except (TypeError, ValueError, RecursionError) as error:
38
+ raise ValueError(f"{label} must contain strict JSON-compatible data") from error
39
+ return json.loads(encoded)
40
+
41
+
42
+ def _project_document(
43
+ project: ProjectDocument | Mapping[str, object],
44
+ ) -> ProjectDocument:
45
+ if isinstance(project, ProjectDocument):
46
+ return ProjectDocument.model_validate(project.root)
47
+ if type(project) is not dict:
48
+ raise TypeError("project must be a ProjectDocument or strict dict")
49
+ return ProjectDocument.model_validate(project)
50
+
51
+
52
+ def _document_bytes(document: str | bytes) -> bytes:
53
+ if type(document) is str:
54
+ return document.encode("utf-8")
55
+ if type(document) is bytes:
56
+ return document
57
+ raise TypeError("project document must be bytes or str")
58
+
59
+
60
+ def import_project_json(document: str | bytes) -> ProjectDocument:
61
+ imported = _native.import_project_json(_document_bytes(document))
62
+ return ProjectDocument.model_validate_json(imported)
63
+
64
+
65
+ def import_project_yaml(document: str | bytes) -> ProjectDocument:
66
+ imported = _native.import_project_yaml(_document_bytes(document))
67
+ return ProjectDocument.model_validate_json(imported)
68
+
69
+
70
+ def export_project_json(
71
+ project: ProjectDocument | Mapping[str, object],
72
+ ) -> str:
73
+ document = _project_document(project)
74
+ return _native.export_project_json(document.canonical_json())
75
+
76
+
77
+ def export_project_yaml(
78
+ project: ProjectDocument | Mapping[str, object],
79
+ ) -> str:
80
+ document = _project_document(project)
81
+ return _native.export_project_yaml(document.canonical_json())
82
+
83
+
84
+ class FileProjectStore:
85
+ __slots__ = ("_inner",)
86
+
87
+ def __init__(self, directory: os.PathLike[str] | str) -> None:
88
+ self._inner = _native._FileProjectStore(os.fspath(directory))
89
+
90
+ def create(
91
+ self, project: ProjectDocument | Mapping[str, object]
92
+ ) -> Awaitable[None]:
93
+ document = _project_document(project)
94
+ encoded = document.canonical_json()
95
+
96
+ async def create() -> None:
97
+ await self._inner.create(encoded)
98
+
99
+ return create()
100
+
101
+ def put(self, project: ProjectDocument | Mapping[str, object]) -> Awaitable[None]:
102
+ document = _project_document(project)
103
+ encoded = document.canonical_json()
104
+
105
+ async def put() -> None:
106
+ await self._inner.put(encoded)
107
+
108
+ return put()
109
+
110
+ async def get(self, project_id: str) -> ProjectDocument:
111
+ if not isinstance(project_id, str):
112
+ raise TypeError("project_id must be a string")
113
+ document = await self._inner.get(project_id)
114
+ return ProjectDocument.model_validate_json(document)
115
+
116
+ async def list(self) -> list[ProjectDocument]:
117
+ documents = await self._inner.list()
118
+ return [ProjectDocument.model_validate_json(document) for document in documents]
119
+
120
+ async def delete(self, project_id: str) -> None:
121
+ if not isinstance(project_id, str):
122
+ raise TypeError("project_id must be a string")
123
+ await self._inner.delete(project_id)
124
+
125
+ def create_blocking(self, project: ProjectDocument | Mapping[str, object]) -> None:
126
+ return _run_blocking(lambda: self.create(project), "create")
127
+
128
+ def put_blocking(self, project: ProjectDocument | Mapping[str, object]) -> None:
129
+ return _run_blocking(lambda: self.put(project), "put")
130
+
131
+ def get_blocking(self, project_id: str) -> ProjectDocument:
132
+ return _run_blocking(lambda: self.get(project_id), "get")
133
+
134
+ def list_blocking(self) -> list[ProjectDocument]:
135
+ return _run_blocking(self.list, "list")
136
+
137
+ def delete_blocking(self, project_id: str) -> None:
138
+ return _run_blocking(lambda: self.delete(project_id), "delete")
@@ -0,0 +1,65 @@
1
+ """The public symbolic declaration surface of ``calc_flow``.
2
+
3
+ ``calc_flow.symbolic`` is the only public declaration module. It builds
4
+ immutable expression IR with canonical v1 digests, programs with canonical v1
5
+ fingerprints, and static analysis over the declaration graph. There is no data
6
+ execution path: no ``eval``, ``push``, ``value``, ``transform``, preview
7
+ evaluator, or formula parser exists. Semantics are frozen by
8
+ ``.codex/artifacts/specs/symbolic-computation-contract.md`` and the exact
9
+ signatures by ``.codex/artifacts/api-notes/symbolic-computation-engine.md``.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ from calc_flow.symbolic.analyzer import AnalysisIssue, AnalysisResult
15
+ from calc_flow.symbolic.expr import (
16
+ ArrayExpr,
17
+ ColumnExpr,
18
+ Expr,
19
+ Parameter,
20
+ TableExpr,
21
+ parameter,
22
+ table_input,
23
+ )
24
+ from calc_flow.symbolic.ops import cs, linalg, row, table, ts, window
25
+ from calc_flow.symbolic.program import FeatureSet, Program
26
+ from calc_flow.symbolic.types import Field
27
+ from calc_flow.symbolic.windows import (
28
+ CrossSectionGroup,
29
+ DurationFrame,
30
+ EventTimeBucket,
31
+ RowFrame,
32
+ duration,
33
+ event_time_bucket,
34
+ exact_time,
35
+ rows,
36
+ )
37
+
38
+ __all__ = [
39
+ "AnalysisIssue",
40
+ "AnalysisResult",
41
+ "ArrayExpr",
42
+ "ColumnExpr",
43
+ "CrossSectionGroup",
44
+ "DurationFrame",
45
+ "EventTimeBucket",
46
+ "Expr",
47
+ "FeatureSet",
48
+ "Field",
49
+ "Parameter",
50
+ "Program",
51
+ "RowFrame",
52
+ "TableExpr",
53
+ "cs",
54
+ "duration",
55
+ "event_time_bucket",
56
+ "exact_time",
57
+ "linalg",
58
+ "parameter",
59
+ "row",
60
+ "rows",
61
+ "table",
62
+ "table_input",
63
+ "ts",
64
+ "window",
65
+ ]
@@ -0,0 +1,23 @@
1
+ # @generated by scripts/generate_rolling_kernel_manifest.py; do not edit.
2
+
3
+ from __future__ import annotations
4
+
5
+ from types import MappingProxyType
6
+
7
+ ROLLING_KERNEL_CAPABILITIES = MappingProxyType(
8
+ {
9
+ "lag": (None, "general", False),
10
+ "delta": (None, "general", False),
11
+ "count": ("numeric", "amortized_constant", False),
12
+ "sum": ("numeric", "amortized_constant", False),
13
+ "mean": ("numeric", "amortized_constant", True),
14
+ "variance": ("numeric", "amortized_constant", False),
15
+ "stddev": ("numeric", "amortized_constant", False),
16
+ "min": ("extrema", "amortized_constant", False),
17
+ "max": ("extrema", "amortized_constant", False),
18
+ "covariance": ("pair", "amortized_constant", False),
19
+ "correlation": ("pair", "amortized_constant", False),
20
+ "ewma": ("ewma", "amortized_constant", False),
21
+ "difference": ("fused_difference", "amortized_constant", False),
22
+ }
23
+ )