Skip to content

Commit

Permalink
structures.MapBins has default select_bins selecting everything.
Browse files Browse the repository at this point in the history
  • Loading branch information
ynikitenko committed Apr 22, 2022
1 parent ff9b812 commit f4f743b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lena/structures/split_into_bins.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class MapBins(object):
corresponding to the vector's components.
"""

def __init__(self, seq, select_bins=True, drop_bins_context=True):
def __init__(self, seq, select_bins=lambda _: True, drop_bins_context=True):
"""*seq* is a sequence or an element applied to bin contents.
If *seq* is not a :class:`.Sequence`
or an element with *run* method, it is converted to a
Expand Down
9 changes: 5 additions & 4 deletions tests/structures/test_split_into_bins.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,13 @@ def test_iterate_bins():

def test_map_bins():
## test init
# wrong sequence raises
with pytest.raises(lena.core.LenaTypeError):
MapBins((), 1)
# this works
MapBins(lambda _: True, ())
MapBins(1)

# wrong selector raises
with pytest.raises(lena.core.LenaTypeError):
MapBins(1, select_bins=lambda _: True)
MapBins((), select_bins=1)

# not selected flow passes unchanged
data = [1, (2, {}), (histogram([0, 1], [1]), {})]
Expand Down

0 comments on commit f4f743b

Please sign in to comment.