Skip to content

Commit

Permalink
Merge pull request #82 from FAST-HEP/BK_unit_test_negative_redux
Browse files Browse the repository at this point in the history
Add unit tests for negative JaggedNth
  • Loading branch information
benkrikler authored Oct 6, 2019
2 parents e8af6c2 + 0ec4e7c commit a195855
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
### Removed

## [0.14.2] - 2019-10-06
### Added
- JaggedNth supports negative indexing, PR #81 [@pmk21](https://github.com/pmk21!)

## [0.14.1] - 2019-10-04
### Added
- Added version flag to CLI, PR #79. [@maikefischer](github.com/maikefischer)
Expand Down
2 changes: 1 addition & 1 deletion fast_carpenter/define/reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, index, fill_missing, force_float=True):
self.dtype = float

def __call__(self, array):
mask = array.counts > abs(self.index)
mask = array.counts > abs(self.index) - int(self.index < 0)
output = np.full(len(array), self.fill_missing, dtype=self.dtype)
output[mask] = array[mask, self.index]
return output
Expand Down
2 changes: 1 addition & 1 deletion fast_carpenter/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ def split_version(version):
return tuple(result)


__version__ = '0.14.1'
__version__ = '0.14.2'
version_info = split_version(__version__) # noqa
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.14.1
current_version = 0.14.2
commit = True
tag = False

Expand Down
14 changes: 12 additions & 2 deletions tests/define/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

@pytest.fixture
def jagged_1():
boundaries = [0, 3, 5, 6, 9, 12, 12]
return JaggedArray(boundaries[:-1], boundaries[1:], [0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.0, 11.0])
return JaggedArray.fromiter([[0.0, 1.1, 2.2], [3.3, 4.4], [5.5], [6.6, 7.7, 8.8], [9.9, 10.0, 11.0], []])


def test_jagged_nth(jagged_1):
Expand All @@ -21,6 +20,17 @@ def test_jagged_nth(jagged_1):
assert np.isnan(reduced[5])


def test_jagged_nth_negative(jagged_1):
get_first_second = reductions.JaggedNth(-1, np.nan)
reduced = get_first_second(jagged_1)
assert reduced[0] == 2.2
assert reduced[1] == 4.4
assert reduced[2] == 5.5
assert reduced[3] == 8.8
assert reduced[4] == 11.0
assert np.isnan(reduced[5])


def test_jagged_nth_default_int(jagged_1):
get_first_second = reductions.JaggedNth(1, 0, force_float=False)
reduced = get_first_second(jagged_1)
Expand Down

0 comments on commit a195855

Please sign in to comment.