Skip to content
This repository was archived by the owner on Aug 25, 2024. It is now read-only.

Commit 0930a81

Browse files
operation: output: get single: Added ability to rename outputs using GetSingle
Signed-off-by: sakshamarora1 <[email protected]>
1 parent d1087f2 commit 0930a81

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88
### Added
9+
- Added ability to rename outputs using GetSingle
910
- Tutorial for using NLP operations with models
1011
- Operations plugin for NLP wrapping spacy and scikit functions
1112
- Support for default value in a Definition

dffml/operation/output.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ async def run(self, inputs: Dict[str, Any]) -> Dict[str, Any]:
169169
# TODO Address the need to copy operation implementation inputs dict
170170
# In case the input is used elsewhere in the network
171171
exported = copy.deepcopy(inputs["spec"])
172+
name_map = {}
173+
for i, input_value in enumerate(exported):
174+
if isinstance(input_value, dict):
175+
name, value = list(input_value.items())[0]
176+
name_map[value] = name
177+
exported[i] = value
178+
172179
# Look up the definiton for each
173180
for convert in range(0, len(exported)):
174181
exported[convert] = await self.octx.ictx.definition(
@@ -184,6 +191,12 @@ async def run(self, inputs: Dict[str, Any]) -> Dict[str, Any]:
184191
async for item in od.inputs(definition):
185192
want.setdefault(definition.name, [])
186193
want[definition.name].append(item.value)
194+
195+
# Rename outputs if present in name_map
196+
for key, value in want.copy().items():
197+
if name_map.get(key, None):
198+
want[name_map[key]] = value
199+
want.pop(key)
187200
return want
188201

189202

@@ -224,11 +237,12 @@ class GetSingle(GetMulti):
224237
>>> from dffml import *
225238
>>>
226239
>>> URL = Definition(name="URL", primitive="string")
240+
>>> ORG = Definition(name="ORG", primitive="string")
227241
>>>
228242
>>> dataflow = DataFlow.auto(GetSingle)
229243
>>> dataflow.seed.append(
230244
... Input(
231-
... value=[URL.name],
245+
... value=[{"Repo Link": URL.name}, ORG.name],
232246
... definition=GetSingle.op.inputs["spec"]
233247
... )
234248
... )
@@ -238,12 +252,16 @@ class GetSingle(GetMulti):
238252
... Input(
239253
... value="https://github.com/intel/dffml",
240254
... definition=URL
255+
... ),
256+
... Input(
257+
... value="Intel",
258+
... definition=ORG
241259
... )
242260
... ]):
243261
... print(results)
244262
...
245263
>>> asyncio.run(main())
246-
{'URL': 'https://github.com/intel/dffml'}
264+
{'ORG': 'Intel', 'Repo Link': 'https://github.com/intel/dffml'}
247265
"""
248266

249267
async def run(self, inputs: Dict[str, Any]) -> Dict[str, Any]:

0 commit comments

Comments
 (0)