arthur-common 1.0.1__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.

Potentially problematic release.


This version of arthur-common might be problematic. Click here for more details.

Files changed (40) hide show
  1. arthur_common/__init__.py +0 -0
  2. arthur_common/__version__.py +1 -0
  3. arthur_common/aggregations/__init__.py +2 -0
  4. arthur_common/aggregations/aggregator.py +214 -0
  5. arthur_common/aggregations/functions/README.md +26 -0
  6. arthur_common/aggregations/functions/__init__.py +25 -0
  7. arthur_common/aggregations/functions/categorical_count.py +89 -0
  8. arthur_common/aggregations/functions/confusion_matrix.py +412 -0
  9. arthur_common/aggregations/functions/inference_count.py +69 -0
  10. arthur_common/aggregations/functions/inference_count_by_class.py +206 -0
  11. arthur_common/aggregations/functions/inference_null_count.py +82 -0
  12. arthur_common/aggregations/functions/mean_absolute_error.py +110 -0
  13. arthur_common/aggregations/functions/mean_squared_error.py +110 -0
  14. arthur_common/aggregations/functions/multiclass_confusion_matrix.py +205 -0
  15. arthur_common/aggregations/functions/multiclass_inference_count_by_class.py +90 -0
  16. arthur_common/aggregations/functions/numeric_stats.py +90 -0
  17. arthur_common/aggregations/functions/numeric_sum.py +87 -0
  18. arthur_common/aggregations/functions/py.typed +0 -0
  19. arthur_common/aggregations/functions/shield_aggregations.py +752 -0
  20. arthur_common/aggregations/py.typed +0 -0
  21. arthur_common/models/__init__.py +0 -0
  22. arthur_common/models/connectors.py +41 -0
  23. arthur_common/models/datasets.py +22 -0
  24. arthur_common/models/metrics.py +227 -0
  25. arthur_common/models/py.typed +0 -0
  26. arthur_common/models/schema_definitions.py +420 -0
  27. arthur_common/models/shield.py +504 -0
  28. arthur_common/models/task_job_specs.py +78 -0
  29. arthur_common/py.typed +0 -0
  30. arthur_common/tools/__init__.py +0 -0
  31. arthur_common/tools/aggregation_analyzer.py +243 -0
  32. arthur_common/tools/aggregation_loader.py +59 -0
  33. arthur_common/tools/duckdb_data_loader.py +329 -0
  34. arthur_common/tools/functions.py +46 -0
  35. arthur_common/tools/py.typed +0 -0
  36. arthur_common/tools/schema_inferer.py +104 -0
  37. arthur_common/tools/time_utils.py +33 -0
  38. arthur_common-1.0.1.dist-info/METADATA +74 -0
  39. arthur_common-1.0.1.dist-info/RECORD +40 -0
  40. arthur_common-1.0.1.dist-info/WHEEL +4 -0
@@ -0,0 +1,87 @@
1
+ from typing import Annotated
2
+ from uuid import UUID
3
+
4
+ from arthur_common.aggregations.aggregator import NumericAggregationFunction
5
+ from arthur_common.models.metrics import DatasetReference, Dimension, NumericMetric
6
+ from arthur_common.models.schema_definitions import (
7
+ DType,
8
+ MetricColumnParameterAnnotation,
9
+ MetricDatasetParameterAnnotation,
10
+ ScalarType,
11
+ ScopeSchemaTag,
12
+ )
13
+ from arthur_common.tools.duckdb_data_loader import escape_identifier
14
+ from duckdb import DuckDBPyConnection
15
+
16
+
17
+ class NumericSumAggregationFunction(NumericAggregationFunction):
18
+ METRIC_NAME = "numeric_sum"
19
+
20
+ @staticmethod
21
+ def id() -> UUID:
22
+ return UUID("00000000-0000-0000-0000-00000000000f")
23
+
24
+ @staticmethod
25
+ def display_name() -> str:
26
+ return "Numeric Sum"
27
+
28
+ @staticmethod
29
+ def description() -> str:
30
+ return "Metric that reports the sum of the numeric column per time window."
31
+
32
+ def aggregate(
33
+ self,
34
+ ddb_conn: DuckDBPyConnection,
35
+ dataset: Annotated[
36
+ DatasetReference,
37
+ MetricDatasetParameterAnnotation(
38
+ friendly_name="Dataset",
39
+ description="The dataset containing the numeric data.",
40
+ ),
41
+ ],
42
+ timestamp_col: Annotated[
43
+ str,
44
+ MetricColumnParameterAnnotation(
45
+ source_dataset_parameter_key="dataset",
46
+ allowed_column_types=[
47
+ ScalarType(dtype=DType.TIMESTAMP),
48
+ ],
49
+ tag_hints=[ScopeSchemaTag.PRIMARY_TIMESTAMP],
50
+ friendly_name="Timestamp Column",
51
+ description="A column containing timestamp values to bucket by.",
52
+ ),
53
+ ],
54
+ numeric_col: Annotated[
55
+ str,
56
+ MetricColumnParameterAnnotation(
57
+ source_dataset_parameter_key="dataset",
58
+ allowed_column_types=[
59
+ ScalarType(dtype=DType.INT),
60
+ ScalarType(dtype=DType.FLOAT),
61
+ ],
62
+ tag_hints=[ScopeSchemaTag.CONTINUOUS],
63
+ friendly_name="Numeric Column",
64
+ description="A column containing numeric values to sum.",
65
+ ),
66
+ ],
67
+ ) -> list[NumericMetric]:
68
+ escaped_timestamp_col = escape_identifier(timestamp_col)
69
+ escaped_numeric_col = escape_identifier(numeric_col)
70
+ count_query = f" \
71
+ select time_bucket(INTERVAL '5 minutes', {escaped_timestamp_col}) as ts, \
72
+ sum({escaped_numeric_col}) as sum \
73
+ from {dataset.dataset_table_name} \
74
+ where {escaped_numeric_col} is not null \
75
+ group by ts \
76
+ "
77
+ results = ddb_conn.sql(count_query).df()
78
+
79
+ series = self.dimensionless_query_results_to_numeric_metrics(
80
+ results,
81
+ "sum",
82
+ "ts",
83
+ )
84
+ series.dimensions = [Dimension(name="column_name", value=numeric_col)]
85
+
86
+ metric = self.series_to_metric(self.METRIC_NAME, [series])
87
+ return [metric]
File without changes