apache-hamilton 1.90.0.dev0__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.
- apache_hamilton-1.90.0.dev0.dist-info/METADATA +407 -0
- apache_hamilton-1.90.0.dev0.dist-info/RECORD +151 -0
- apache_hamilton-1.90.0.dev0.dist-info/WHEEL +4 -0
- apache_hamilton-1.90.0.dev0.dist-info/entry_points.txt +9 -0
- apache_hamilton-1.90.0.dev0.dist-info/licenses/DISCLAIMER +10 -0
- apache_hamilton-1.90.0.dev0.dist-info/licenses/LICENSE +228 -0
- apache_hamilton-1.90.0.dev0.dist-info/licenses/NOTICE +5 -0
- hamilton/__init__.py +24 -0
- hamilton/ad_hoc_utils.py +132 -0
- hamilton/async_driver.py +465 -0
- hamilton/base.py +466 -0
- hamilton/caching/__init__.py +16 -0
- hamilton/caching/adapter.py +1475 -0
- hamilton/caching/cache_key.py +70 -0
- hamilton/caching/fingerprinting.py +287 -0
- hamilton/caching/stores/__init__.py +16 -0
- hamilton/caching/stores/base.py +242 -0
- hamilton/caching/stores/file.py +140 -0
- hamilton/caching/stores/memory.py +297 -0
- hamilton/caching/stores/sqlite.py +282 -0
- hamilton/caching/stores/utils.py +40 -0
- hamilton/cli/__init__.py +16 -0
- hamilton/cli/__main__.py +328 -0
- hamilton/cli/commands.py +126 -0
- hamilton/cli/logic.py +338 -0
- hamilton/common/__init__.py +76 -0
- hamilton/contrib/__init__.py +41 -0
- hamilton/data_quality/__init__.py +16 -0
- hamilton/data_quality/base.py +198 -0
- hamilton/data_quality/default_validators.py +560 -0
- hamilton/data_quality/pandera_validators.py +121 -0
- hamilton/dataflows/__init__.py +726 -0
- hamilton/dataflows/template/README.md +25 -0
- hamilton/dataflows/template/__init__.py +54 -0
- hamilton/dataflows/template/author.md +28 -0
- hamilton/dataflows/template/requirements.txt +0 -0
- hamilton/dataflows/template/tags.json +7 -0
- hamilton/dataflows/template/valid_configs.jsonl +1 -0
- hamilton/dev_utils/__init__.py +16 -0
- hamilton/dev_utils/deprecation.py +204 -0
- hamilton/driver.py +2112 -0
- hamilton/execution/__init__.py +16 -0
- hamilton/execution/debugging_utils.py +56 -0
- hamilton/execution/executors.py +502 -0
- hamilton/execution/graph_functions.py +421 -0
- hamilton/execution/grouping.py +430 -0
- hamilton/execution/state.py +539 -0
- hamilton/experimental/__init__.py +27 -0
- hamilton/experimental/databackend.py +61 -0
- hamilton/experimental/decorators/__init__.py +16 -0
- hamilton/experimental/decorators/parameterize_frame.py +233 -0
- hamilton/experimental/h_async.py +29 -0
- hamilton/experimental/h_cache.py +413 -0
- hamilton/experimental/h_dask.py +28 -0
- hamilton/experimental/h_databackends.py +174 -0
- hamilton/experimental/h_ray.py +28 -0
- hamilton/experimental/h_spark.py +32 -0
- hamilton/function_modifiers/README +40 -0
- hamilton/function_modifiers/__init__.py +121 -0
- hamilton/function_modifiers/adapters.py +900 -0
- hamilton/function_modifiers/base.py +859 -0
- hamilton/function_modifiers/configuration.py +310 -0
- hamilton/function_modifiers/delayed.py +202 -0
- hamilton/function_modifiers/dependencies.py +246 -0
- hamilton/function_modifiers/expanders.py +1230 -0
- hamilton/function_modifiers/macros.py +1634 -0
- hamilton/function_modifiers/metadata.py +434 -0
- hamilton/function_modifiers/recursive.py +908 -0
- hamilton/function_modifiers/validation.py +289 -0
- hamilton/function_modifiers_base.py +31 -0
- hamilton/graph.py +1153 -0
- hamilton/graph_types.py +264 -0
- hamilton/graph_utils.py +41 -0
- hamilton/htypes.py +450 -0
- hamilton/io/__init__.py +32 -0
- hamilton/io/data_adapters.py +216 -0
- hamilton/io/default_data_loaders.py +224 -0
- hamilton/io/materialization.py +500 -0
- hamilton/io/utils.py +158 -0
- hamilton/lifecycle/__init__.py +67 -0
- hamilton/lifecycle/api.py +833 -0
- hamilton/lifecycle/base.py +1130 -0
- hamilton/lifecycle/default.py +802 -0
- hamilton/log_setup.py +47 -0
- hamilton/models.py +92 -0
- hamilton/node.py +449 -0
- hamilton/plugins/README.md +48 -0
- hamilton/plugins/__init__.py +16 -0
- hamilton/plugins/dask_extensions.py +47 -0
- hamilton/plugins/dlt_extensions.py +161 -0
- hamilton/plugins/geopandas_extensions.py +49 -0
- hamilton/plugins/h_dask.py +331 -0
- hamilton/plugins/h_ddog.py +522 -0
- hamilton/plugins/h_diskcache.py +163 -0
- hamilton/plugins/h_experiments/__init__.py +22 -0
- hamilton/plugins/h_experiments/__main__.py +62 -0
- hamilton/plugins/h_experiments/cache.py +39 -0
- hamilton/plugins/h_experiments/data_model.py +68 -0
- hamilton/plugins/h_experiments/hook.py +219 -0
- hamilton/plugins/h_experiments/server.py +375 -0
- hamilton/plugins/h_kedro.py +152 -0
- hamilton/plugins/h_logging.py +454 -0
- hamilton/plugins/h_mcp/__init__.py +28 -0
- hamilton/plugins/h_mcp/__main__.py +33 -0
- hamilton/plugins/h_mcp/_helpers.py +129 -0
- hamilton/plugins/h_mcp/_templates.py +417 -0
- hamilton/plugins/h_mcp/server.py +328 -0
- hamilton/plugins/h_mlflow.py +335 -0
- hamilton/plugins/h_narwhals.py +134 -0
- hamilton/plugins/h_openlineage.py +400 -0
- hamilton/plugins/h_opentelemetry.py +167 -0
- hamilton/plugins/h_pandas.py +257 -0
- hamilton/plugins/h_pandera.py +117 -0
- hamilton/plugins/h_polars.py +304 -0
- hamilton/plugins/h_polars_lazyframe.py +282 -0
- hamilton/plugins/h_pyarrow.py +56 -0
- hamilton/plugins/h_pydantic.py +127 -0
- hamilton/plugins/h_ray.py +242 -0
- hamilton/plugins/h_rich.py +142 -0
- hamilton/plugins/h_schema.py +493 -0
- hamilton/plugins/h_slack.py +100 -0
- hamilton/plugins/h_spark.py +1380 -0
- hamilton/plugins/h_threadpool.py +125 -0
- hamilton/plugins/h_tqdm.py +122 -0
- hamilton/plugins/h_vaex.py +129 -0
- hamilton/plugins/huggingface_extensions.py +236 -0
- hamilton/plugins/ibis_extensions.py +93 -0
- hamilton/plugins/jupyter_magic.py +622 -0
- hamilton/plugins/kedro_extensions.py +117 -0
- hamilton/plugins/lightgbm_extensions.py +99 -0
- hamilton/plugins/matplotlib_extensions.py +108 -0
- hamilton/plugins/mlflow_extensions.py +216 -0
- hamilton/plugins/numpy_extensions.py +105 -0
- hamilton/plugins/pandas_extensions.py +1763 -0
- hamilton/plugins/plotly_extensions.py +150 -0
- hamilton/plugins/polars_extensions.py +71 -0
- hamilton/plugins/polars_implementations.py +25 -0
- hamilton/plugins/polars_lazyframe_extensions.py +302 -0
- hamilton/plugins/polars_post_1_0_0_extensions.py +877 -0
- hamilton/plugins/polars_pre_1_0_0_extension.py +836 -0
- hamilton/plugins/pydantic_extensions.py +98 -0
- hamilton/plugins/pyspark_pandas_extensions.py +47 -0
- hamilton/plugins/sklearn_plot_extensions.py +129 -0
- hamilton/plugins/spark_extensions.py +105 -0
- hamilton/plugins/vaex_extensions.py +51 -0
- hamilton/plugins/xgboost_extensions.py +91 -0
- hamilton/plugins/yaml_extensions.py +89 -0
- hamilton/registry.py +254 -0
- hamilton/settings.py +18 -0
- hamilton/telemetry.py +50 -0
- hamilton/version.py +18 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
|
3
|
+
# distributed with this work for additional information
|
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
|
6
|
+
# "License"); you may not use this file except in compliance
|
|
7
|
+
# with the License. You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
|
|
18
|
+
import logging
|
|
19
|
+
|
|
20
|
+
from hamilton.plugins.h_dask import DaskDataFrameResult, DaskExecutor, DaskGraphAdapter
|
|
21
|
+
|
|
22
|
+
logger = logging.getLogger(__name__)
|
|
23
|
+
logger.warning(
|
|
24
|
+
"Importing from this module is deprecated. We have moved these features out of experimental! "
|
|
25
|
+
"Please use hamilton.plugins.h_dask instead."
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
__all__ = ["DaskGraphAdapter", "DaskDataFrameResult", "DaskExecutor"]
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
|
3
|
+
# distributed with this work for additional information
|
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
|
6
|
+
# "License"); you may not use this file except in compliance
|
|
7
|
+
# with the License. You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
|
|
18
|
+
"""This module defines "databackends". They are essentially abstract types such as
|
|
19
|
+
`AbstractPandasDataFrame` or `AbstractPandasSeries` which can be used with
|
|
20
|
+
`isinstance()` or `issubclass()` without having to import pandas.
|
|
21
|
+
|
|
22
|
+
It is powerful when used with `@functools.singledispatch`
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
@functools.singledispatch
|
|
26
|
+
def get_arrow_schema(df) -> pyarrow.Schema:
|
|
27
|
+
if not hasattr(df, "__dataframe__"):
|
|
28
|
+
raise NotImplementedError(f"Type {type(df)} is currently unsupported.")
|
|
29
|
+
return from_dataframe(df, allow_copy=True).schema
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@get_arrow_schema.register
|
|
33
|
+
def _(df: h_databackends.AbstractPandasDataFrame) -> pyarrow.Schema:
|
|
34
|
+
return pyarrow.Table.from_pandas(df).schema
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@get_arrow_schema.register
|
|
38
|
+
def _(df: h_databackends.AbstractIbisDataFrame) -> pyarrow.Schema:
|
|
39
|
+
return df.schema().to_pyarrow()
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Instead of centralizing code by library / dependency, we can now centralize it
|
|
43
|
+
by Hamilton feature. For example, we can have all the implementations to collect
|
|
44
|
+
schemas under `schema.py` instead of spread across `pandas_extension.py`,
|
|
45
|
+
polars_extension.py`, etc.
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
import importlib
|
|
49
|
+
import inspect
|
|
50
|
+
|
|
51
|
+
from hamilton.experimental.databackend import AbstractBackend
|
|
52
|
+
|
|
53
|
+
# TODO add a `_has__dataframe__` attribute for those that implement the
|
|
54
|
+
# dataframe interchange protocol
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
# PyArrow
|
|
58
|
+
class AbstractPyArrowDataFrame(AbstractBackend):
|
|
59
|
+
_backends = [("pyarrow", "Table"), ("pyarrow", "RecordBatch")]
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class AbstractPyarrowColumn(AbstractBackend):
|
|
63
|
+
_backends = [("pyarrow", "Array"), ("pyarrow", "ChunkedArray")]
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
# Ibis
|
|
67
|
+
class AbstractIbisDataFrame(AbstractBackend):
|
|
68
|
+
_backends = [("ibis.expr.types", "Table")]
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class AbstractIbisColumn(AbstractBackend):
|
|
72
|
+
_backends = [("ibis.expr.types", "Column")]
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
# Pandas
|
|
76
|
+
class AbstractPandasDataFrame(AbstractBackend):
|
|
77
|
+
_backends = [("pandas", "DataFrame")]
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class AbstractPandasColumn(AbstractBackend):
|
|
81
|
+
_backends = [("pandas", "Series")]
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
# Polars
|
|
85
|
+
class AbstractPolarsDataFrame(AbstractBackend):
|
|
86
|
+
_backends = [("polars", "DataFrame")]
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class AbstractPolarsColumn(AbstractBackend):
|
|
90
|
+
_backends = [("polars", "Series")]
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
# Polars Lazy
|
|
94
|
+
class AbstractLazyPolarsDataFrame(AbstractBackend):
|
|
95
|
+
_backends = [("polars", "LazyFrame")]
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
# Vaex
|
|
99
|
+
class AbstractVaexDataFrame(AbstractBackend):
|
|
100
|
+
_backends = [("vaex.dataframe", "DataFrame")]
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class AbstractVaexColumn(AbstractBackend):
|
|
104
|
+
_backends = [("vaex.expression", "Expression")]
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
# Dask
|
|
108
|
+
class AbstractDaskDataFrame(AbstractBackend):
|
|
109
|
+
_backends = [("dask.dataframe", "DataFrame")]
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class AbstractDaskColumn(AbstractBackend):
|
|
113
|
+
_backends = [("dask.dataframe", "Series")]
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
# SparkSQL
|
|
117
|
+
class AbstractSparkSQLDataFrame(AbstractBackend):
|
|
118
|
+
_backends = [("pyspark.sql", "DataFrame")]
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
# SparkPandas
|
|
122
|
+
class AbstractSparkPandasDataFrame(AbstractBackend):
|
|
123
|
+
_backends = [("pyspark.pandas", "DataFrame")]
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
class AbstractSparkPandasColumn(AbstractBackend):
|
|
127
|
+
_backends = [("pyspark.pandas", "Series")]
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
# Geopandas
|
|
131
|
+
class AbstractGeoPandasDataFrame(AbstractBackend):
|
|
132
|
+
_backends = [("geopandas", "GeoDataFrame")]
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
class AbstractGeoPandasColumn(AbstractBackend):
|
|
136
|
+
_backends = [("geopandas", "GeoSeries")]
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
# cuDF
|
|
140
|
+
class AbstractCuDFDataFrame(AbstractBackend):
|
|
141
|
+
_backends = [("cudf", "DataFrame")]
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
# Modin
|
|
145
|
+
class AbstractModinDataFrame(AbstractBackend):
|
|
146
|
+
_backends = [("modin.pandas", "DataFrame")]
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
# numpy
|
|
150
|
+
class AbstractNumpyArray(AbstractBackend):
|
|
151
|
+
_backends = [("numpy", "ndarray")]
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def register_backends() -> tuple[tuple[type], tuple[type]]:
|
|
155
|
+
"""Register databackends defined in this module that
|
|
156
|
+
include `DataFrame` and `Column` in their class name
|
|
157
|
+
"""
|
|
158
|
+
abstract_dataframe_types = set()
|
|
159
|
+
abstract_column_types = set()
|
|
160
|
+
|
|
161
|
+
h_databackends_module = importlib.import_module(__name__)
|
|
162
|
+
for name, cls in inspect.getmembers(h_databackends_module, inspect.isclass):
|
|
163
|
+
if "DataFrame" in name:
|
|
164
|
+
abstract_dataframe_types.add(cls)
|
|
165
|
+
elif "Column" in name:
|
|
166
|
+
abstract_column_types.add(cls)
|
|
167
|
+
|
|
168
|
+
# Union[tuple()] creates a Union type object
|
|
169
|
+
DATAFRAME_TYPES = tuple(abstract_dataframe_types)
|
|
170
|
+
COLUMN_TYPES = tuple(abstract_column_types)
|
|
171
|
+
return DATAFRAME_TYPES, COLUMN_TYPES
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
DATAFRAME_TYPES, COLUMN_TYPES = register_backends()
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
|
3
|
+
# distributed with this work for additional information
|
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
|
6
|
+
# "License"); you may not use this file except in compliance
|
|
7
|
+
# with the License. You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
|
|
18
|
+
import logging
|
|
19
|
+
|
|
20
|
+
from hamilton.plugins.h_ray import RayGraphAdapter, RayTaskExecutor
|
|
21
|
+
|
|
22
|
+
logger = logging.getLogger(__name__)
|
|
23
|
+
logger.warning(
|
|
24
|
+
"Importing from this module is deprecated. We have moved these features out of experimental!"
|
|
25
|
+
" Please use hamilton.plugins.h_ray instead."
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
__all__ = ["RayGraphAdapter", "RayTaskExecutor"]
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
|
3
|
+
# distributed with this work for additional information
|
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
|
6
|
+
# "License"); you may not use this file except in compliance
|
|
7
|
+
# with the License. You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
|
|
18
|
+
import logging
|
|
19
|
+
|
|
20
|
+
from hamilton.plugins.h_spark import (
|
|
21
|
+
KoalasDataFrameResult,
|
|
22
|
+
PySparkUDFGraphAdapter,
|
|
23
|
+
SparkKoalasGraphAdapter,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
logger = logging.getLogger(__name__)
|
|
27
|
+
logger.warning(
|
|
28
|
+
"Importing from this module is deprecated. We have moved these features out of experimental!"
|
|
29
|
+
" Please use hamilton.plugins.h_spark instead."
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
__all__ = ["KoalasDataFrameResult", "SparkKoalasGraphAdapter", "PySparkUDFGraphAdapter"]
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
or more contributor license agreements. See the NOTICE file
|
|
4
|
+
distributed with this work for additional information
|
|
5
|
+
regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
to you under the Apache License, Version 2.0 (the
|
|
7
|
+
"License"); you may not use this file except in compliance
|
|
8
|
+
with the License. You may obtain a copy of the License at
|
|
9
|
+
|
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
|
|
12
|
+
Unless required by applicable law or agreed to in writing,
|
|
13
|
+
software distributed under the License is distributed on an
|
|
14
|
+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
KIND, either express or implied. See the License for the
|
|
16
|
+
specific language governing permissions and limitations
|
|
17
|
+
under the License.
|
|
18
|
+
-->
|
|
19
|
+
|
|
20
|
+
# with_columns_base
|
|
21
|
+
|
|
22
|
+
Documenting the current design flow for the `with_columns` decorator.
|
|
23
|
+
|
|
24
|
+
For now, it belongs to the `NodeInjector` lifecycle since it still runs the decorated function as a node but injects the dataframe with columns appended columns as one of the parameters.
|
|
25
|
+
|
|
26
|
+
The `with_columns` consists of three parts that are represented in the corresponding three abstract methods in `with_columns_base`:
|
|
27
|
+
|
|
28
|
+
1. `get_initial_nodes` -- Input node(s): Either a dataframe if `pass_datafame_as` is used or extracted columns into nodes if `columns_to_pass` and is library specific.
|
|
29
|
+
2. `get_subdag_nodes` -- Subdag nodes: Creating the `subdag` is outsourced to `recursive.subdag`, left flexibility to pre- and post-process since some libraries need that (see h_spark).
|
|
30
|
+
3. `chain_subdag_nodes` -- Merge node: The append functionality between dataframe and selected columns is library specific.
|
|
31
|
+
|
|
32
|
+
Each plugin library that can implement `with_columns` should subclass from this base class and implement the three abstract methods (four since `validate()` is also abstract). The child
|
|
33
|
+
classes need to override the `init` where they call out to the parent `init` and pass in `dataframe_type` which is registered in the corresponding `extensions` and has information of what
|
|
34
|
+
columns types are permitted for the given dataframe type.
|
|
35
|
+
|
|
36
|
+
Keeping it for now loosely coupled to the `registry` and detached from `ResultBuilder`. The API is private, should we want to switch to `registry`, the refactoring is straightforward and shouldn't get us into trouble down the road.
|
|
37
|
+
|
|
38
|
+
## NOTE
|
|
39
|
+
The handling of scalars and dataframe types varies between library to library. We made the decision that such a thing should not be permissible, so all the selected columns that want to be
|
|
40
|
+
appended to the original dataframe need to have the matching column type that is registered in the `registry` and set in the library extension modules.
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
|
3
|
+
# distributed with this work for additional information
|
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
|
6
|
+
# "License"); you may not use this file except in compliance
|
|
7
|
+
# with the License. You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
|
|
18
|
+
import logging
|
|
19
|
+
|
|
20
|
+
from . import (
|
|
21
|
+
adapters,
|
|
22
|
+
base,
|
|
23
|
+
configuration,
|
|
24
|
+
delayed,
|
|
25
|
+
dependencies,
|
|
26
|
+
expanders,
|
|
27
|
+
macros,
|
|
28
|
+
metadata,
|
|
29
|
+
recursive,
|
|
30
|
+
validation,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
logger = logging.getLogger(__name__)
|
|
34
|
+
|
|
35
|
+
"""
|
|
36
|
+
Annotations for modifying the way functions get added to the DAG.
|
|
37
|
+
All user-facing annotation classes are lowercase as they're meant to be used
|
|
38
|
+
as annotations. They are classes to hold state and subclass common functionality.
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
# These all represent the public API for function_modifiers
|
|
42
|
+
# All new user-facing decorators/helper functions should be here
|
|
43
|
+
|
|
44
|
+
# Backwards-compatibility to be safe
|
|
45
|
+
InvalidDecoratorException = base.InvalidDecoratorException
|
|
46
|
+
|
|
47
|
+
# The config decorator
|
|
48
|
+
config = configuration.config
|
|
49
|
+
hamilton_exclude = configuration.hamilton_exclude()
|
|
50
|
+
|
|
51
|
+
# Dependency Specification
|
|
52
|
+
# Helper functions to specify dependency sources for parameterization
|
|
53
|
+
value = dependencies.value
|
|
54
|
+
source = dependencies.source
|
|
55
|
+
group = dependencies.group
|
|
56
|
+
configuration = dependencies.configuration
|
|
57
|
+
|
|
58
|
+
# These aren't strictly part of the API but we should have them here for safety
|
|
59
|
+
LiteralDependency = dependencies.LiteralDependency
|
|
60
|
+
UpstreamDependency = dependencies.UpstreamDependency
|
|
61
|
+
|
|
62
|
+
# Parameterization decorators (both the old and new ones)
|
|
63
|
+
# The three "blessed" @parameterize decorators
|
|
64
|
+
parameterize = expanders.parameterize
|
|
65
|
+
parameterize_sources = expanders.parameterize_sources
|
|
66
|
+
parameterize_values = expanders.parameterize_values
|
|
67
|
+
parameterize_extract_columns = expanders.parameterize_extract_columns
|
|
68
|
+
ParameterizedExtract = expanders.ParameterizedExtract
|
|
69
|
+
inject = expanders.inject
|
|
70
|
+
|
|
71
|
+
# The older ones that will be deprecated
|
|
72
|
+
parametrized = expanders.parametrized
|
|
73
|
+
parameterized_inputs = expanders.parameterized_inputs
|
|
74
|
+
parametrized_input = expanders.parametrized_input
|
|
75
|
+
|
|
76
|
+
# Extract decorators
|
|
77
|
+
extract_columns = expanders.extract_columns
|
|
78
|
+
extract_fields = expanders.extract_fields
|
|
79
|
+
unpack_fields = expanders.unpack_fields
|
|
80
|
+
|
|
81
|
+
# does decorator
|
|
82
|
+
does = macros.does
|
|
83
|
+
pipe = macros.pipe
|
|
84
|
+
pipe_input = macros.pipe_input
|
|
85
|
+
pipe_output = macros.pipe_output
|
|
86
|
+
mutate = macros.mutate
|
|
87
|
+
step = macros.step
|
|
88
|
+
apply_to = macros.apply_to
|
|
89
|
+
|
|
90
|
+
# resolve transform/model decorator
|
|
91
|
+
dynamic_transform = macros.dynamic_transform
|
|
92
|
+
model = macros.model
|
|
93
|
+
|
|
94
|
+
# Metadata-specifying decorators
|
|
95
|
+
tag = metadata.tag
|
|
96
|
+
tag_outputs = metadata.tag_outputs
|
|
97
|
+
schema = metadata.schema
|
|
98
|
+
cache = metadata.cache
|
|
99
|
+
|
|
100
|
+
# data quality + associated tags
|
|
101
|
+
check_output = validation.check_output
|
|
102
|
+
check_output_custom = validation.check_output_custom
|
|
103
|
+
IS_DATA_VALIDATOR_TAG = validation.IS_DATA_VALIDATOR_TAG
|
|
104
|
+
DATA_VALIDATOR_ORIGINAL_OUTPUT_TAG = validation.DATA_VALIDATOR_ORIGINAL_OUTPUT_TAG
|
|
105
|
+
|
|
106
|
+
# recursive/subdag operators
|
|
107
|
+
|
|
108
|
+
subdag = recursive.subdag
|
|
109
|
+
parameterized_subdag = recursive.parameterized_subdag
|
|
110
|
+
|
|
111
|
+
# resolve/meta stuff -- power user features
|
|
112
|
+
|
|
113
|
+
resolve = delayed.resolve
|
|
114
|
+
ResolveAt = delayed.ResolveAt
|
|
115
|
+
resolve_from_config = delayed.resolve_from_config
|
|
116
|
+
|
|
117
|
+
# materialization stuff
|
|
118
|
+
load_from = adapters.load_from
|
|
119
|
+
save_to = adapters.save_to
|
|
120
|
+
dataloader = adapters.dataloader
|
|
121
|
+
datasaver = adapters.datasaver
|