diff --git a/pyyeti/cyclecount.py b/pyyeti/cyclecount.py index a4fdd8b..a2156f0 100644 --- a/pyyeti/cyclecount.py +++ b/pyyeti/cyclecount.py @@ -383,6 +383,11 @@ def getbins(bins, mx, mn, right=True, check_bounds=False): Notes ----- + If `mx` and `mn` are equal, they are reset:: + + mx = mx + 0.5 + mn = mn - 0.5 + If `bins` is a scalar, this routine tries to mimic the behavior of the :func:`pandas.cut` routine:: @@ -400,8 +405,6 @@ def getbins(bins, mx, mn, right=True, check_bounds=False): Raises ------ - ValueError - If `mx` and `mn` are equal ValueError If `bins` is a vector but is not monotonically increasing @@ -419,7 +422,10 @@ def getbins(bins, mx, mn, right=True, check_bounds=False): if mx < mn: mx, mn = mn, mx elif mx == mn: - raise ValueError("`mx` and `mn` must not be equal") + mx = mx + 0.5 + mn = mn - 0.5 + # raise ValueError("`mx` and `mn` must not be equal") + if bins.size == 1: bins = int(bins) bb = np.linspace(mn, mx, bins + 1) diff --git a/tests/test_cyclecount.py b/tests/test_cyclecount.py index 4ce8e90..03d97ac 100644 --- a/tests/test_cyclecount.py +++ b/tests/test_cyclecount.py @@ -152,8 +152,6 @@ def test_getbins_1(): assert np.allclose(bb, [3.992, 6.0, 8.0, 10.0, 12.0]) bb = cyclecount.getbins(4, 4, 12, right=False) assert np.allclose(bb, [4.0, 6.0, 8.0, 10.0, 12.008]) - with pytest.raises(ValueError): - cyclecount.getbins(4, 3.0, 3.0) def test_getbins_2(): @@ -210,3 +208,28 @@ def test_sigcount_2(): assert np.allclose(table.values, [[12.0, 12.5], [12.5, 12.5]]) assert np.allclose(ampb, [0.500, 49.500, 98.598]) assert np.allclose(aveb, [-0.500, 0.000, 0.501]) + + +def test_sigcount_3(): + df = cyclecount.sigcount(np.array([10.0, -10.0, 10.0, -10.0]), ampbins=4) + assert np.allclose(df.values, [[0.0, 1.5, 0.0, 0.0]]) + assert list(df.columns) == [ + "(9.499, 9.750]", + "(9.750, 10.000]", + "(10.000, 10.250]", + "(10.250, 10.500]", + ] + assert list(df.index) == ["(-0.501, 0.500]"] + + df = cyclecount.sigcount( + np.array([10.0, -10.0, 10.0, -10.0]), ampbins=4, right=False + ) + + assert np.allclose(df.values, [[0.0, 0.0, 1.5, 0.0]]) + assert list(df.columns) == [ + "[9.500, 9.750)", + "[9.750, 10.000)", + "[10.000, 10.250)", + "[10.250, 10.501)", + ] + assert list(df.index) == ["[-0.500, 0.501)"]