kumoai 2.13.0.dev202511181731__cp311-cp311-macosx_11_0_arm64.whl → 2.14.0.dev202512191731__cp311-cp311-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 (49) hide show
  1. kumoai/__init__.py +12 -0
  2. kumoai/_version.py +1 -1
  3. kumoai/client/pquery.py +6 -2
  4. kumoai/connector/utils.py +23 -2
  5. kumoai/experimental/rfm/__init__.py +52 -52
  6. kumoai/experimental/rfm/authenticate.py +3 -4
  7. kumoai/experimental/rfm/backend/__init__.py +0 -0
  8. kumoai/experimental/rfm/backend/local/__init__.py +42 -0
  9. kumoai/experimental/rfm/{local_graph_store.py → backend/local/graph_store.py} +57 -110
  10. kumoai/experimental/rfm/backend/local/sampler.py +315 -0
  11. kumoai/experimental/rfm/backend/local/table.py +114 -0
  12. kumoai/experimental/rfm/backend/snow/__init__.py +37 -0
  13. kumoai/experimental/rfm/backend/snow/sampler.py +252 -0
  14. kumoai/experimental/rfm/backend/snow/table.py +169 -0
  15. kumoai/experimental/rfm/backend/sqlite/__init__.py +32 -0
  16. kumoai/experimental/rfm/backend/sqlite/sampler.py +349 -0
  17. kumoai/experimental/rfm/backend/sqlite/table.py +154 -0
  18. kumoai/experimental/rfm/base/__init__.py +33 -0
  19. kumoai/experimental/rfm/base/column.py +68 -0
  20. kumoai/experimental/rfm/base/column_expression.py +50 -0
  21. kumoai/experimental/rfm/base/sampler.py +773 -0
  22. kumoai/experimental/rfm/base/source.py +19 -0
  23. kumoai/experimental/rfm/base/sql_sampler.py +84 -0
  24. kumoai/experimental/rfm/base/sql_table.py +229 -0
  25. kumoai/experimental/rfm/{local_table.py → base/table.py} +219 -189
  26. kumoai/experimental/rfm/{local_graph.py → graph.py} +510 -91
  27. kumoai/experimental/rfm/infer/__init__.py +8 -0
  28. kumoai/experimental/rfm/infer/dtype.py +79 -0
  29. kumoai/experimental/rfm/infer/pkey.py +128 -0
  30. kumoai/experimental/rfm/infer/stype.py +35 -0
  31. kumoai/experimental/rfm/infer/time_col.py +61 -0
  32. kumoai/experimental/rfm/pquery/executor.py +27 -27
  33. kumoai/experimental/rfm/pquery/pandas_executor.py +30 -32
  34. kumoai/experimental/rfm/rfm.py +313 -246
  35. kumoai/experimental/rfm/sagemaker.py +15 -7
  36. kumoai/pquery/predictive_query.py +10 -6
  37. kumoai/testing/decorators.py +1 -1
  38. kumoai/testing/snow.py +50 -0
  39. kumoai/utils/__init__.py +3 -2
  40. kumoai/utils/progress_logger.py +178 -12
  41. kumoai/utils/sql.py +3 -0
  42. {kumoai-2.13.0.dev202511181731.dist-info → kumoai-2.14.0.dev202512191731.dist-info}/METADATA +10 -8
  43. {kumoai-2.13.0.dev202511181731.dist-info → kumoai-2.14.0.dev202512191731.dist-info}/RECORD +46 -26
  44. kumoai/experimental/rfm/local_graph_sampler.py +0 -184
  45. kumoai/experimental/rfm/local_pquery_driver.py +0 -689
  46. kumoai/experimental/rfm/utils.py +0 -344
  47. {kumoai-2.13.0.dev202511181731.dist-info → kumoai-2.14.0.dev202512191731.dist-info}/WHEEL +0 -0
  48. {kumoai-2.13.0.dev202511181731.dist-info → kumoai-2.14.0.dev202512191731.dist-info}/licenses/LICENSE +0 -0
  49. {kumoai-2.13.0.dev202511181731.dist-info → kumoai-2.14.0.dev202512191731.dist-info}/top_level.txt +0 -0
kumoai/__init__.py CHANGED
@@ -280,7 +280,19 @@ __all__ = [
280
280
  ]
