planframe 0.1.0__py3-none-any.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.
- planframe/__init__.py +4 -0
- planframe/backend/__init__.py +18 -0
- planframe/backend/adapter.py +256 -0
- planframe/backend/errors.py +18 -0
- planframe/expr/__init__.py +99 -0
- planframe/expr/api.py +564 -0
- planframe/frame.py +906 -0
- planframe/frame.pyi +380 -0
- planframe/groupby.py +55 -0
- planframe/groupby.pyi +30 -0
- planframe/plan/__init__.py +25 -0
- planframe/plan/nodes.py +190 -0
- planframe/py.typed +1 -0
- planframe/schema/__init__.py +12 -0
- planframe/schema/ir.py +238 -0
- planframe/schema/materialize.py +30 -0
- planframe/schema/source.py +50 -0
- planframe/typing/__init__.py +1 -0
- planframe/typing/_schema_types.pyi +9 -0
- planframe-0.1.0.dist-info/METADATA +42 -0
- planframe-0.1.0.dist-info/RECORD +23 -0
- planframe-0.1.0.dist-info/WHEEL +4 -0
- planframe-0.1.0.dist-info/licenses/LICENSE +22 -0
planframe/__init__.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from planframe.backend.adapter import BackendAdapter, BaseAdapter
|
|
2
|
+
from planframe.backend.errors import (
|
|
3
|
+
PlanFrameBackendError,
|
|
4
|
+
PlanFrameError,
|
|
5
|
+
PlanFrameExecutionError,
|
|
6
|
+
PlanFrameExpressionError,
|
|
7
|
+
PlanFrameSchemaError,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"BackendAdapter",
|
|
12
|
+
"BaseAdapter",
|
|
13
|
+
"PlanFrameError",
|
|
14
|
+
"PlanFrameBackendError",
|
|
15
|
+
"PlanFrameExecutionError",
|
|
16
|
+
"PlanFrameExpressionError",
|
|
17
|
+
"PlanFrameSchemaError",
|
|
18
|
+
]
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
from typing import Any, Generic, TypeVar
|
|
5
|
+
|
|
6
|
+
BackendFrameT = TypeVar("BackendFrameT")
|
|
7
|
+
BackendExprT = TypeVar("BackendExprT")
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class BaseAdapter(ABC, Generic[BackendFrameT, BackendExprT]):
|
|
11
|
+
"""Backend execution base class.
|
|
12
|
+
|
|
13
|
+
Core PlanFrame code must not import backend libraries. Adapters translate PlanFrame
|
|
14
|
+
operations + expression IR into backend-native operations.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
name: str
|
|
18
|
+
|
|
19
|
+
@abstractmethod
|
|
20
|
+
def select(self, df: BackendFrameT, columns: tuple[str, ...]) -> BackendFrameT: ...
|
|
21
|
+
|
|
22
|
+
@abstractmethod
|
|
23
|
+
def drop(self, df: BackendFrameT, columns: tuple[str, ...]) -> BackendFrameT: ...
|
|
24
|
+
|
|
25
|
+
@abstractmethod
|
|
26
|
+
def rename(self, df: BackendFrameT, mapping: dict[str, str]) -> BackendFrameT: ...
|
|
27
|
+
|
|
28
|
+
@abstractmethod
|
|
29
|
+
def with_column(self, df: BackendFrameT, name: str, expr: BackendExprT) -> BackendFrameT: ...
|
|
30
|
+
|
|
31
|
+
@abstractmethod
|
|
32
|
+
def cast(self, df: BackendFrameT, name: str, dtype: Any) -> BackendFrameT: ...
|
|
33
|
+
|
|
34
|
+
@abstractmethod
|
|
35
|
+
def filter(self, df: BackendFrameT, predicate: BackendExprT) -> BackendFrameT: ...
|
|
36
|
+
|
|
37
|
+
@abstractmethod
|
|
38
|
+
def sort(
|
|
39
|
+
self,
|
|
40
|
+
df: BackendFrameT,
|
|
41
|
+
columns: tuple[str, ...],
|
|
42
|
+
*,
|
|
43
|
+
descending: bool = False,
|
|
44
|
+
nulls_last: bool = False,
|
|
45
|
+
) -> BackendFrameT: ...
|
|
46
|
+
|
|
47
|
+
@abstractmethod
|
|
48
|
+
def unique(
|
|
49
|
+
self,
|
|
50
|
+
df: BackendFrameT,
|
|
51
|
+
subset: tuple[str, ...] | None,
|
|
52
|
+
*,
|
|
53
|
+
keep: str = "first",
|
|
54
|
+
maintain_order: bool = False,
|
|
55
|
+
) -> BackendFrameT: ...
|
|
56
|
+
|
|
57
|
+
@abstractmethod
|
|
58
|
+
def duplicated(
|
|
59
|
+
self,
|
|
60
|
+
df: BackendFrameT,
|
|
61
|
+
subset: tuple[str, ...] | None,
|
|
62
|
+
*,
|
|
63
|
+
keep: str | bool = "first",
|
|
64
|
+
out_name: str = "duplicated",
|
|
65
|
+
) -> BackendFrameT: ...
|
|
66
|
+
|
|
67
|
+
@abstractmethod
|
|
68
|
+
def group_by_agg(
|
|
69
|
+
self,
|
|
70
|
+
df: BackendFrameT,
|
|
71
|
+
*,
|
|
72
|
+
keys: tuple[str, ...],
|
|
73
|
+
named_aggs: dict[str, tuple[str, str]],
|
|
74
|
+
) -> BackendFrameT: ...
|
|
75
|
+
|
|
76
|
+
@abstractmethod
|
|
77
|
+
def drop_nulls(
|
|
78
|
+
self,
|
|
79
|
+
df: BackendFrameT,
|
|
80
|
+
subset: tuple[str, ...] | None,
|
|
81
|
+
) -> BackendFrameT: ...
|
|
82
|
+
|
|
83
|
+
@abstractmethod
|
|
84
|
+
def fill_null(
|
|
85
|
+
self,
|
|
86
|
+
df: BackendFrameT,
|
|
87
|
+
value: Any,
|
|
88
|
+
subset: tuple[str, ...] | None,
|
|
89
|
+
) -> BackendFrameT: ...
|
|
90
|
+
|
|
91
|
+
@abstractmethod
|
|
92
|
+
def melt(
|
|
93
|
+
self,
|
|
94
|
+
df: BackendFrameT,
|
|
95
|
+
*,
|
|
96
|
+
id_vars: tuple[str, ...],
|
|
97
|
+
value_vars: tuple[str, ...],
|
|
98
|
+
variable_name: str,
|
|
99
|
+
value_name: str,
|
|
100
|
+
) -> BackendFrameT: ...
|
|
101
|
+
|
|
102
|
+
@abstractmethod
|
|
103
|
+
def join(
|
|
104
|
+
self,
|
|
105
|
+
left: BackendFrameT,
|
|
106
|
+
right: BackendFrameT,
|
|
107
|
+
*,
|
|
108
|
+
on: tuple[str, ...],
|
|
109
|
+
how: str = "inner",
|
|
110
|
+
suffix: str = "_right",
|
|
111
|
+
) -> BackendFrameT: ...
|
|
112
|
+
|
|
113
|
+
@abstractmethod
|
|
114
|
+
def slice(
|
|
115
|
+
self,
|
|
116
|
+
df: BackendFrameT,
|
|
117
|
+
*,
|
|
118
|
+
offset: int,
|
|
119
|
+
length: int | None,
|
|
120
|
+
) -> BackendFrameT: ...
|
|
121
|
+
|
|
122
|
+
@abstractmethod
|
|
123
|
+
def head(self, df: BackendFrameT, n: int) -> BackendFrameT: ...
|
|
124
|
+
|
|
125
|
+
@abstractmethod
|
|
126
|
+
def tail(self, df: BackendFrameT, n: int) -> BackendFrameT: ...
|
|
127
|
+
|
|
128
|
+
@abstractmethod
|
|
129
|
+
def concat_vertical(self, left: BackendFrameT, right: BackendFrameT) -> BackendFrameT: ...
|
|
130
|
+
|
|
131
|
+
@abstractmethod
|
|
132
|
+
def concat_horizontal(self, left: BackendFrameT, right: BackendFrameT) -> BackendFrameT: ...
|
|
133
|
+
|
|
134
|
+
@abstractmethod
|
|
135
|
+
def pivot(
|
|
136
|
+
self,
|
|
137
|
+
df: BackendFrameT,
|
|
138
|
+
*,
|
|
139
|
+
index: tuple[str, ...],
|
|
140
|
+
on: str,
|
|
141
|
+
values: str,
|
|
142
|
+
agg: str = "first",
|
|
143
|
+
on_columns: tuple[str, ...] | None = None,
|
|
144
|
+
separator: str = "_",
|
|
145
|
+
) -> BackendFrameT: ...
|
|
146
|
+
|
|
147
|
+
@abstractmethod
|
|
148
|
+
def write_parquet(
|
|
149
|
+
self,
|
|
150
|
+
df: BackendFrameT,
|
|
151
|
+
path: str,
|
|
152
|
+
*,
|
|
153
|
+
compression: str = "zstd",
|
|
154
|
+
row_group_size: int | None = None,
|
|
155
|
+
partition_by: tuple[str, ...] | None = None,
|
|
156
|
+
storage_options: dict[str, Any] | None = None,
|
|
157
|
+
) -> None: ...
|
|
158
|
+
|
|
159
|
+
@abstractmethod
|
|
160
|
+
def write_csv(
|
|
161
|
+
self,
|
|
162
|
+
df: BackendFrameT,
|
|
163
|
+
path: str,
|
|
164
|
+
*,
|
|
165
|
+
separator: str = ",",
|
|
166
|
+
include_header: bool = True,
|
|
167
|
+
storage_options: dict[str, Any] | None = None,
|
|
168
|
+
) -> None: ...
|
|
169
|
+
|
|
170
|
+
@abstractmethod
|
|
171
|
+
def write_ndjson(
|
|
172
|
+
self, df: BackendFrameT, path: str, *, storage_options: dict[str, Any] | None = None
|
|
173
|
+
) -> None: ...
|
|
174
|
+
|
|
175
|
+
@abstractmethod
|
|
176
|
+
def write_ipc(
|
|
177
|
+
self,
|
|
178
|
+
df: BackendFrameT,
|
|
179
|
+
path: str,
|
|
180
|
+
*,
|
|
181
|
+
compression: str = "uncompressed",
|
|
182
|
+
storage_options: dict[str, Any] | None = None,
|
|
183
|
+
) -> None: ...
|
|
184
|
+
|
|
185
|
+
@abstractmethod
|
|
186
|
+
def write_database(
|
|
187
|
+
self,
|
|
188
|
+
df: BackendFrameT,
|
|
189
|
+
*,
|
|
190
|
+
table_name: str,
|
|
191
|
+
connection: Any,
|
|
192
|
+
if_table_exists: str = "fail",
|
|
193
|
+
engine: str | None = None,
|
|
194
|
+
) -> None: ...
|
|
195
|
+
|
|
196
|
+
@abstractmethod
|
|
197
|
+
def write_excel(self, df: BackendFrameT, path: str, *, worksheet: str = "Sheet1") -> None: ...
|
|
198
|
+
|
|
199
|
+
@abstractmethod
|
|
200
|
+
def write_delta(
|
|
201
|
+
self,
|
|
202
|
+
df: BackendFrameT,
|
|
203
|
+
target: str,
|
|
204
|
+
*,
|
|
205
|
+
mode: str = "error",
|
|
206
|
+
storage_options: dict[str, Any] | None = None,
|
|
207
|
+
) -> None: ...
|
|
208
|
+
|
|
209
|
+
@abstractmethod
|
|
210
|
+
def write_avro(
|
|
211
|
+
self,
|
|
212
|
+
df: BackendFrameT,
|
|
213
|
+
path: str,
|
|
214
|
+
*,
|
|
215
|
+
compression: str = "uncompressed",
|
|
216
|
+
name: str = "",
|
|
217
|
+
) -> None: ...
|
|
218
|
+
|
|
219
|
+
@abstractmethod
|
|
220
|
+
def explode(self, df: BackendFrameT, column: str) -> BackendFrameT: ...
|
|
221
|
+
|
|
222
|
+
@abstractmethod
|
|
223
|
+
def unnest(self, df: BackendFrameT, column: str) -> BackendFrameT: ...
|
|
224
|
+
|
|
225
|
+
@abstractmethod
|
|
226
|
+
def drop_nulls_all(
|
|
227
|
+
self, df: BackendFrameT, subset: tuple[str, ...] | None
|
|
228
|
+
) -> BackendFrameT: ...
|
|
229
|
+
|
|
230
|
+
@abstractmethod
|
|
231
|
+
def sample(
|
|
232
|
+
self,
|
|
233
|
+
df: BackendFrameT,
|
|
234
|
+
*,
|
|
235
|
+
n: int | None = None,
|
|
236
|
+
frac: float | None = None,
|
|
237
|
+
with_replacement: bool = False,
|
|
238
|
+
shuffle: bool = False,
|
|
239
|
+
seed: int | None = None,
|
|
240
|
+
) -> BackendFrameT: ...
|
|
241
|
+
|
|
242
|
+
@abstractmethod
|
|
243
|
+
def compile_expr(self, expr: Any) -> BackendExprT: ...
|
|
244
|
+
|
|
245
|
+
@abstractmethod
|
|
246
|
+
def collect(self, df: BackendFrameT) -> BackendFrameT: ...
|
|
247
|
+
|
|
248
|
+
@abstractmethod
|
|
249
|
+
def to_dicts(self, df: BackendFrameT) -> list[dict[str, object]]: ...
|
|
250
|
+
|
|
251
|
+
@abstractmethod
|
|
252
|
+
def to_dict(self, df: BackendFrameT) -> dict[str, list[object]]: ...
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
# Backwards-compatible name for older imports.
|
|
256
|
+
BackendAdapter = BaseAdapter
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class PlanFrameError(Exception):
|
|
2
|
+
"""Base exception for PlanFrame."""
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class PlanFrameSchemaError(PlanFrameError):
|
|
6
|
+
"""Raised when schema inference/evolution fails."""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class PlanFrameExpressionError(PlanFrameError):
|
|
10
|
+
"""Raised when expression typing/compilation fails."""
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class PlanFrameBackendError(PlanFrameError):
|
|
14
|
+
"""Raised when a backend adapter fails or is misused."""
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class PlanFrameExecutionError(PlanFrameBackendError):
|
|
18
|
+
"""Raised when backend execution/collection fails."""
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
from planframe.expr.api import (
|
|
2
|
+
Expr,
|
|
3
|
+
add,
|
|
4
|
+
abs_,
|
|
5
|
+
and_,
|
|
6
|
+
between,
|
|
7
|
+
ceil,
|
|
8
|
+
col,
|
|
9
|
+
contains,
|
|
10
|
+
coalesce,
|
|
11
|
+
day,
|
|
12
|
+
eq,
|
|
13
|
+
ends_with,
|
|
14
|
+
floor,
|
|
15
|
+
ge,
|
|
16
|
+
gt,
|
|
17
|
+
if_else,
|
|
18
|
+
infer_dtype,
|
|
19
|
+
is_not_null,
|
|
20
|
+
is_null,
|
|
21
|
+
isin,
|
|
22
|
+
length,
|
|
23
|
+
le,
|
|
24
|
+
lit,
|
|
25
|
+
lt,
|
|
26
|
+
log,
|
|
27
|
+
mul,
|
|
28
|
+
month,
|
|
29
|
+
ne,
|
|
30
|
+
not_,
|
|
31
|
+
or_,
|
|
32
|
+
over,
|
|
33
|
+
pow_,
|
|
34
|
+
replace,
|
|
35
|
+
strip,
|
|
36
|
+
split,
|
|
37
|
+
round_,
|
|
38
|
+
starts_with,
|
|
39
|
+
sub,
|
|
40
|
+
truediv,
|
|
41
|
+
upper,
|
|
42
|
+
lower,
|
|
43
|
+
year,
|
|
44
|
+
exp,
|
|
45
|
+
clip,
|
|
46
|
+
xor,
|
|
47
|
+
sqrt,
|
|
48
|
+
is_finite,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
__all__ = [
|
|
52
|
+
"Expr",
|
|
53
|
+
"add",
|
|
54
|
+
"abs_",
|
|
55
|
+
"and_",
|
|
56
|
+
"between",
|
|
57
|
+
"ceil",
|
|
58
|
+
"col",
|
|
59
|
+
"contains",
|
|
60
|
+
"coalesce",
|
|
61
|
+
"day",
|
|
62
|
+
"eq",
|
|
63
|
+
"ends_with",
|
|
64
|
+
"floor",
|
|
65
|
+
"ge",
|
|
66
|
+
"gt",
|
|
67
|
+
"if_else",
|
|
68
|
+
"infer_dtype",
|
|
69
|
+
"is_not_null",
|
|
70
|
+
"is_null",
|
|
71
|
+
"isin",
|
|
72
|
+
"length",
|
|
73
|
+
"le",
|
|
74
|
+
"lit",
|
|
75
|
+
"lt",
|
|
76
|
+
"log",
|
|
77
|
+
"mul",
|
|
78
|
+
"month",
|
|
79
|
+
"ne",
|
|
80
|
+
"not_",
|
|
81
|
+
"or_",
|
|
82
|
+
"over",
|
|
83
|
+
"pow_",
|
|
84
|
+
"replace",
|
|
85
|
+
"strip",
|
|
86
|
+
"split",
|
|
87
|
+
"round_",
|
|
88
|
+
"starts_with",
|
|
89
|
+
"sub",
|
|
90
|
+
"truediv",
|
|
91
|
+
"upper",
|
|
92
|
+
"lower",
|
|
93
|
+
"year",
|
|
94
|
+
"exp",
|
|
95
|
+
"clip",
|
|
96
|
+
"xor",
|
|
97
|
+
"sqrt",
|
|
98
|
+
"is_finite",
|
|
99
|
+
]
|