-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2b7df37
commit 2b44b4c
Showing
11 changed files
with
278 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 11 additions & 3 deletions
14
data-processing-lib/python/src/data_processing/test_support/transform/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
from .table_transform_test import AbstractTableTransformTest | ||
from .binary_transform_test import AbstractBinaryTransformTest | ||
from .noop_transform import ( | ||
from data_processing.test_support.transform.table_transform_test import AbstractTableTransformTest | ||
from data_processing.test_support.transform.binary_transform_test import AbstractBinaryTransformTest | ||
from data_processing.test_support.transform.noop_transform import ( | ||
NOOPTransform, | ||
NOOPPythonTransformConfiguration, | ||
) | ||
from data_processing.test_support.transform.resize_transform import ( | ||
ResizeTransform, | ||
ResizePythonTransformConfiguration, | ||
) | ||
|
||
from data_processing.test_support.transform.pipeline_transform import ( | ||
ResizeNOOPPythonTransformConfiguration, | ||
) |
45 changes: 45 additions & 0 deletions
45
data-processing-lib/python/src/data_processing/test_support/transform/pipeline_transform.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# (C) Copyright IBM Corp. 2024. | ||
# Licensed under the Apache License, Version 2.0 (the “License”); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an “AS IS” BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
################################################################################ | ||
|
||
from data_processing.runtime.pure_python import PythonTransformLauncher | ||
from data_processing.runtime.pure_python.runtime_configuration import ( | ||
PythonTransformRuntimeConfiguration, | ||
) | ||
from data_processing.transform import PipelineTransformConfiguration | ||
from data_processing.utils import get_logger | ||
from data_processing.test_support.transform import NOOPPythonTransformConfiguration, ResizePythonTransformConfiguration | ||
|
||
logger = get_logger(__name__) | ||
|
||
|
||
class ResizeNOOPPythonTransformConfiguration(PythonTransformRuntimeConfiguration): | ||
""" | ||
Implements the PythonTransformConfiguration for NOOP as required by the PythonTransformLauncher. | ||
NOOP does not use a RayRuntime class so the superclass only needs the base | ||
python-only configuration. | ||
""" | ||
|
||
def __init__(self): | ||
""" | ||
Initialization | ||
""" | ||
super().__init__(transform_config= | ||
PipelineTransformConfiguration({"transforms": [ResizePythonTransformConfiguration(), | ||
NOOPPythonTransformConfiguration()]}) | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
# launcher = NOOPRayLauncher() | ||
launcher = PythonTransformLauncher(ResizeNOOPPythonTransformConfiguration()) | ||
logger.info("Launching resize/noop transform") | ||
launcher.launch() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
data-processing-lib/python/src/data_processing/transform/pipeline_transform_configuration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# (C) Copyright IBM Corp. 2024. | ||
# Licensed under the Apache License, Version 2.0 (the “License”); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an “AS IS” BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
################################################################################ | ||
|
||
from typing import Any | ||
from argparse import ArgumentParser, Namespace | ||
|
||
from data_processing.transform import TransformConfiguration | ||
from data_processing.transform.pure_python import PythonPipelineTransform | ||
from data_processing.utils import get_logger | ||
|
||
logger = get_logger(__name__) | ||
|
||
|
||
class PipelineTransformConfiguration(TransformConfiguration): | ||
|
||
""" | ||
Provides support for configuring and using the associated Transform class include | ||
configuration with CLI args. | ||
""" | ||
|
||
def __init__(self, config: dict[str, Any]): | ||
super().__init__( | ||
name="pipeline", | ||
transform_class=PythonPipelineTransform, | ||
) | ||
self.params = config | ||
|
||
def add_input_params(self, parser: ArgumentParser) -> None: | ||
""" | ||
Add Transform-specific arguments to the given parser. | ||
This will be included in a dictionary used to initialize the NOOPTransform. | ||
By convention a common prefix should be used for all transform-specific CLI args | ||
(e.g, noop_, pii_, etc.) | ||
""" | ||
for t in self.params["transforms"]: | ||
t.transform_config.add_input_params(parser=parser) | ||
|
||
def apply_input_params(self, args: Namespace) -> bool: | ||
""" | ||
Validate and apply the arguments that have been parsed | ||
:param args: user defined arguments. | ||
:return: True, if validate pass or False otherwise | ||
""" | ||
res = True | ||
for t in self.params["transforms"]: | ||
res = res and t.transform_config.apply_input_params(args=args) | ||
return res | ||
|
||
def get_input_params(self) -> dict[str, Any]: | ||
""" | ||
Provides a default implementation if the user has provided a set of keys to the initializer. | ||
These keys are used in apply_input_params() to extract our key/values from the global Namespace of args. | ||
:return: | ||
""" | ||
params = {} | ||
for t in self.params["transforms"]: | ||
params |= t.transform_config.get_input_params() | ||
return params | ||
|
||
def get_transform_metadata(self) -> dict[str, Any]: | ||
""" | ||
Get transform metadata. Before returning remove all parameters key accumulated in | ||
self.remove_from metadata. This allows transform developer to mark any input parameters | ||
that should not make it to the metadata. This can be parameters containing sensitive | ||
information, access keys, secrets, passwords, etc. | ||
:return parameters for metadata: | ||
""" | ||
params = {} | ||
for t in self.params["transforms"]: | ||
params |= t.transform_config.get_transform_metadata() | ||
return params |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
data-processing-lib/python/test/data_processing_tests/transform/test_resize.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# (C) Copyright IBM Corp. 2024. | ||
# Licensed under the Apache License, Version 2.0 (the “License”); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an “AS IS” BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
################################################################################ | ||
import os | ||
|
||
from data_processing.test_support.transform import ResizePythonTransformConfiguration | ||
from data_processing.runtime.pure_python import PythonTransformLauncher | ||
from data_processing.test_support.launch.transform_test import ( | ||
AbstractTransformLauncherTest, | ||
) | ||
|
||
|
||
class TestPythonResizeTransform(AbstractTransformLauncherTest): | ||
""" | ||
Extends the super-class to define the test data for the tests defined there. | ||
The name of this class MUST begin with the word Test so that pytest recognizes it as a test class. | ||
""" | ||
|
||
def get_test_transform_fixtures(self) -> list[tuple]: | ||
# The following based on 3 identical input files of about 39kbytes, and 200 rows | ||
fixtures = [] | ||
basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../../../transforms/universal/resize/python/test-data")) | ||
launcher = PythonTransformLauncher(ResizePythonTransformConfiguration()) | ||
|
||
# Split into 4 or so files | ||
config = {"resize_max_rows_per_table": 125} | ||
fixtures.append((launcher, config, basedir + "/input", basedir + "/expected-rows-125")) | ||
|
||
# Merge into 2 or so files | ||
config = {"resize_max_rows_per_table": 300} | ||
fixtures.append((launcher, config, basedir + "/input", basedir + "/expected-rows-300")) | ||
|
||
# # Merge all into a single table | ||
config = {"resize_max_mbytes_per_table": 1} | ||
fixtures.append((launcher, config, basedir + "/input", basedir + "/expected-mbytes-1")) | ||
|
||
# # Merge the 1st 2 and some of the 2nd with the 3rd | ||
config = {"resize_max_mbytes_per_table": 0.05} | ||
fixtures.append((launcher, config, basedir + "/input", basedir + "/expected-mbytes-0.05")) | ||
|
||
# Split into 4 or so files | ||
config = {"resize_max_mbytes_per_table": 0.02} | ||
fixtures.append((launcher, config, basedir + "/input", basedir + "/expected-mbytes-0.02")) | ||
|
||
return fixtures |
Oops, something went wrong.