281
281
 
282
282
 
283
+ def in_snowflake_notebook() -> bool:
284
+ try:
285
+ from snowflake.snowpark.context import get_active_session
286
+ import streamlit # noqa: F401
287
+ get_active_session()
288
+ return True
289
+ except Exception:
290
+ return False
291
+
292
+
283
293
  def in_notebook() -> bool:
294
+ if in_snowflake_notebook():
295
+ return True
284
296
  try:
285
297
  from IPython import get_ipython
286
298
  shell = get_ipython()
kumoai/_version.py CHANGED
@@ -1 +1 @@
1
- __version__ = '2.13.0.dev202511181731'
1
+ __version__ = '2.14.0.dev202512191731'
kumoai/client/pquery.py CHANGED
@@ -176,8 +176,12 @@ def filter_model_plan(
176
176
  # Undefined
177
177
  pass
178
178
 
179
- new_opt_fields.append((field.name, _type, default))
180
- new_opts.append(getattr(section, field.name))
179
+ # Forward compatibility - Remove any newly introduced arguments not
180
+ # returned yet by the backend:
181
+ value = getattr(section, field.name)
182
+ if value != MissingType.VALUE:
183
+ new_opt_fields.append((field.name, _type, default))
184
+ new_opts.append(value)
181
185
 
182
186
  Section = dataclass(
183
187
  config=dict(validate_assignment=True),
kumoai/connector/utils.py CHANGED
@@ -381,8 +381,29 @@ def _handle_duplicate_names(names: List[str]) -> List[str]:
381
381
 
382
382
 
383
383
  def _sanitize_columns(names: List[str]) -> Tuple[List[str], bool]:
384
- _SAN_RE = re.compile(r"[^0-9A-Za-z]+")
384
+ """Normalize column names in a CSV or Parquet file.
385
+
386
+ Rules:
387
+ - Replace any non-alphanumeric character with "_"
388
+ - Strip leading/trailing underscores
389
+ - Ensure uniqueness by appending suffixes: _1, _2, ...
390
+ - Auto-name empty columns as auto_named_<n>
391
+
392
+ Returns:
393
+ (new_column_names, changed)
394
+ """
395
+ _SAN_RE = re.compile(r"[^0-9A-Za-z,\t]")
396
+ # 1) Replace non-alphanumeric sequences with underscore
385
397
  new = [_SAN_RE.sub("_", n).strip("_") for n in names]
398
+
399
+ # 2) Auto-name any empty column names to match UI behavior
400
+ unnamed_counter = 0
401
+ for i, n in enumerate(new):
402
+ if not n:
403
+ new[i] = f"auto_named_{unnamed_counter}"
404
+ unnamed_counter += 1
405
+
406
+ # 3) Ensure uniqueness (append suffixes where needed)
386
407
  new = _handle_duplicate_names(new)
387
408
  return new, new != names
388
409
 
@@ -1168,7 +1189,7 @@ def _detect_and_validate_csv(head_bytes: bytes) -> str:
1168
1189
  - Re-serializes those rows and validates with pandas (small nrows) to catch
1169
1190
  malformed inputs.
1170
1191
  - Raises ValueError on empty input or if parsing fails with the chosen
1171
- delimiter.
1192
+ delimiter.
1172
1193
  """
1173
1194
  if not head_bytes:
1174
1195
  raise ValueError("Could not auto-detect a delimiter: file is empty.")
@@ -1,54 +1,26 @@
1
- try:
2
- import kumoai.kumolib # noqa: F401
3
- except Exception as e:
4
- import platform
5
-
6
- _msg = f"""RFM is not supported in your environment.
7
-
8
- 💻 Your Environment:
9
- Python version: {platform.python_version()}
10
- Operating system: {platform.system()}
11
- CPU architecture: {platform.machine()}
12
- glibc version: {platform.libc_ver()[1]}
13
-
14
- ✅ Supported Environments:
15
- * Python versions: 3.10, 3.11, 3.12, 3.13
16
- * Operating systems and CPU architectures:
17
- * Linux (x86_64)
18
- * macOS (arm64)
19
- * Windows (x86_64)
20
- * glibc versions: >=2.28
21
-
22
- ❌ Unsupported Environments:
23
- * Python versions: 3.8, 3.9, 3.14
24
- * Operating systems and CPU architectures:
25
- * Linux (arm64)
26
- * macOS (x86_64)
27
- * Windows (arm64)
28
- * glibc versions: <2.28
29
-
30
- Please create a feature request at 'https://github.com/kumo-ai/kumo-rfm'."""
31
-
32
- raise RuntimeError(_msg) from e
33
-
34
- from dataclasses import dataclass
35
- from enum import Enum
36
1
  import ipaddress
37
2
  import logging
3
+ import os
38
4
  import re
39
5
  import socket
40
6
  import threading
41
- from typing import Optional, Dict, Tuple
42
- import os
7
+ from dataclasses import dataclass
8
+ from enum import Enum
43
9
  from urllib.parse import urlparse
10
+
44
11
  import kumoai
45
12
  from kumoai.client.client import KumoClient
46
- from .sagemaker import (KumoClient_SageMakerAdapter,
47
- KumoClient_SageMakerProxy_Local)
48
- from .local_table import LocalTable
49
- from .local_graph import LocalGraph
50
- from .rfm import ExplainConfig, Explanation, KumoRFM
13
+ from kumoai.spcs import _get_active_session
14
+
51
15
  from .authenticate import authenticate
16
+ from .sagemaker import (
17
+ KumoClient_SageMakerAdapter,
18
+ KumoClient_SageMakerProxy_Local,
19
+ )
20
+ from .base import Table
21
+ from .backend.local import LocalTable
22
+ from .graph import Graph
23
+ from .rfm import ExplainConfig, Explanation, KumoRFM
52
24
 
53
25
  logger = logging.getLogger('kumoai_rfm')
54
26
 
@@ -77,7 +49,8 @@ class InferenceBackend(str, Enum):
77
49
 
78
50
 
79
51
  def _detect_backend(
80
- url: str) -> Tuple[InferenceBackend, Optional[str], Optional[str]]:
52
+ url: str, #
53
+ ) -> tuple[InferenceBackend, str | None, str | None]:
81
54
  parsed = urlparse(url)
82
55
 
83
56
  # Remote SageMaker
@@ -101,12 +74,27 @@ def _detect_backend(
101
74
  return InferenceBackend.REST, None, None
102
75
 
103
76
 
77
+ def _get_snowflake_url(snowflake_application: str) -> str:
78
+ snowpark_session = _get_active_session()
79
+ if not snowpark_session:
80
+ raise ValueError(
81
+ "Client creation failed: snowflake_application is specified "
82
+ "without an active snowpark session. If running outside "
83
+ "a snowflake notebook, specify a URL and credentials.")
84
+ with snowpark_session.connection.cursor() as cur:
85
+ cur.execute(
86
+ f"DESCRIBE SERVICE {snowflake_application}.user_schema.rfm_service"
87
+ f" ->> SELECT \"dns_name\" from $1")
88
+ dns_name: str = cur.fetchone()[0]
89
+ return f"http://{dns_name}:8000/api"
90
+
91
+
104
92
  @dataclass
105
93
  class RfmGlobalState:
106
94
  _url: str = '__url_not_provided__'
107
95
  _backend: InferenceBackend = InferenceBackend.UNKNOWN
108
- _region: Optional[str] = None
109
- _endpoint_name: Optional[str] = None
96
+ _region: str | None = None
97
+ _endpoint_name: str | None = None
110
98
  _thread_local = threading.local()
111
99
 
112
100
  # Thread-safe init-once.
@@ -149,10 +137,10 @@ global_state = RfmGlobalState()
149
137
 
150
138
 
151
139
  def init(
152
- url: Optional[str] = None,
153
- api_key: Optional[str] = None,
154
- snowflake_credentials: Optional[Dict[str, str]] = None,
155
- snowflake_application: Optional[str] = None,
140
+ url: str | None = None,
141
+ api_key: str | None = None,
142
+ snowflake_credentials: dict[str, str] | None = None,
143
+ snowflake_application: str | None = None,
156
144
  log_level: str = "INFO",
157
145
  ) -> None:
158
146
  with global_state._lock:
@@ -164,6 +152,15 @@ def init(
164
152
  "supported.")
165
153
  return
166
154
 
155
+ if snowflake_application:
156
+ if url is not None:
157
+ raise ValueError(
158
+ "Client creation failed: both snowflake_application and "
159
+ "url are specified. If running from a snowflake notebook, "
160
+ "specify only snowflake_application.")
161
+ url = _get_snowflake_url(snowflake_application)
162
+ api_key = "test:DISABLED"
163
+
167
164
  if url is None:
168
165
  url = os.getenv("RFM_API_URL", "https://kumorfm.ai/api")
169
166
 
@@ -197,12 +194,15 @@ def init(
197
194
  url)
198
195
 
199
196
 
197
+ LocalGraph = Graph # NOTE Backward compatibility - do not use anymore.
198
+
200
199
  __all__ = [
200
+ 'authenticate',
201
+ 'init',
202
+ 'Table',
201
203
  'LocalTable',
202
- 'LocalGraph',
204
+ 'Graph',
203
205
  'KumoRFM',
204
206
  'ExplainConfig',
205
207
  'Explanation',
206
- 'authenticate',
207
- 'init',
208
208
  ]
@@ -2,12 +2,11 @@ import logging
2
2
  import os
3
3
  import platform
4
4
  from datetime import datetime
5
- from typing import Optional
6
5
 
7
6
  from kumoai import in_notebook
8
7
 
9
8
 
10
- def authenticate(api_url: Optional[str] = None) -> None:
9
+ def authenticate(api_url: str | None = None) -> None:
11
10
  """Authenticates the user and sets the Kumo API key for the SDK.
12
11
 
13
12
  This function detects the current environment and launches the appropriate
@@ -65,11 +64,11 @@ def _authenticate_local(api_url: str, redirect_port: int = 8765) -> None:
65
64
  import webbrowser
66
65
  from getpass import getpass
67
66
  from socketserver import TCPServer
68
- from typing import Any, Dict
67
+ from typing import Any
69
68
 
70
69
  logger = logging.getLogger('kumoai')
71
70
 
72
- token_status: Dict[str, Any] = {
71
+ token_status: dict[str, Any] = {
73
72
  'token': None,
74
73
  'token_name': None,
75
74
  'failed': False
File without changes
@@ -0,0 +1,42 @@
1
+ try:
2
+ import kumoai.kumolib # noqa: F401
3
+ except Exception as e:
4
+ import platform
5
+
6
+ _msg = f"""RFM is not supported in your environment.
7
+
8
+ 💻 Your Environment:
9
+ Python version: {platform.python_version()}
10
+ Operating system: {platform.system()}
11
+ CPU architecture: {platform.machine()}
12
+ glibc version: {platform.libc_ver()[1]}
13
+
14
+ ✅ Supported Environments:
15
+ * Python versions: 3.10, 3.11, 3.12, 3.13
16
+ * Operating systems and CPU architectures:
17
+ * Linux (x86_64)
18
+ * macOS (arm64)
19
+ * Windows (x86_64)
20
+ * glibc versions: >=2.28
21
+
22
+ ❌ Unsupported Environments:
23
+ * Python versions: 3.8, 3.9, 3.14
24
+ * Operating systems and CPU architectures:
25
+ * Linux (arm64)
26
+ * macOS (x86_64)
27
+ * Windows (arm64)
28
+ * glibc versions: <2.28
29
+
30
+ Please create a feature request at 'https://github.com/kumo-ai/kumo-rfm'."""
31
+
32
+ raise RuntimeError(_msg) from e
33
+
34
+ from .table import LocalTable
35
+ from .graph_store import LocalGraphStore
36
+ from .sampler import LocalSampler
37
+
38
+ __all__ = [
39
+ 'LocalTable',
40
+ 'LocalGraphStore',
41
+ 'LocalSampler',
42
+ ]
@@ -1,14 +1,13 @@
1
1
  import warnings
2
- from typing import Dict, List, Optional, Tuple, Union
2
+ from typing import TYPE_CHECKING
3
3
 
4
4
  import numpy as np
5
5
  import pandas as pd
6
6
  from kumoapi.rfm.context import Subgraph
7
7
  from kumoapi.typing import Stype
8
8
 
9
- from kumoai.experimental.rfm import LocalGraph
10
- from kumoai.experimental.rfm.utils import normalize_text
11
- from kumoai.utils import InteractiveProgressLogger, ProgressLogger
9
+ from kumoai.experimental.rfm.backend.local import LocalTable
10
+ from kumoai.utils import ProgressLogger
12
11
 
13
12
  try:
14
13
  import torch
@@ -16,43 +15,40 @@ try:
16
15
  except ImportError:
17
16
  WITH_TORCH = False
18
17
 
18
+ if TYPE_CHECKING:
19
+ from kumoai.experimental.rfm import Graph
20
+
19
21
 
20
22
  class LocalGraphStore:
21
23
  def __init__(
22
24
  self,
23
- graph: LocalGraph,
24
- preprocess: bool = False,
25
- verbose: Union[bool, ProgressLogger] = True,
25
+ graph: 'Graph',
26
+ verbose: bool | ProgressLogger = True,
26
27
  ) -> None:
27
28
 
28
29
  if not isinstance(verbose, ProgressLogger):
29
- verbose = InteractiveProgressLogger(
30
- "Materializing graph",
30
+ verbose = ProgressLogger.default(
31
+ msg="Materializing graph",
31
32
  verbose=verbose,
32
33
  )
33
34
 
34
35
  with verbose as logger:
35
- self.df_dict, self.mask_dict = self.sanitize(graph, preprocess)
36
- self.stype_dict = self.get_stype_dict(graph)
36
+ self.df_dict, self.mask_dict = self.sanitize(graph)
37
37
  logger.log("Sanitized input data")
38
38
 
39
- self.pkey_name_dict, self.pkey_map_dict = self.get_pkey_data(graph)
39
+ self.pkey_map_dict = self.get_pkey_map_dict(graph)
40
40
  num_pkeys = sum(t.has_primary_key() for t in graph.tables.values())
41
41
  if num_pkeys > 1:
42
42
  logger.log(f"Collected primary keys from {num_pkeys} tables")
43
43
  else:
44
44
  logger.log(f"Collected primary key from {num_pkeys} table")
45
45
 
46
- (
47
- self.time_column_dict,
48
- self.end_time_column_dict,
49
- self.time_dict,
50
- self.min_time,
51
- self.max_time,
52
- ) = self.get_time_data(graph)
53
- if self.max_time != pd.Timestamp.min:
46
+ self.time_dict, self.min_max_time_dict = self.get_time_data(graph)
47
+ if len(self.min_max_time_dict) > 0:
48
+ min_time = min(t for t, _ in self.min_max_time_dict.values())
49
+ max_time = max(t for _, t in self.min_max_time_dict.values())
54
50
  logger.log(f"Identified temporal graph from "
55
- f"{self.min_time.date()} to {self.max_time.date()}")
51
+ f"{min_time.date()} to {max_time.date()}")
56
52
  else:
57
53
  logger.log("Identified static graph without timestamps")
58
54
 
@@ -62,14 +58,6 @@ class LocalGraphStore:
62
58
  logger.log(f"Created graph with {num_nodes:,} nodes and "
63
59
  f"{num_edges:,} edges")
64
60
 
65
- @property
66
- def node_types(self) -> List[str]:
67
- return list(self.df_dict.keys())
68
-
69
- @property
70
- def edge_types(self) -> List[Tuple[str, str, str]]:
71
- return list(self.row_dict.keys())
72
-
73
61
  def get_node_id(self, table_name: str, pkey: pd.Series) -> np.ndarray:
74
62
  r"""Returns the node ID given primary keys.
75
63
 
@@ -105,9 +93,8 @@ class LocalGraphStore:
105
93
 
106
94
  def sanitize(
107
95
  self,
108
- graph: LocalGraph,
109
- preprocess: bool = False,
110
- ) -> Tuple[Dict[str, pd.DataFrame], Dict[str, np.ndarray]]:
96
+ graph: 'Graph',
97
+ ) -> tuple[dict[str, pd.DataFrame], dict[str, np.ndarray]]:
111
98
  r"""Sanitizes raw data according to table schema definition:
112
99
 
113
100
  In particular, it:
@@ -115,19 +102,14 @@ class LocalGraphStore:
115
102
  * drops timezone information from timestamps
116
103
  * drops duplicate primary keys
117
104
  * removes rows with missing primary keys or time values
118
-
119
- If ``preprocess`` is set to ``True``, it will additionally pre-process
120
- data for faster model processing. In particular, it:
121
- * tokenizes any text column that is not a foreign key
122
105
  """
123
- df_dict: Dict[str, pd.DataFrame] = {
124
- table_name: table._data.copy(deep=False).reset_index(drop=True)
125
- for table_name, table in graph.tables.items()
126
- }
127
-
128
- foreign_keys = {(edge.src_table, edge.fkey) for edge in graph.edges}
106
+ df_dict: dict[str, pd.DataFrame] = {}
107
+ for table_name, table in graph.tables.items():
108
+ assert isinstance(table, LocalTable)
109
+ df = table._data
110
+ df_dict[table_name] = df.copy(deep=False).reset_index(drop=True)
129
111
 
130
- mask_dict: Dict[str, np.ndarray] = {}
112
+ mask_dict: dict[str, np.ndarray] = {}
131
113
  for table in graph.tables.values():
132
114
  for col in table.columns:
133
115
  if col.stype == Stype.timestamp:
@@ -144,13 +126,7 @@ class LocalGraphStore:
144
126
  ser = ser.dt.tz_localize(None)
145
127
  df_dict[table.name][col.name] = ser
146
128
 
147
- # Normalize text in advance (but exclude foreign keys):
148
- if (preprocess and col.stype == Stype.text
149
- and (table.name, col.name) not in foreign_keys):
150
- ser = df_dict[table.name][col.name]
151
- df_dict[table.name][col.name] = normalize_text(ser)
152
-
153
- mask: Optional[np.ndarray] = None
129
+ mask: np.ndarray | None = None
154
130
  if table._time_column is not None:
155
131
  ser = df_dict[table.name][table._time_column]
156
132
  mask = ser.notna().to_numpy()
@@ -165,34 +141,16 @@ class LocalGraphStore:
165
141
 
166
142
  return df_dict, mask_dict
167
143
 
168
- def get_stype_dict(self, graph: LocalGraph) -> Dict[str, Dict[str, Stype]]:
169
- stype_dict: Dict[str, Dict[str, Stype]] = {}
170
- foreign_keys = {(edge.src_table, edge.fkey) for edge in graph.edges}
171
- for table in graph.tables.values():
172
- stype_dict[table.name] = {}
173
- for column in table.columns:
174
- if column == table.primary_key:
175
- continue
176
- if (table.name, column.name) in foreign_keys:
177
- continue
178
- stype_dict[table.name][column.name] = column.stype
179
- return stype_dict
180
-
181
- def get_pkey_data(
144
+ def get_pkey_map_dict(
182
145
  self,
183
- graph: LocalGraph,
184
- ) -> Tuple[
185
- Dict[str, str],
186
- Dict[str, pd.DataFrame],
187
- ]:
188
- pkey_name_dict: Dict[str, str] = {}
189
- pkey_map_dict: Dict[str, pd.DataFrame] = {}
146
+ graph: 'Graph',
147
+ ) -> dict[str, pd.DataFrame]:
148
+ pkey_map_dict: dict[str, pd.DataFrame] = {}
190
149
 
191
150
  for table in graph.tables.values():
192
151
  if table._primary_key is None:
193
152
  continue
194
153
 
195
- pkey_name_dict[table.name] = table._primary_key
196
154
  pkey = self.df_dict[table.name][table._primary_key]
197
155
  pkey_map = pd.DataFrame(
198
156
  dict(arange=range(len(pkey))),
@@ -214,61 +172,50 @@ class LocalGraphStore:
214
172
 
215
173
  pkey_map_dict[table.name] = pkey_map
216
174
 
217
- return pkey_name_dict, pkey_map_dict
175
+ return pkey_map_dict
218
176
 
219
177
  def get_time_data(
220
178
  self,
221
- graph: LocalGraph,
222
- ) -> Tuple[
223
- Dict[str, str],
224
- Dict[str, str],
225
- Dict[str, np.ndarray],
226
- pd.Timestamp,
227
- pd.Timestamp,
179
+ graph: 'Graph',
180
+ ) -> tuple[
181
+ dict[str, np.ndarray],
182
+ dict[str, tuple[pd.Timestamp, pd.Timestamp]],
228
183
  ]:
229
- time_column_dict: Dict[str, str] = {}
230
- end_time_column_dict: Dict[str, str] = {}
231
- time_dict: Dict[str, np.ndarray] = {}
232
- min_time = pd.Timestamp.max
233
- max_time = pd.Timestamp.min
184
+ time_dict: dict[str, np.ndarray] = {}
185
+ min_max_time_dict: dict[str, tuple[pd.Timestamp, pd.Timestamp]] = {}
234
186
  for table in graph.tables.values():
235
- if table._end_time_column is not None:
236
- end_time_column_dict[table.name] = table._end_time_column
237
-
238
187
  if table._time_column is None:
239
188
  continue
240
189
 
241
190
  time = self.df_dict[table.name][table._time_column]
242
- time_dict[table.name] = time.astype('datetime64[ns]').astype(
243
- int).to_numpy() // 1000**3
244
- time_column_dict[table.name] = table._time_column
191
+ if time.dtype != 'datetime64[ns]':
192
+ time = time.astype('datetime64[ns]')
193
+ time_dict[table.name] = time.astype(int).to_numpy() // 1000**3
245
194
 
246
195
  if table.name in self.mask_dict.keys():
247
196
  time = time[self.mask_dict[table.name]]
248
197
  if len(time) > 0:
249
- min_time = min(min_time, time.min())
250
- max_time = max(max_time, time.max())
198
+ min_max_time_dict[table.name] = (time.min(), time.max())
199
+ else:
200
+ min_max_time_dict[table.name] = (
201
+ pd.Timestamp.max,
202
+ pd.Timestamp.min,
203
+ )
251
204
 
252
- return (
253
- time_column_dict,
254
- end_time_column_dict,
255
- time_dict,
256
- min_time,
257
- max_time,
258
- )
205
+ return time_dict, min_max_time_dict
259
206
 
260
207
  def get_csc(
261
208
  self,
262
- graph: LocalGraph,
263
- ) -> Tuple[
264
- Dict[Tuple[str, str, str], np.ndarray],
265
- Dict[Tuple[str, str, str], np.ndarray],
209
+ graph: 'Graph',
210
+ ) -> tuple[
211
+ dict[tuple[str, str, str], np.ndarray],
212
+ dict[tuple[str, str, str], np.ndarray],
266
213
  ]:
267
214
  # A mapping from raw primary keys to node indices (0 to N-1):
268
- map_dict: Dict[str, pd.CategoricalDtype] = {}
215
+ map_dict: dict[str, pd.CategoricalDtype] = {}
269
216
  # A dictionary to manage offsets of node indices for invalid rows:
270
- offset_dict: Dict[str, np.ndarray] = {}
271
- for table_name in set(edge.dst_table for edge in graph.edges):
217
+ offset_dict: dict[str, np.ndarray] = {}
218
+ for table_name in {edge.dst_table for edge in graph.edges}:
272
219
  ser = self.df_dict[table_name][graph[table_name]._primary_key]
273
220
  if table_name in self.mask_dict.keys():
274
221
  mask = self.mask_dict[table_name]
@@ -277,8 +224,8 @@ class LocalGraphStore:
277
224
  map_dict[table_name] = pd.CategoricalDtype(ser, ordered=True)
278
225
 
279
226
  # Build CSC graph representation:
280
- row_dict: Dict[Tuple[str, str, str], np.ndarray] = {}
281
- colptr_dict: Dict[Tuple[str, str, str], np.ndarray] = {}
227
+ row_dict: dict[tuple[str, str, str], np.ndarray] = {}
228
+ colptr_dict: dict[tuple[str, str, str], np.ndarray] = {}
282
229
  for src_table, fkey, dst_table in graph.edges:
283
230
  src_df = self.df_dict[src_table]
284
231
  dst_df = self.df_dict[dst_table]
@@ -340,7 +287,7 @@ def _argsort(input: np.ndarray) -> np.ndarray:
340
287
  return torch.from_numpy(input).argsort().numpy()
341
288
 
342
289
 
343
- def _lexsort(inputs: List[np.ndarray]) -> np.ndarray:
290
+ def _lexsort(inputs: list[np.ndarray]) -> np.ndarray:
344
291
  assert len(inputs) >= 1
345
292
 
346
293
  if not WITH_TORCH: