kumoai 2.13.0.dev202512031731__cp312-cp312-macosx_11_0_arm64.whl → 2.14.0.dev202512301731__cp312-cp312-macosx_11_0_arm64.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.
Files changed (50) hide show
  1. kumoai/__init__.py +35 -26
  2. kumoai/_version.py +1 -1
  3. kumoai/client/client.py +6 -0
  4. kumoai/client/jobs.py +24 -0
  5. kumoai/client/pquery.py +6 -2
  6. kumoai/experimental/rfm/__init__.py +49 -24
  7. kumoai/experimental/rfm/authenticate.py +3 -4
  8. kumoai/experimental/rfm/backend/local/__init__.py +4 -0
  9. kumoai/experimental/rfm/{local_graph_store.py → backend/local/graph_store.py} +62 -110
  10. kumoai/experimental/rfm/backend/local/sampler.py +312 -0
  11. kumoai/experimental/rfm/backend/local/table.py +32 -14
  12. kumoai/experimental/rfm/backend/snow/__init__.py +2 -0
  13. kumoai/experimental/rfm/backend/snow/sampler.py +297 -0
  14. kumoai/experimental/rfm/backend/snow/table.py +186 -39
  15. kumoai/experimental/rfm/backend/sqlite/__init__.py +4 -2
  16. kumoai/experimental/rfm/backend/sqlite/sampler.py +398 -0
  17. kumoai/experimental/rfm/backend/sqlite/table.py +131 -41
  18. kumoai/experimental/rfm/base/__init__.py +23 -3
  19. kumoai/experimental/rfm/base/column.py +96 -10
  20. kumoai/experimental/rfm/base/expression.py +44 -0
  21. kumoai/experimental/rfm/base/sampler.py +761 -0
  22. kumoai/experimental/rfm/base/source.py +2 -1
  23. kumoai/experimental/rfm/base/sql_sampler.py +143 -0
  24. kumoai/experimental/rfm/base/table.py +380 -185
  25. kumoai/experimental/rfm/graph.py +404 -144
  26. kumoai/experimental/rfm/infer/__init__.py +6 -4
  27. kumoai/experimental/rfm/infer/dtype.py +52 -60
  28. kumoai/experimental/rfm/infer/multicategorical.py +1 -1
  29. kumoai/experimental/rfm/infer/pkey.py +4 -2
  30. kumoai/experimental/rfm/infer/stype.py +35 -0
  31. kumoai/experimental/rfm/infer/time_col.py +1 -2
  32. kumoai/experimental/rfm/pquery/executor.py +27 -27
  33. kumoai/experimental/rfm/pquery/pandas_executor.py +30 -32
  34. kumoai/experimental/rfm/relbench.py +76 -0
  35. kumoai/experimental/rfm/rfm.py +283 -230
  36. kumoai/experimental/rfm/sagemaker.py +4 -4
  37. kumoai/pquery/predictive_query.py +10 -6
  38. kumoai/testing/snow.py +50 -0
  39. kumoai/trainer/distilled_trainer.py +175 -0
  40. kumoai/utils/__init__.py +3 -2
  41. kumoai/utils/display.py +51 -0
  42. kumoai/utils/progress_logger.py +178 -12
  43. kumoai/utils/sql.py +3 -0
  44. {kumoai-2.13.0.dev202512031731.dist-info → kumoai-2.14.0.dev202512301731.dist-info}/METADATA +4 -2
  45. {kumoai-2.13.0.dev202512031731.dist-info → kumoai-2.14.0.dev202512301731.dist-info}/RECORD +48 -38
  46. kumoai/experimental/rfm/local_graph_sampler.py +0 -223
  47. kumoai/experimental/rfm/local_pquery_driver.py +0 -689
  48. {kumoai-2.13.0.dev202512031731.dist-info → kumoai-2.14.0.dev202512301731.dist-info}/WHEEL +0 -0
  49. {kumoai-2.13.0.dev202512031731.dist-info → kumoai-2.14.0.dev202512301731.dist-info}/licenses/LICENSE +0 -0
  50. {kumoai-2.13.0.dev202512031731.dist-info → kumoai-2.14.0.dev202512301731.dist-info}/top_level.txt +0 -0
@@ -1,37 +1,119 @@
1
+ from __future__ import annotations
2
+
1
3
  from dataclasses import dataclass
2
- from typing import Any
4
+ from typing import Any, Mapping, TypeAlias
3
5
 
4
6
  from kumoapi.typing import Dtype, Stype
7
+ from typing_extensions import Self
8
+
9
+ from kumoai.experimental.rfm.base import Expression
10
+ from kumoai.mixin import CastMixin
11
+
12
+
13
+ @dataclass(init=False)
14
+ class ColumnSpec(CastMixin):
15
+ r"""A column specification for adding a column to a table.
16
+
17
+ A column specification can either refer to a physical column present in
18
+ the data source, or be defined logically via an expression.
19
+
20
+ Args:
21
+ name: The name of the column.
22
+ expr: A column expression to define logical columns.
23
+ dtype: The data type of the column.
24
+ """
25
+ def __init__(
26
+ self,
27
+ name: str,
28
+ expr: Expression | Mapping[str, str] | str | None = None,
29
+ dtype: Dtype | str | None = None,
30
+ stype: Stype | str | None = None,
31
+ ) -> None:
32
+
33
+ self.name = name
34
+ self.expr = Expression.coerce(expr)
35
+ self.dtype = Dtype(dtype) if dtype is not None else None
36
+ self.stype = Stype(dtype) if stype is not None else None
37
+
38
+ @classmethod
39
+ def coerce(cls, spec: ColumnSpec | Mapping[str, Any] | str) -> Self:
40
+ r"""Coerces a column specification into a :class:`ColumnSpec`."""
41
+ if isinstance(spec, cls):
42
+ return spec
43
+ if isinstance(spec, str):
44
+ return cls(name=spec)
45
+ if isinstance(spec, Mapping):
46
+ try:
47
+ return cls(**spec)
48
+ except TypeError:
49
+ pass
50
+ raise TypeError(f"Unable to coerce 'ColumnSpec' from '{spec}'")
51
+
52
+ @property
53
+ def is_source(self) -> bool:
54
+ r"""Whether the column specification refers to a phyiscal column
55
+ present in the data source.
56
+ """
57
+ return self.expr is None
58
+
59
+
60
+ ColumnSpecType: TypeAlias = ColumnSpec | Mapping[str, Any] | str
5
61
 
