Skip to content

Commit

Permalink
Sequences can no longer be initialised from tuples. No need for that,…
Browse files Browse the repository at this point in the history
… since one can always unpack them.
  • Loading branch information
ynikitenko committed Sep 2, 2023
1 parent 090ddb7 commit 351a12d
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 25 deletions.
4 changes: 0 additions & 4 deletions lena/core/fill_compute_seq.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ def __init__(self, *args):
fc_el = None
after = []

# same as for Sequence
if len(args) == 1 and isinstance(args[0], tuple):
args = args[0]

for ind, el in enumerate(args):
if not check_sequence_type.is_fill_compute_el(el):
before.append(el)
Expand Down
4 changes: 0 additions & 4 deletions lena/core/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ def __init__(self, *args):
"""
seq = []

# Sequence can be initialized from a single tuple
if len(args) == 1 and isinstance(args[0], tuple):
args = args[0]

for el in args:
if hasattr(el, "run") and callable(el.run):
seq.append(el)
Expand Down
4 changes: 0 additions & 4 deletions lena/core/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ def __init__(self, *args):
raise exceptions.LenaTypeError(
"Source must be initialized with 1 argument or more (0 given)"
)
if len(args) == 1 and isinstance(args[0], tuple):
# unpack one nesting level.
# Deeper nesting ((el,),) is not allowed.
args = args[0]
if not callable(args[0]):
raise exceptions.LenaTypeError(
"first element {} ".format(args[0])
Expand Down
2 changes: 1 addition & 1 deletion lena/flow/group_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def __init__(self, group_by, select=None, transform=(), scale=None,
if isinstance(transform, lena.core.LenaSequence):
self._transform = transform
else:
self._transform = lena.core.Sequence(transform)
self._transform = lena.core.Sequence(*transform)

self._yield_selected = yield_selected

Expand Down
6 changes: 0 additions & 6 deletions tests/core/test_fill_compute_seq.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import print_function

import pytest

from lena.core import Sequence, Source, FillCompute, FillComputeSeq, Run
Expand Down Expand Up @@ -39,11 +37,7 @@ def test_fill_compute_seq():
assert next(s3()) == 11.0

s4 = Source(cnt1, Slice(10), FillComputeSeq(mul2, FillCompute(Mean()), Print()))
# tuple initialization works
s41 = Source(cnt1, Slice(10), FillComputeSeq((mul2, FillCompute(Mean()), Print())))
assert next(s4()) == 11.0
assert next(s41()) == 11.0
# 11.0

s5 = FillComputeSeq(mul2, FillCompute(Mean()), Print())

Expand Down
8 changes: 2 additions & 6 deletions tests/core/test_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ def test_source():
with pytest.raises(lena.core.LenaTypeError):
s = Source(1)

# can initialize from tuple
s3 = Source((cnt0, Slice(1)))
assert list(s3()) == [0]

# nested tuples are not allowed (see no reason to do that)
# can not initialize from a tuple
with pytest.raises(lena.core.LenaTypeError):
Source(((cnt0,),))
Source((cnt0, Slice(1)))

0 comments on commit 351a12d

Please sign in to comment.