Skip to content

Commit ed8fe28

Browse files
committed
applied Ghisvail's review suggestions
1 parent 1dc29da commit ed8fe28

File tree

4 files changed

+29
-27
lines changed

4 files changed

+29
-27
lines changed

pydra/engine/core.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ def split(
599599
if splitter is None and inputs:
600600
splitter = list(inputs)
601601
elif splitter:
602-
missing = set(self._unwrap_splitter(splitter)) - set(inputs)
602+
missing = set(hlpst.unwrap_splitter(splitter)) - set(inputs)
603603
missing = [m for m in missing if not m.startswith("_")]
604604
if missing:
605605
raise ValueError(
@@ -619,7 +619,7 @@ def split(
619619
new_inputs = {}
620620
split_inputs = set(
621621
f"{self.name}.{n}" if "." not in n else n
622-
for n in self._unwrap_splitter(splitter)
622+
for n in hlpst.unwrap_splitter(splitter)
623623
if not n.startswith("_")
624624
)
625625
for inpt_name, inpt_val in inputs.items():
@@ -643,28 +643,6 @@ def split(
643643
self.set_state(splitter)
644644
return self
645645

646-
@classmethod
647-
def _unwrap_splitter(
648-
cls, splitter: ty.Union[str, ty.List[str], ty.Tuple[str, ...]]
649-
) -> ty.Iterable[str]:
650-
"""Unwraps a splitter into a flat list of fields that are split over, i.e.
651-
[("a", "b"), "c"] -> ["a", "b", "c"]
652-
653-
Parameters
654-
----------
655-
splitter: str or list[str] or tuple[str, ...]
656-
the splitter spec to unwrap
657-
658-
Returns
659-
-------
660-
unwrapped : ty.Iterable[str]
661-
the field names listed in the splitter
662-
"""
663-
if isinstance(splitter, str):
664-
return [splitter]
665-
else:
666-
return itertools.chain(*(cls._unwrap_splitter(s) for s in splitter))
667-
668646
def combine(
669647
self,
670648
combiner: ty.Union[ty.List[str], str],

pydra/engine/helpers_state.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ def add_name_splitter(
337337
return _add_name(list(splitter), name)
338338
elif isinstance(splitter, tuple):
339339
return tuple(_add_name(list(splitter), name))
340+
else:
341+
return None
340342

341343

342344
def _add_name(mlist, name):
@@ -627,3 +629,25 @@ def inputs_types_to_dict(name, inputs):
627629
for field in input_names:
628630
inputs_dict[f"{name}.{field}"] = getattr(inputs, field)
629631
return inputs_dict
632+
633+
634+
def unwrap_splitter(
635+
splitter: ty.Union[str, ty.List[str], ty.Tuple[str, ...]]
636+
) -> ty.Iterable[str]:
637+
"""Unwraps a splitter into a flat list of fields that are split over, i.e.
638+
[("a", "b"), "c"] -> ["a", "b", "c"]
639+
640+
Parameters
641+
----------
642+
splitter: str or list[str] or tuple[str, ...]
643+
the splitter spec to unwrap
644+
645+
Returns
646+
-------
647+
unwrapped : ty.Iterable[str]
648+
the field names listed in the splitter
649+
"""
650+
if isinstance(splitter, str):
651+
return [splitter]
652+
else:
653+
return itertools.chain(*(unwrap_splitter(s) for s in splitter))

pydra/engine/tests/test_helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ def test_load_and_run_wf(tmpdir):
236236
"""testing load_and_run for pickled task"""
237237
wf_pkl = Path(tmpdir.join("wf_main.pkl"))
238238

239-
wf = Workflow(name="wf", input_spec=["x", "y"])
239+
wf = Workflow(name="wf", input_spec=["x", "y"], y=10)
240240
wf.add(multiply(name="mult", x=wf.lzin.x, y=wf.lzin.y))
241-
wf.split("x", x=[1, 2], y=10)
241+
wf.split("x", x=[1, 2])
242242

243243
wf.set_output([("out", wf.mult.lzout.out)])
244244

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ dependencies = [
1212
"cloudpickle >=2.0.0",
1313
"etelemetry >=0.2.2",
1414
"filelock >=3.0.0",
15-
"fileformats >=0.6",
15+
"fileformats >=0.8",
1616
"importlib_resources >=5.7; python_version < '3.11'",
1717
"typing_extensions >=4.6.3; python_version < '3.10'",
1818
"typing_utils >=0.1.0; python_version < '3.10'",

0 commit comments

Comments
 (0)