class TaskWithCustomValue(PythonTask): custom_value = parameter.type(_MyCustomObjectValueType) list_of_customs = parameter.sub_type(_MyCustomObjectValueType)[List] report = output[str] def run(self): assert isinstance(self.custom_value, MyCustomObject) assert isinstance(self.list_of_customs[1], MyCustomObject) self.report = self.custom_value.custom + self.list_of_customs[1].custom
DateValueType, ObjectValueType, TargetPathValueType, TargetValueType, TimeDeltaValueType, ) from targets.values.custom_datetime_values import ( DateHourValueType, DateMinuteValueType, DateSecondValueType, MonthValueType, YearValueType, ) from targets.values.timedelta_value import DateIntervalValueType Parameter = parameter.type(ObjectValueType) StrParameter = parameter[str] IntParameter = parameter[int] FloatParameter = parameter[float] BoolParameter = parameter[bool] DictParameter = parameter[Dict] ListParameter = parameter[List] SetParameter = parameter[Set] FileListParameter = parameter[List[str]] ListStrParameter = parameter[List[str]] TupleParameter = parameter[Tuple] # target parameters TargetParameter = parameter.type(TargetValueType)
type = FeatureStore def load_from_target(self, target, **kwargs): features = target.partition("features").load(DataFrame) targets = target.partition("targets").load(DataFrame) return FeatureStore(features=features, targets=targets) def save_to_target(self, target, value, **kwargs): target.partition("features").save(value.features) target.partition("targets").save(value.targets) target.mark_success() FeatureStoreParameter = register_custom_parameter( value_type=MyFeatureStoreValueType, parameter=parameter.type(MyFeatureStoreValueType).folder.hdf5, ) ############### # USAGE @task(result=FeatureStoreParameter.output) def create_feature_store(ratio=1): features = pd.DataFrame(data=[[ratio, 2], [2, 3]], columns=["Names", "Births"]) targets = pd.DataFrame(data=[[1, 22], [2, 33]], columns=["Names", "Class"]) return FeatureStore(features=features, targets=targets) @task
from dbnd import PipelineTask, PythonTask, output, parameter from targets.dir_target import DirTarget from targets.target_config import file from targets.values import TargetValueType logger = logging.getLogger(__name__) class MyCustomFolder(DirTarget): def __init__(self, *args, **kwargs): super(MyCustomFolder, self).__init__(*args, **kwargs) self.scores = self.partition("scores", config=file.csv) self.reports = self.partition("reports", config=file.csv) my_custom_target = parameter.type(TargetValueType).custom_target( MyCustomFolder, folder=True) class TaskWithCustomOutput(PythonTask): custom = my_custom_target.output def run(self): self.custom.scores.write("1") self.custom.reports.write("2") self.custom.mark_success() class TaskWithCustomInput(PythonTask): custom = my_custom_target t_output = output.data