From a1b8704fe7dea6b2da4a5c97e4cef56c04e10b9c Mon Sep 17 00:00:00 2001 From: Ben Krikler Date: Sun, 6 Oct 2019 15:04:34 +0200 Subject: [PATCH 1/3] Add unit tests for negative JaggedNth --- fast_carpenter/define/reductions.py | 2 +- tests/define/test_reductions.py | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/fast_carpenter/define/reductions.py b/fast_carpenter/define/reductions.py index 98af2b9..7af8dc5 100644 --- a/fast_carpenter/define/reductions.py +++ b/fast_carpenter/define/reductions.py @@ -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 diff --git a/tests/define/test_reductions.py b/tests/define/test_reductions.py index aede8f5..8d4a7ac 100644 --- a/tests/define/test_reductions.py +++ b/tests/define/test_reductions.py @@ -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): @@ -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) From 9d39e967e72b67ad428cd3f7d1c3e3e53faeea7c Mon Sep 17 00:00:00 2001 From: Ben Krikler Date: Sun, 6 Oct 2019 15:06:09 +0200 Subject: [PATCH 2/3] Update CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20218fe..4a758a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) From 0ec4e7c2ab002268cdc234626b633e0b1dd55d7d Mon Sep 17 00:00:00 2001 From: Ben Krikler Date: Sun, 6 Oct 2019 15:06:15 +0200 Subject: [PATCH 3/3] =?UTF-8?q?Bump=20version:=200.14.1=20=E2=86=92=200.14?= =?UTF-8?q?.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fast_carpenter/version.py | 2 +- setup.cfg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fast_carpenter/version.py b/fast_carpenter/version.py index 439084e..5fa7d0b 100644 --- a/fast_carpenter/version.py +++ b/fast_carpenter/version.py @@ -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 diff --git a/setup.cfg b/setup.cfg index 6d95d3a..a5226c3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.14.1 +current_version = 0.14.2 commit = True tag = False