Skip to content

Commit d757a90

Browse files
authored
Allow empty sequence expressions seq(), pseq() (#161)
Issue: #159
1 parent 56ff25b commit d757a90

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Changelog
22
## Next Release
3+
* Allow empty sequence expressions `seq()`, `pseq()` (#159)
34

45
## Release 1.3.0
56
* added precompute attribute to reverse transformation (#137)

functional/streams.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,11 @@ def __call__(self, *args, **kwargs):
4141
"""
4242
# pylint: disable=no-self-use
4343
engine = ExecutionEngine()
44-
return self._parse_args(
45-
args, engine, "seq() takes at least 1 argument ({0} given)"
46-
)
44+
return self._parse_args(args, engine)
4745

48-
def _parse_args(self, args, engine, error_message):
46+
def _parse_args(self, args, engine):
4947
if len(args) == 0:
50-
raise TypeError(error_message.format(len(args)))
48+
return Sequence([], engine=engine, max_repr_items=self.max_repr_items)
5149
if len(args) == 1:
5250
try:
5351
if type(args[0]).__name__ == "DataFrame":
@@ -304,9 +302,7 @@ def __call__(self, *args, **kwargs):
304302
engine = ParallelExecutionEngine(
305303
processes=processes, partition_size=partition_size
306304
)
307-
return self._parse_args(
308-
args, engine, "pseq() takes at least 1 argument ({0} given)"
309-
)
305+
return self._parse_args(args, engine)
310306

311307

312308
# pylint: disable=invalid-name

functional/test/test_functional.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ def test_sliding(self):
663663

664664
def test_empty(self):
665665
self.assertTrue(self.seq([]).empty())
666+
self.assertEqual(self.seq(), self.seq([]))
666667

667668
def test_non_empty(self):
668669
self.assertTrue(self.seq([1]).non_empty())
@@ -920,8 +921,7 @@ def test_seq(self):
920921
self.assertIteratorEqual(self.seq(1, 2, 3), [1, 2, 3])
921922
self.assertIteratorEqual(self.seq(1), [1])
922923
self.assertIteratorEqual(self.seq(iter([1, 2, 3])), [1, 2, 3])
923-
with self.assertRaises(TypeError):
924-
self.seq()
924+
self.assertIteratorEqual(self.seq(), [])
925925

926926
def test_lineage_repr(self):
927927
s = self.seq(1).map(lambda x: x).filter(lambda x: True)

0 commit comments

Comments
 (0)