6
62
 
7
63
  @dataclass(init=False, repr=False, eq=False)
8
64
  class Column:
65
+ r"""Column-level metadata information.
66
+
67
+ A column can either refer to a physical column present in the data source,
68
+ or be defined logically via an expression.
69
+
70
+ Args:
71
+ name: The name of the column.
72
+ expr: A column expression to define logical columns.
73
+ dtype: The data type of the column.
74
+ stype: The semantic type of the column.
75
+ """
9
76
  stype: Stype
10
77
 
11
78
  def __init__(
12
79
  self,
13
80
  name: str,
81
+ expr: Expression | None,
14
82
  dtype: Dtype,
15
83
  stype: Stype,
16
- is_primary_key: bool = False,
17
- is_time_column: bool = False,
18
- is_end_time_column: bool = False,
19
84
  ) -> None:
20
85
  self._name = name
86
+ self._expr = expr
21
87
  self._dtype = Dtype(dtype)
22
- self._is_primary_key = is_primary_key
23
- self._is_time_column = is_time_column
24
- self._is_end_time_column = is_end_time_column
88
+
89
+ self._is_primary_key = False
90
+ self._is_time_column = False
91
+ self._is_end_time_column = False
92
+
25
93
  self.stype = Stype(stype)
26
94
 
27
95
  @property
28
96
  def name(self) -> str:
97
+ r"""The name of the column."""
29
98
  return self._name
30
99
 
100
+ @property
101
+ def expr(self) -> Expression | None:
102
+ r"""The expression of column (if logically)."""
103
+ return self._expr
104
+
31
105
  @property
32
106
  def dtype(self) -> Dtype:
107
+ r"""The data type of the column."""
33
108
  return self._dtype
34
109
 
110
+ @property
111
+ def is_source(self) -> bool:
112
+ r"""Whether the column refers to a phyiscal column present in the data
113
+ source.
114
+ """
115
+ return self.expr is None
116
+
35
117
  def __setattr__(self, key: str, val: Any) -> None:
36
118
  if key == 'stype':
37
119
  if isinstance(val, str):
@@ -54,7 +136,7 @@ class Column:
54
136
  super().__setattr__(key, val)
55
137
 
56
138
  def __hash__(self) -> int:
57
- return hash((self.name, self.stype, self.dtype))
139
+ return hash((self.name, self.expr, self.dtype, self.stype))
58
140
 
59
141
  def __eq__(self, other: Any) -> bool:
60
142
  if not isinstance(other, Column):
@@ -62,5 +144,9 @@ class Column:
62
144
  return hash(self) == hash(other)
63
145
 
64
146
  def __repr__(self) -> str:
65
- return (f'{self.__class__.__name__}(name={self.name}, '
66
- f'stype={self.stype}, dtype={self.dtype})')
147
+ parts = [f'name={self.name}']
148
+ if self.expr is not None:
149
+ parts.append(f'expr={self.expr}')
150
+ parts.append(f'dtype={self.dtype}')
151
+ parts.append(f'stype={self.stype}')
152
+ return f"{self.__class__.__name__}({', '.join(parts)})"
@@ -0,0 +1,44 @@
1
+ from __future__ import annotations
2
+
3
+ from abc import ABC
4
+ from dataclasses import dataclass
5
+ from typing import Mapping
6
+
7
+
8
+ class Expression(ABC):
9
+ """A base expression to define logical columns."""
10
+ @classmethod
11
+ def coerce(
12
+ cls,
13
+ spec: Expression | Mapping[str, str] | str | None,
14
+ ) -> Expression | None:
15
+ r"""Coerces an expression specification into an :class:`Expression`, if
16
+ possible.
17
+ """
18
+ if spec is None:
19
+ return None
20
+ if isinstance(spec, Expression):
21
+ return spec
22
+ if isinstance(spec, str):
23
+ return LocalExpression(spec)
24
+ if isinstance(spec, Mapping):
25
+ for sub_cls in (LocalExpression, ):
26
+ try:
27
+ return sub_cls(**spec)
28
+ except TypeError:
29
+ pass
30
+ raise TypeError(f"Unable to coerce 'Expression' from '{spec}'")
31
+
32
+
33
+ @dataclass(frozen=True, repr=False)
34
+ class LocalExpression(Expression):
35
+ r"""A local expression to define a row-level logical attribute based on
36
+ physical columns of the data source in the same row.
37
+
38
+ Args:
39
+ value: The value of the expression.
40
+ """
41
+ value: str
42
+
43
+ def __repr__(self) -> str:
44
+ return self.value