chalkpy 2.94.1__py3-none-any.whl → 2.94.3__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.
- chalk/__init__.py +2 -1
- chalk/_gen/chalk/engine/v1/query_planning_server_pb2.py +38 -0
- chalk/_gen/chalk/engine/v1/query_planning_server_pb2.pyi +25 -0
- chalk/_gen/chalk/engine/v1/query_planning_server_pb2_grpc.py +80 -0
- chalk/_gen/chalk/engine/v1/query_planning_server_pb2_grpc.pyi +36 -0
- chalk/_version.py +1 -1
- chalk/features/inference.py +17 -8
- chalk/features/resolver.py +182 -0
- chalk/ml/__init__.py +2 -0
- chalk/utils/tracing.py +12 -1
- {chalkpy-2.94.1.dist-info → chalkpy-2.94.3.dist-info}/METADATA +2 -2
- {chalkpy-2.94.1.dist-info → chalkpy-2.94.3.dist-info}/RECORD +15 -11
- {chalkpy-2.94.1.dist-info → chalkpy-2.94.3.dist-info}/WHEEL +0 -0
- {chalkpy-2.94.1.dist-info → chalkpy-2.94.3.dist-info}/entry_points.txt +0 -0
- {chalkpy-2.94.1.dist-info → chalkpy-2.94.3.dist-info}/top_level.txt +0 -0
chalk/__init__.py
CHANGED
|
@@ -26,7 +26,7 @@ from chalk.features._document import Document
|
|
|
26
26
|
from chalk.features._last import Last
|
|
27
27
|
from chalk.features.filter import freeze_time
|
|
28
28
|
from chalk.features.pseudofeatures import Distance, Now
|
|
29
|
-
from chalk.features.resolver import OfflineResolver, OnlineResolver, Resolver, offline, online
|
|
29
|
+
from chalk.features.resolver import OfflineResolver, OnlineResolver, Resolver, make_model_resolver, offline, online
|
|
30
30
|
from chalk.features.tag import BranchId, EnvironmentId
|
|
31
31
|
from chalk.features.underscore import _, __, underscore
|
|
32
32
|
from chalk.importer import get_resolver
|
|
@@ -98,6 +98,7 @@ __all__ = (
|
|
|
98
98
|
"has_many",
|
|
99
99
|
"has_one",
|
|
100
100
|
"is_primary",
|
|
101
|
+
"make_model_resolver",
|
|
101
102
|
"make_sql_file_resolver",
|
|
102
103
|
"offline",
|
|
103
104
|
"online",
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
3
|
+
# source: chalk/engine/v1/query_planning_server.proto
|
|
4
|
+
# Protobuf Python Version: 4.25.3
|
|
5
|
+
"""Generated protocol buffer code."""
|
|
6
|
+
|
|
7
|
+
from google.protobuf import descriptor as _descriptor
|
|
8
|
+
from google.protobuf import descriptor_pool as _descriptor_pool
|
|
9
|
+
from google.protobuf import symbol_database as _symbol_database
|
|
10
|
+
from google.protobuf.internal import builder as _builder
|
|
11
|
+
# @@protoc_insertion_point(imports)
|
|
12
|
+
|
|
13
|
+
_sym_db = _symbol_database.Default()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
from chalk._gen.chalk.enginestorage.v1 import adhoc_query_pb2 as chalk_dot_enginestorage_dot_v1_dot_adhoc__query__pb2
|
|
17
|
+
from chalk._gen.chalk.planner.v1 import batch_operator_pb2 as chalk_dot_planner_dot_v1_dot_batch__operator__pb2
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(
|
|
21
|
+
b'\n+chalk/engine/v1/query_planning_server.proto\x12\x0f\x63halk.engine.v1\x1a(chalk/enginestorage/v1/adhoc_query.proto\x1a%chalk/planner/v1/batch_operator.proto"x\n\x16\x43reateBatchPlanRequest\x12^\n\x13\x61ll_planning_inputs\x18\x01 \x01(\x0b\x32..chalk.enginestorage.v1.AllPlanningInputsProtoR\x11\x61llPlanningInputs"r\n\x17\x43reateBatchPlanResponse\x12:\n\nbatch_plan\x18\x01 \x01(\x0b\x32\x1b.chalk.planner.v1.BatchPlanR\tbatchPlan\x12\x1b\n\tcache_hit\x18\x02 \x01(\x08R\x08\x63\x61\x63heHit2~\n\x14QueryPlanningService\x12\x66\n\x0f\x43reateBatchPlan\x12\'.chalk.engine.v1.CreateBatchPlanRequest\x1a(.chalk.engine.v1.CreateBatchPlanResponse"\x00\x42\x8d\x01\n\x13\x63om.chalk.engine.v1B\x18QueryPlanningServerProtoP\x01\xa2\x02\x03\x43\x45X\xaa\x02\x0f\x43halk.Engine.V1\xca\x02\x0f\x43halk\\Engine\\V1\xe2\x02\x1b\x43halk\\Engine\\V1\\GPBMetadata\xea\x02\x11\x43halk::Engine::V1b\x06proto3'
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
_globals = globals()
|
|
25
|
+
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
|
|
26
|
+
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, "chalk.engine.v1.query_planning_server_pb2", _globals)
|
|
27
|
+
if _descriptor._USE_C_DESCRIPTORS == False:
|
|
28
|
+
_globals["DESCRIPTOR"]._options = None
|
|
29
|
+
_globals[
|
|
30
|
+
"DESCRIPTOR"
|
|
31
|
+
]._serialized_options = b"\n\023com.chalk.engine.v1B\030QueryPlanningServerProtoP\001\242\002\003CEX\252\002\017Chalk.Engine.V1\312\002\017Chalk\\Engine\\V1\342\002\033Chalk\\Engine\\V1\\GPBMetadata\352\002\021Chalk::Engine::V1"
|
|
32
|
+
_globals["_CREATEBATCHPLANREQUEST"]._serialized_start = 145
|
|
33
|
+
_globals["_CREATEBATCHPLANREQUEST"]._serialized_end = 265
|
|
34
|
+
_globals["_CREATEBATCHPLANRESPONSE"]._serialized_start = 267
|
|
35
|
+
_globals["_CREATEBATCHPLANRESPONSE"]._serialized_end = 381
|
|
36
|
+
_globals["_QUERYPLANNINGSERVICE"]._serialized_start = 383
|
|
37
|
+
_globals["_QUERYPLANNINGSERVICE"]._serialized_end = 509
|
|
38
|
+
# @@protoc_insertion_point(module_scope)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from chalk._gen.chalk.enginestorage.v1 import adhoc_query_pb2 as _adhoc_query_pb2
|
|
2
|
+
from chalk._gen.chalk.planner.v1 import batch_operator_pb2 as _batch_operator_pb2
|
|
3
|
+
from google.protobuf import descriptor as _descriptor
|
|
4
|
+
from google.protobuf import message as _message
|
|
5
|
+
from typing import ClassVar as _ClassVar, Mapping as _Mapping, Optional as _Optional, Union as _Union
|
|
6
|
+
|
|
7
|
+
DESCRIPTOR: _descriptor.FileDescriptor
|
|
8
|
+
|
|
9
|
+
class CreateBatchPlanRequest(_message.Message):
|
|
10
|
+
__slots__ = ("all_planning_inputs",)
|
|
11
|
+
ALL_PLANNING_INPUTS_FIELD_NUMBER: _ClassVar[int]
|
|
12
|
+
all_planning_inputs: _adhoc_query_pb2.AllPlanningInputsProto
|
|
13
|
+
def __init__(
|
|
14
|
+
self, all_planning_inputs: _Optional[_Union[_adhoc_query_pb2.AllPlanningInputsProto, _Mapping]] = ...
|
|
15
|
+
) -> None: ...
|
|
16
|
+
|
|
17
|
+
class CreateBatchPlanResponse(_message.Message):
|
|
18
|
+
__slots__ = ("batch_plan", "cache_hit")
|
|
19
|
+
BATCH_PLAN_FIELD_NUMBER: _ClassVar[int]
|
|
20
|
+
CACHE_HIT_FIELD_NUMBER: _ClassVar[int]
|
|
21
|
+
batch_plan: _batch_operator_pb2.BatchPlan
|
|
22
|
+
cache_hit: bool
|
|
23
|
+
def __init__(
|
|
24
|
+
self, batch_plan: _Optional[_Union[_batch_operator_pb2.BatchPlan, _Mapping]] = ..., cache_hit: bool = ...
|
|
25
|
+
) -> None: ...
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
|
|
2
|
+
"""Client and server classes corresponding to protobuf-defined services."""
|
|
3
|
+
|
|
4
|
+
import grpc
|
|
5
|
+
|
|
6
|
+
from chalk._gen.chalk.engine.v1 import (
|
|
7
|
+
query_planning_server_pb2 as chalk_dot_engine_dot_v1_dot_query__planning__server__pb2,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class QueryPlanningServiceStub(object):
|
|
12
|
+
"""Missing associated documentation comment in .proto file."""
|
|
13
|
+
|
|
14
|
+
def __init__(self, channel):
|
|
15
|
+
"""Constructor.
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
channel: A grpc.Channel.
|
|
19
|
+
"""
|
|
20
|
+
self.CreateBatchPlan = channel.unary_unary(
|
|
21
|
+
"/chalk.engine.v1.QueryPlanningService/CreateBatchPlan",
|
|
22
|
+
request_serializer=chalk_dot_engine_dot_v1_dot_query__planning__server__pb2.CreateBatchPlanRequest.SerializeToString,
|
|
23
|
+
response_deserializer=chalk_dot_engine_dot_v1_dot_query__planning__server__pb2.CreateBatchPlanResponse.FromString,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class QueryPlanningServiceServicer(object):
|
|
28
|
+
"""Missing associated documentation comment in .proto file."""
|
|
29
|
+
|
|
30
|
+
def CreateBatchPlan(self, request, context):
|
|
31
|
+
"""Missing associated documentation comment in .proto file."""
|
|
32
|
+
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
|
|
33
|
+
context.set_details("Method not implemented!")
|
|
34
|
+
raise NotImplementedError("Method not implemented!")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def add_QueryPlanningServiceServicer_to_server(servicer, server):
|
|
38
|
+
rpc_method_handlers = {
|
|
39
|
+
"CreateBatchPlan": grpc.unary_unary_rpc_method_handler(
|
|
40
|
+
servicer.CreateBatchPlan,
|
|
41
|
+
request_deserializer=chalk_dot_engine_dot_v1_dot_query__planning__server__pb2.CreateBatchPlanRequest.FromString,
|
|
42
|
+
response_serializer=chalk_dot_engine_dot_v1_dot_query__planning__server__pb2.CreateBatchPlanResponse.SerializeToString,
|
|
43
|
+
),
|
|
44
|
+
}
|
|
45
|
+
generic_handler = grpc.method_handlers_generic_handler("chalk.engine.v1.QueryPlanningService", rpc_method_handlers)
|
|
46
|
+
server.add_generic_rpc_handlers((generic_handler,))
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# This class is part of an EXPERIMENTAL API.
|
|
50
|
+
class QueryPlanningService(object):
|
|
51
|
+
"""Missing associated documentation comment in .proto file."""
|
|
52
|
+
|
|
53
|
+
@staticmethod
|
|
54
|
+
def CreateBatchPlan(
|
|
55
|
+
request,
|
|
56
|
+
target,
|
|
57
|
+
options=(),
|
|
58
|
+
channel_credentials=None,
|
|
59
|
+
call_credentials=None,
|
|
60
|
+
insecure=False,
|
|
61
|
+
compression=None,
|
|
62
|
+
wait_for_ready=None,
|
|
63
|
+
timeout=None,
|
|
64
|
+
metadata=None,
|
|
65
|
+
):
|
|
66
|
+
return grpc.experimental.unary_unary(
|
|
67
|
+
request,
|
|
68
|
+
target,
|
|
69
|
+
"/chalk.engine.v1.QueryPlanningService/CreateBatchPlan",
|
|
70
|
+
chalk_dot_engine_dot_v1_dot_query__planning__server__pb2.CreateBatchPlanRequest.SerializeToString,
|
|
71
|
+
chalk_dot_engine_dot_v1_dot_query__planning__server__pb2.CreateBatchPlanResponse.FromString,
|
|
72
|
+
options,
|
|
73
|
+
channel_credentials,
|
|
74
|
+
insecure,
|
|
75
|
+
call_credentials,
|
|
76
|
+
compression,
|
|
77
|
+
wait_for_ready,
|
|
78
|
+
timeout,
|
|
79
|
+
metadata,
|
|
80
|
+
)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""
|
|
2
|
+
@generated by mypy-protobuf. Do not edit manually!
|
|
3
|
+
isort:skip_file
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from abc import (
|
|
7
|
+
ABCMeta,
|
|
8
|
+
abstractmethod,
|
|
9
|
+
)
|
|
10
|
+
from chalk._gen.chalk.engine.v1.query_planning_server_pb2 import (
|
|
11
|
+
CreateBatchPlanRequest,
|
|
12
|
+
CreateBatchPlanResponse,
|
|
13
|
+
)
|
|
14
|
+
from grpc import (
|
|
15
|
+
Channel,
|
|
16
|
+
Server,
|
|
17
|
+
ServicerContext,
|
|
18
|
+
UnaryUnaryMultiCallable,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
class QueryPlanningServiceStub:
|
|
22
|
+
def __init__(self, channel: Channel) -> None: ...
|
|
23
|
+
CreateBatchPlan: UnaryUnaryMultiCallable[
|
|
24
|
+
CreateBatchPlanRequest,
|
|
25
|
+
CreateBatchPlanResponse,
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
class QueryPlanningServiceServicer(metaclass=ABCMeta):
|
|
29
|
+
@abstractmethod
|
|
30
|
+
def CreateBatchPlan(
|
|
31
|
+
self,
|
|
32
|
+
request: CreateBatchPlanRequest,
|
|
33
|
+
context: ServicerContext,
|
|
34
|
+
) -> CreateBatchPlanResponse: ...
|
|
35
|
+
|
|
36
|
+
def add_QueryPlanningServiceServicer_to_server(servicer: QueryPlanningServiceServicer, server: Server) -> None: ...
|
chalk/_version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "2.94.
|
|
1
|
+
__version__ = "2.94.3"
|
chalk/features/inference.py
CHANGED
|
@@ -12,7 +12,7 @@ from chalk.utils.collections import ensure_tuple
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
def build_inference_function(
|
|
15
|
-
model_version: ModelVersion, pkey: Feature,
|
|
15
|
+
model_version: ModelVersion, pkey: Feature, output_features: Optional[Feature | list[Feature]] = None
|
|
16
16
|
) -> Callable[[DataFrame], DataFrame]:
|
|
17
17
|
"""Build the core inference function that takes a DataFrame and returns predictions.
|
|
18
18
|
|
|
@@ -24,8 +24,9 @@ def build_inference_function(
|
|
|
24
24
|
The model version to use for prediction
|
|
25
25
|
pkey
|
|
26
26
|
The primary key feature to exclude from predictions
|
|
27
|
-
|
|
28
|
-
Optional output feature to add predictions to the DataFrame
|
|
27
|
+
output_features
|
|
28
|
+
Optional output feature(s) to add predictions to the DataFrame.
|
|
29
|
+
Can be a single Feature or a list of Features for multi-output models.
|
|
29
30
|
|
|
30
31
|
Returns
|
|
31
32
|
-------
|
|
@@ -45,11 +46,19 @@ def build_inference_function(
|
|
|
45
46
|
# Run prediction
|
|
46
47
|
result = model_version.predict(model_input)
|
|
47
48
|
|
|
48
|
-
if
|
|
49
|
-
#
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
if output_features is not None:
|
|
50
|
+
# Normalize to list for uniform processing
|
|
51
|
+
features_list = output_features if isinstance(output_features, list) else [output_features]
|
|
52
|
+
|
|
53
|
+
# Extract output for each feature and build columns dict
|
|
54
|
+
columns_dict = {}
|
|
55
|
+
for output_feature in features_list:
|
|
56
|
+
# Use model-specific output extraction (default: identity, ONNX: extract field)
|
|
57
|
+
output_feature_name = str(output_feature).split(".")[-1]
|
|
58
|
+
result_data = model_version.predictor.extract_output(result, output_feature_name)
|
|
59
|
+
columns_dict[output_feature] = result_data
|
|
60
|
+
|
|
61
|
+
return inp[pkey_string].with_columns(columns_dict)
|
|
53
62
|
|
|
54
63
|
return result
|
|
55
64
|
|
chalk/features/resolver.py
CHANGED
|
@@ -115,6 +115,7 @@ if TYPE_CHECKING:
|
|
|
115
115
|
|
|
116
116
|
from chalk.features import Underscore
|
|
117
117
|
from chalk.features.underscore import UnderscoreAttr, UnderscoreCall, UnderscoreCast, UnderscoreFunction
|
|
118
|
+
from chalk.ml.model_version import ModelVersion
|
|
118
119
|
from chalk.sql import BaseSQLSourceProtocol, SQLSourceGroup
|
|
119
120
|
from chalk.sql._internal.sql_settings import SQLResolverSettings
|
|
120
121
|
from chalk.sql._internal.sql_source import BaseSQLSource
|
|
@@ -4478,3 +4479,184 @@ def validate_message_attributes(
|
|
|
4478
4479
|
message_type = message_type.__args__[0] # pyright: ignore[reportAttributeAccessIssue]
|
|
4479
4480
|
for expression in expressions:
|
|
4480
4481
|
validate_underscore_expression(expression, message_type, error_builder, name)
|
|
4482
|
+
|
|
4483
|
+
|
|
4484
|
+
def make_model_resolver(
|
|
4485
|
+
name: str,
|
|
4486
|
+
model: "ModelVersion",
|
|
4487
|
+
inputs: Dict[Feature, str] | List[Feature],
|
|
4488
|
+
output: Feature | List[Feature] | Dict[Feature, str],
|
|
4489
|
+
feature_class: Optional[type[Features]] = None,
|
|
4490
|
+
resource_group: Optional[str] = None,
|
|
4491
|
+
resource_hint: Optional[ResourceHint] = None,
|
|
4492
|
+
) -> OnlineResolver:
|
|
4493
|
+
"""
|
|
4494
|
+
Create an online resolver that runs inference on a model.
|
|
4495
|
+
|
|
4496
|
+
This function provides an imperative API for creating model inference resolvers,
|
|
4497
|
+
as an alternative to using F.inference in feature definitions. It uses the same
|
|
4498
|
+
underlying implementation as F.inference but allows you to create resolvers
|
|
4499
|
+
programmatically.
|
|
4500
|
+
|
|
4501
|
+
Parameters
|
|
4502
|
+
----------
|
|
4503
|
+
name
|
|
4504
|
+
The name of the resolver
|
|
4505
|
+
model
|
|
4506
|
+
A ModelVersion reference to a deployed model
|
|
4507
|
+
inputs
|
|
4508
|
+
Either a dict mapping Feature objects to model input names (strings), or a list of
|
|
4509
|
+
Feature objects. If a dict, the values represent the model's expected input names
|
|
4510
|
+
(for future use). If a list, the features will be passed as a single DataFrame to
|
|
4511
|
+
the model.
|
|
4512
|
+
output
|
|
4513
|
+
The output feature(s) that will contain the predictions.
|
|
4514
|
+
Can be a single Feature, a list of Features, or a dict mapping Feature objects to
|
|
4515
|
+
model output names (strings) for future use with multi-output models.
|
|
4516
|
+
feature_class
|
|
4517
|
+
Optional feature class to use. If not provided, will be inferred from the inputs.
|
|
4518
|
+
resource_group
|
|
4519
|
+
Optional resource group for the resolver
|
|
4520
|
+
resource_hint
|
|
4521
|
+
Optional resource hint for execution (e.g., CPU/GPU preferences)
|
|
4522
|
+
|
|
4523
|
+
Returns
|
|
4524
|
+
-------
|
|
4525
|
+
OnlineResolver
|
|
4526
|
+
The created resolver
|
|
4527
|
+
|
|
4528
|
+
Examples
|
|
4529
|
+
--------
|
|
4530
|
+
>>> from chalk.features import features, feature
|
|
4531
|
+
>>> from chalk.features.resolver import make_model_resolver
|
|
4532
|
+
>>> from chalk.ml import ModelVersion
|
|
4533
|
+
>>>
|
|
4534
|
+
>>> @features
|
|
4535
|
+
... class User:
|
|
4536
|
+
... id: str = feature(primary=True)
|
|
4537
|
+
... age: float
|
|
4538
|
+
... income: float
|
|
4539
|
+
... risk_score: float
|
|
4540
|
+
... credit_score: float
|
|
4541
|
+
>>>
|
|
4542
|
+
>>> # Create a model version reference
|
|
4543
|
+
>>> model = ModelVersion(
|
|
4544
|
+
... name="risk_model",
|
|
4545
|
+
... version=1,
|
|
4546
|
+
... model_type="sklearn",
|
|
4547
|
+
... model_encoding="pickle",
|
|
4548
|
+
... filename="model.pkl"
|
|
4549
|
+
... )
|
|
4550
|
+
>>>
|
|
4551
|
+
>>> # Create resolver with single output
|
|
4552
|
+
>>> resolver = make_model_resolver(
|
|
4553
|
+
... name="risk_model",
|
|
4554
|
+
... model=model,
|
|
4555
|
+
... inputs=[User.age, User.income],
|
|
4556
|
+
... output=User.risk_score,
|
|
4557
|
+
... )
|
|
4558
|
+
>>>
|
|
4559
|
+
>>> # Create resolver with multiple outputs (list)
|
|
4560
|
+
>>> resolver = make_model_resolver(
|
|
4561
|
+
... name="multi_output_model",
|
|
4562
|
+
... model=model,
|
|
4563
|
+
... inputs=[User.age, User.income],
|
|
4564
|
+
... output=[User.risk_score, User.credit_score],
|
|
4565
|
+
... )
|
|
4566
|
+
>>>
|
|
4567
|
+
>>> # Create resolver with named inputs and outputs (dict)
|
|
4568
|
+
>>> resolver = make_model_resolver(
|
|
4569
|
+
... name="named_model",
|
|
4570
|
+
... model=model,
|
|
4571
|
+
... inputs={User.age: "age_input", User.income: "income_input"},
|
|
4572
|
+
... output={User.risk_score: "risk_output", User.credit_score: "credit_output"},
|
|
4573
|
+
... )
|
|
4574
|
+
"""
|
|
4575
|
+
from chalk.features.inference import build_inference_function
|
|
4576
|
+
|
|
4577
|
+
if isinstance(inputs, dict):
|
|
4578
|
+
input_features_raw = list(inputs.keys())
|
|
4579
|
+
else:
|
|
4580
|
+
input_features_raw = inputs
|
|
4581
|
+
|
|
4582
|
+
input_features = [unwrap_feature(f) for f in input_features_raw]
|
|
4583
|
+
|
|
4584
|
+
if isinstance(output, dict):
|
|
4585
|
+
output_features = [unwrap_feature(f) for f in output.keys()]
|
|
4586
|
+
elif isinstance(output, list):
|
|
4587
|
+
output_features = [unwrap_feature(f) for f in output]
|
|
4588
|
+
else:
|
|
4589
|
+
output_features = [unwrap_feature(output)]
|
|
4590
|
+
|
|
4591
|
+
# If feature_class is not provided, try to infer it from the first input feature
|
|
4592
|
+
if feature_class is None:
|
|
4593
|
+
if not input_features:
|
|
4594
|
+
raise ValueError("Cannot infer feature class: no input features provided and feature_class not specified")
|
|
4595
|
+
|
|
4596
|
+
first_input = input_features[0]
|
|
4597
|
+
|
|
4598
|
+
if hasattr(first_input, "features_cls") and first_input.features_cls is not None:
|
|
4599
|
+
feature_class = first_input.features_cls
|
|
4600
|
+
else:
|
|
4601
|
+
raise ValueError(
|
|
4602
|
+
"Cannot infer feature class from inputs. Please provide feature_class parameter explicitly."
|
|
4603
|
+
)
|
|
4604
|
+
|
|
4605
|
+
pkey = feature_class.__chalk_primary__
|
|
4606
|
+
if pkey is None:
|
|
4607
|
+
raise ValueError(f"Feature class {feature_class} does not have a primary key defined")
|
|
4608
|
+
|
|
4609
|
+
first_output = output_features[0]
|
|
4610
|
+
|
|
4611
|
+
output_namespace = (
|
|
4612
|
+
first_output.namespace
|
|
4613
|
+
if hasattr(first_output, "namespace") and first_output.namespace
|
|
4614
|
+
else feature_class.__name__.lower()
|
|
4615
|
+
)
|
|
4616
|
+
|
|
4617
|
+
# Use the same underlying inference function as F.inference
|
|
4618
|
+
# Pass list of outputs if multiple, single if only one
|
|
4619
|
+
output_for_inference = output_features if len(output_features) > 1 else output_features[0]
|
|
4620
|
+
inference_fn = build_inference_function(model, pkey, output_for_inference)
|
|
4621
|
+
|
|
4622
|
+
if len(output_features) == 1:
|
|
4623
|
+
output_names = output_features[0].name
|
|
4624
|
+
else:
|
|
4625
|
+
output_names = "_".join(f.name for f in output_features)
|
|
4626
|
+
|
|
4627
|
+
resolver = OnlineResolver(
|
|
4628
|
+
function_definition="",
|
|
4629
|
+
filename="",
|
|
4630
|
+
fqn=f"{name}__{output_namespace}_{output_names}",
|
|
4631
|
+
doc=None,
|
|
4632
|
+
inputs=[DataFrame[[pkey, *ensure_tuple(input_features)]]],
|
|
4633
|
+
state=None,
|
|
4634
|
+
output=Features[DataFrame[tuple([*output_features, pkey])]], # type: ignore[misc]
|
|
4635
|
+
fn=inference_fn,
|
|
4636
|
+
environment=None,
|
|
4637
|
+
machine_type=None,
|
|
4638
|
+
default_args=[None],
|
|
4639
|
+
timeout=None,
|
|
4640
|
+
cron=None,
|
|
4641
|
+
when=None,
|
|
4642
|
+
tags=None,
|
|
4643
|
+
owner=None,
|
|
4644
|
+
resource_hint=resource_hint or model.resource_hint,
|
|
4645
|
+
data_sources=None,
|
|
4646
|
+
is_sql_file_resolver=False,
|
|
4647
|
+
source_line=None,
|
|
4648
|
+
lsp_builder=get_resolver_error_builder(inference_fn),
|
|
4649
|
+
parse=None,
|
|
4650
|
+
static=False,
|
|
4651
|
+
total=False,
|
|
4652
|
+
autogenerated=False,
|
|
4653
|
+
unique_on=None,
|
|
4654
|
+
partitioned_by=None,
|
|
4655
|
+
data_lineage=None,
|
|
4656
|
+
sql_settings=None,
|
|
4657
|
+
)
|
|
4658
|
+
|
|
4659
|
+
# Register the resolver
|
|
4660
|
+
RESOLVER_REGISTRY.add_to_registry(resolver, override=False)
|
|
4661
|
+
|
|
4662
|
+
return resolver
|
chalk/ml/__init__.py
CHANGED
|
@@ -2,6 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from chalk.ml.model_file_transfer import FileInfo, HFSourceConfig, LocalSourceConfig, S3SourceConfig, SourceConfig
|
|
4
4
|
from chalk.ml.model_reference import ModelReference
|
|
5
|
+
from chalk.ml.model_version import ModelVersion
|
|
5
6
|
from chalk.ml.utils import ModelClass, ModelEncoding, ModelRunCriterion, ModelType
|
|
6
7
|
|
|
7
8
|
__all__ = (
|
|
@@ -9,6 +10,7 @@ __all__ = (
|
|
|
9
10
|
"ModelClass",
|
|
10
11
|
"ModelEncoding",
|
|
11
12
|
"ModelReference",
|
|
13
|
+
"ModelVersion",
|
|
12
14
|
"SourceConfig",
|
|
13
15
|
"LocalSourceConfig",
|
|
14
16
|
"S3SourceConfig",
|
chalk/utils/tracing.py
CHANGED
|
@@ -10,16 +10,21 @@ from typing import TYPE_CHECKING, Any, Mapping, Union, cast
|
|
|
10
10
|
from chalk.utils._ddtrace_version import can_use_datadog_statsd, can_use_ddtrace
|
|
11
11
|
from chalk.utils._otel_version import can_use_otel_trace
|
|
12
12
|
from chalk.utils.environment_parsing import env_var_bool
|
|
13
|
+
from chalk.utils.log_with_context import get_logger
|
|
13
14
|
|
|
14
15
|
if TYPE_CHECKING:
|
|
15
16
|
import ddtrace.context
|
|
16
17
|
from opentelemetry import trace as otel_trace
|
|
17
18
|
|
|
19
|
+
_logger = get_logger(__name__)
|
|
20
|
+
|
|
18
21
|
if can_use_otel_trace:
|
|
19
22
|
from opentelemetry import context as otel_context
|
|
20
23
|
from opentelemetry import trace as otel_trace
|
|
21
24
|
from opentelemetry.propagate import inject as otel_inject
|
|
22
25
|
|
|
26
|
+
_logger.debug("OTEL trace packages installed, otel tracing is available")
|
|
27
|
+
|
|
23
28
|
@contextlib.contextmanager
|
|
24
29
|
def safe_trace(span_id: str, attributes: Mapping[str, str] | None = None): # pyright: ignore[reportRedeclaration]
|
|
25
30
|
if attributes is None:
|
|
@@ -73,10 +78,12 @@ if can_use_otel_trace:
|
|
|
73
78
|
otel_inject(headers, context=ctx)
|
|
74
79
|
return headers
|
|
75
80
|
|
|
76
|
-
elif can_use_ddtrace
|
|
81
|
+
elif can_use_ddtrace:
|
|
77
82
|
import ddtrace
|
|
78
83
|
from ddtrace.propagation.http import HTTPPropagator
|
|
79
84
|
|
|
85
|
+
_logger.debug("ddtrace installed and available, using it to trace")
|
|
86
|
+
|
|
80
87
|
@contextlib.contextmanager
|
|
81
88
|
def safe_trace(span_id: str, attributes: Mapping[str, str] | None = None): # pyright: ignore[reportRedeclaration]
|
|
82
89
|
if not ddtrace.tracer.enabled:
|
|
@@ -134,6 +141,7 @@ elif can_use_ddtrace and can_use_datadog_statsd:
|
|
|
134
141
|
return headers
|
|
135
142
|
|
|
136
143
|
else:
|
|
144
|
+
_logger.debug("no trace packages found, tracing will not work")
|
|
137
145
|
|
|
138
146
|
@contextlib.contextmanager
|
|
139
147
|
def safe_trace(span_id: str, attributes: Mapping[str, str] | None = None): # pyright: ignore[reportRedeclaration]
|
|
@@ -283,3 +291,6 @@ def configure_tracing(default_service_name: str):
|
|
|
283
291
|
)
|
|
284
292
|
else:
|
|
285
293
|
_logger.warning("neither opentelemetry nor ddtrace are installed")
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
configure_tracing("chalkpy")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: chalkpy
|
|
3
|
-
Version: 2.94.
|
|
3
|
+
Version: 2.94.3
|
|
4
4
|
Summary: Python SDK for Chalk
|
|
5
5
|
Author: Chalk AI, Inc.
|
|
6
6
|
Project-URL: Homepage, https://chalk.ai
|
|
@@ -24,7 +24,7 @@ Requires-Dist: cattrs<25,>=22.1.0
|
|
|
24
24
|
Requires-Dist: dataclasses_json>=0.5.7
|
|
25
25
|
Requires-Dist: executing<3,>=1.2.0
|
|
26
26
|
Requires-Dist: googleapis-common-protos>=1.56.0
|
|
27
|
-
Requires-Dist: grpcio<2,>=1.
|
|
27
|
+
Requires-Dist: grpcio<2,>=1.63.0
|
|
28
28
|
Requires-Dist: ipywidgets>=8.0.6
|
|
29
29
|
Requires-Dist: isodate<0.8,>=0.6.1
|
|
30
30
|
Requires-Dist: numpy<3
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
chalk/__init__.py,sha256=
|
|
2
|
-
chalk/_version.py,sha256=
|
|
1
|
+
chalk/__init__.py,sha256=vKsx9-cl5kImlVWGHVRYO6bweBm79NAzGs3l36u71wM,2657
|
|
2
|
+
chalk/_version.py,sha256=Mgp0492ynB8-nfxBKfxss0lfGoDYzM17OzvkWNaZWPs,23
|
|
3
3
|
chalk/cli.py,sha256=ckqqfOI-A2mT23-rnZzDMmblYj-2x1VBX8ebHlIEn9A,5873
|
|
4
4
|
chalk/importer.py,sha256=m4lMn1lSYj_euDq8CS7LYTBnek9JOcjGJf9-82dJHbA,64441
|
|
5
5
|
chalk/prompts.py,sha256=2H9UomLAamdfRTNUdKs9i3VTpiossuyRhntqsAXUhhg,16117
|
|
@@ -176,6 +176,10 @@ chalk/_gen/chalk/engine/v1/plan_server_pb2.py,sha256=jXu4uFmfJ3-3CUuWI7UHvG4GxeF
|
|
|
176
176
|
chalk/_gen/chalk/engine/v1/plan_server_pb2.pyi,sha256=n1w6-1bwHDFCQA5_VEM6AV9XqMAHOrezxud1wq8RIgs,1658
|
|
177
177
|
chalk/_gen/chalk/engine/v1/plan_server_pb2_grpc.py,sha256=ivCzw4ixyHPWvY5MU4je2Sn7Md0YAPDclAJVifzbsfk,4532
|
|
178
178
|
chalk/_gen/chalk/engine/v1/plan_server_pb2_grpc.pyi,sha256=ekfys8Ph7XYcUQmMGkNGwI6TuptoVSbFI7SMqLY0X9U,1239
|
|
179
|
+
chalk/_gen/chalk/engine/v1/query_planning_server_pb2.py,sha256=XFx5-kotDfyZOZPstpAV3J-ATvZ8rLV6Gg_7X6cUBSI,2687
|
|
180
|
+
chalk/_gen/chalk/engine/v1/query_planning_server_pb2.pyi,sha256=C38EfqzWTUQfoFtRuUi-FKN9CTYIIGgqlInqjalSf70,1161
|
|
181
|
+
chalk/_gen/chalk/engine/v1/query_planning_server_pb2_grpc.py,sha256=DhO0XfRDYgoWwI2d2lecpAoS8ymQJi9Sxc3CDU9FlmU,2994
|
|
182
|
+
chalk/_gen/chalk/engine/v1/query_planning_server_pb2_grpc.pyi,sha256=8ChkgxVfT2LBcba-a1FlZoB3AbgzYW2e_E72R3COdiU,901
|
|
179
183
|
chalk/_gen/chalk/engine/v1/query_server_pb2.py,sha256=P9N752YGIto5UscE_5wWicBmrXOGzx826JSpDlGfwfU,5053
|
|
180
184
|
chalk/_gen/chalk/engine/v1/query_server_pb2.pyi,sha256=JvDayBaIkLly8D9v4blmCdlW0qGxwvQEnT6N9aJHU2Q,862
|
|
181
185
|
chalk/_gen/chalk/engine/v1/query_server_pb2_grpc.py,sha256=umiBlZgTZqCWM0IgAX8jsZRmI1vjyhtXwdbL6nLe8Rc,16536
|
|
@@ -627,12 +631,12 @@ chalk/features/feature_time.py,sha256=iUk8NDelig81jP7QT3tguyzx5eOZ-YC84OVgJRRKVw
|
|
|
627
631
|
chalk/features/feature_wrapper.py,sha256=OolNWGGX67IAEMHCObFvOCpH5EmwjbMvMygRSBJJtu0,19259
|
|
628
632
|
chalk/features/filter.py,sha256=2ldMbqvXC-nJ0jc-OZ36qHtrej-Jkx4TNQ1W_NZodAs,11177
|
|
629
633
|
chalk/features/hooks.py,sha256=KPJnudnhosEH7UptQT8W8sumIYPcZVMVjaJJJhPsOyk,5489
|
|
630
|
-
chalk/features/inference.py,sha256=
|
|
634
|
+
chalk/features/inference.py,sha256=D1mieSj9AvVZ47tsf_gaipw_y4QnBVD6XU1AJedwTo0,5377
|
|
631
635
|
chalk/features/live_updates.py,sha256=8ZbiDjcLqfFruSL15_aycwzSqJ0TbKNhas06KfZLyLU,3644
|
|
632
636
|
chalk/features/namespace_context.py,sha256=fL-nPohqtNiyPDS1uQTAaHLns4aivuBL2Flf50DajU4,1813
|
|
633
637
|
chalk/features/primary.py,sha256=BZ8mrMmKfRNy_wnKGDJt2cdnejP_CZb6xBsD9Ljgajc,5209
|
|
634
638
|
chalk/features/pseudofeatures.py,sha256=50Pe_Xi8ttYWtgNNRpgkhBxP8xoCZCYwyLb0aWUQ-PI,2147
|
|
635
|
-
chalk/features/resolver.py,sha256=
|
|
639
|
+
chalk/features/resolver.py,sha256=B_iIP3wm-nfYCkW1ZuxFMH2rWZogwaYshrLSZqLR0oQ,188553
|
|
636
640
|
chalk/features/tag.py,sha256=LRmKRA8ANCOvmaIAk-L5j1QW2U0aah2SeASy8Uydkmk,2675
|
|
637
641
|
chalk/features/underscore.py,sha256=4xnfQV3bfvVn0PNEtkT4J-k7hW4ebtH9KBe4_BvGjY4,26763
|
|
638
642
|
chalk/features/underscore_features.py,sha256=PlVCoaDDffOgtiSMaxPSWCoj8IjscbkOzDLA471HsJ4,13005
|
|
@@ -674,7 +678,7 @@ chalk/integrations/catalogs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMp
|
|
|
674
678
|
chalk/integrations/catalogs/base_catalog.py,sha256=CwfZZWRvLHJtbIdeRWtBvuXjbtKjUuOWaGxTfvVMlgU,237
|
|
675
679
|
chalk/integrations/catalogs/glue_catalog.py,sha256=V0FzB_sy8espMAijnQpmTs-VSmmTLbTd_Ijn08RKrn4,5635
|
|
676
680
|
chalk/logging/__init__.py,sha256=CpWJAO83W8kOwihQSqPEBTOCCJBJ7jo2JsHPr-JDjPc,746
|
|
677
|
-
chalk/ml/__init__.py,sha256=
|
|
681
|
+
chalk/ml/__init__.py,sha256=B7QkTqFBhNlHTTvLK5xa8sWA_UcF386S3V91TfQXMU4,577
|
|
678
682
|
chalk/ml/chalk_train.py,sha256=B-Kr1_vKgaeUk8kIk7-8YYCDoWjYzQvgbAQHkkb8JCI,2335
|
|
679
683
|
chalk/ml/model_file_transfer.py,sha256=tpD3tg1PI20bNSLwyE63wzFU4qeG4rLFt1sL0JRkzMs,9587
|
|
680
684
|
chalk/ml/model_hooks.py,sha256=vAd8iqW5zarEl2nLAdhoPYuJxxThx2_UuZ4orK9b9kI,14927
|
|
@@ -795,12 +799,12 @@ chalk/utils/storage_client.py,sha256=cK5KH8DVAt4Okk3X4jNMCkMiZgfUJE9Sq3zn4HkaBQo
|
|
|
795
799
|
chalk/utils/string.py,sha256=mHciu1FR1NdXiE0GjiCOOs_Q3JBVpaNnjUQPorE5cJg,4268
|
|
796
800
|
chalk/utils/stubgen.py,sha256=-mKIWFeiZojtfPwaTd9o3h4m4RvTmMTk6i-bI9JpU6c,21580
|
|
797
801
|
chalk/utils/threading.py,sha256=dacvfFCpDs9GDWdRrE2mmM3Ex5DKOIaj5rCYDTqGshk,5305
|
|
798
|
-
chalk/utils/tracing.py,sha256=
|
|
802
|
+
chalk/utils/tracing.py,sha256=ye5z6UCEsrxXC3ofXUNCDdUCf8ydPahEO92qQTd0AIA,11383
|
|
799
803
|
chalk/utils/weak_set_by_identity.py,sha256=VmikA_laYwFeOphCwXJIuyOIkrdlQe0bSzaXq7onoQw,953
|
|
800
804
|
chalk/utils/pydanticutil/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
801
805
|
chalk/utils/pydanticutil/pydantic_compat.py,sha256=O575lLYJ5GvZC4HMzR9yATxf9XwjC6NrDUXbNwZidlE,3031
|
|
802
|
-
chalkpy-2.94.
|
|
803
|
-
chalkpy-2.94.
|
|
804
|
-
chalkpy-2.94.
|
|
805
|
-
chalkpy-2.94.
|
|
806
|
-
chalkpy-2.94.
|
|
806
|
+
chalkpy-2.94.3.dist-info/METADATA,sha256=DE-oJNmVDm-sqj6YqRF-pLy9UdcbW-U46KO2EHzUYa0,27494
|
|
807
|
+
chalkpy-2.94.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
808
|
+
chalkpy-2.94.3.dist-info/entry_points.txt,sha256=Vg23sd8icwq-morJrljVFr-kQnMbm95rZfZj5wsZGis,42
|
|
809
|
+
chalkpy-2.94.3.dist-info/top_level.txt,sha256=1Q6_19IGYfNxSw50W8tYKEJ2t5HKQ3W9Wiw4ia5yg2c,6
|
|
810
|
+
chalkpy-2.94.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|