Skip to content

groupBy, countBy, indexBy raises exception when len(ns.result) is one #11

@ento

Description

@ento

These don't work because of a KeyError:

_.countBy([1], lambda num, *args: num)
_.groupBy([1], lambda num, *args: num)
_.indexBy([1], lambda num, *args: num)

Traceback:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "path/to/underscore/underscore.py", line 1505, in execute
    r = getattr(underscore(args[0]), a)()
  File "path/to/underscore/underscore.py", line 432, in indexBy
    res = self._group(self.obj, val, by)
  File "path/to/underscore/underscore.py", line 403, in _group
    return ns.result[0]
KeyError: 0

These appear to work, but that is because {False: [1]}[0], {0: [1]}[0] evaluates fine in Python.

_.groupBy([1], lambda num, *args: False)
_.groupBy([1], lambda num, *args: 0)

underscore.py version: HEAD of master branch

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions