def test_generate_bins(self): values = np.array([1, 2, 3, 4, 5, 6], dtype=np.int64) binner = np.array([0, 3, 6, 9], dtype=np.int64) for func in [lib.generate_bins_dt64, generate_bins_generic]: bins = func(values, binner, closed="left") assert (bins == np.array([2, 5, 6])).all() bins = func(values, binner, closed="right") assert (bins == np.array([3, 6, 6])).all() for func in [lib.generate_bins_dt64, generate_bins_generic]: values = np.array([1, 2, 3, 4, 5, 6], dtype=np.int64) binner = np.array([0, 3, 6], dtype=np.int64) bins = func(values, binner, closed="right") assert (bins == np.array([3, 6])).all() msg = "Invalid length for values or for binner" with pytest.raises(ValueError, match=msg): generate_bins_generic(values, [], "right") with pytest.raises(ValueError, match=msg): generate_bins_generic(values[:0], binner, "right") msg = "Values falls before first bin" with pytest.raises(ValueError, match=msg): generate_bins_generic(values, [4], "right") msg = "Values falls after last bin" with pytest.raises(ValueError, match=msg): generate_bins_generic(values, [-3, -1], "right")
def test_generate_bins(self): values = np.array([1, 2, 3, 4, 5, 6], dtype=np.int64) binner = np.array([0, 3, 6, 9], dtype=np.int64) for func in [lib.generate_bins_dt64, generate_bins_generic]: bins = func(values, binner, closed='left') assert ((bins == np.array([2, 5, 6])).all()) bins = func(values, binner, closed='right') assert ((bins == np.array([3, 6, 6])).all()) for func in [lib.generate_bins_dt64, generate_bins_generic]: values = np.array([1, 2, 3, 4, 5, 6], dtype=np.int64) binner = np.array([0, 3, 6], dtype=np.int64) bins = func(values, binner, closed='right') assert ((bins == np.array([3, 6])).all()) msg = "Invalid length for values or for binner" with pytest.raises(ValueError, match=msg): generate_bins_generic(values, [], 'right') with pytest.raises(ValueError, match=msg): generate_bins_generic(values[:0], binner, 'right') msg = "Values falls before first bin" with pytest.raises(ValueError, match=msg): generate_bins_generic(values, [4], 'right') msg = "Values falls after last bin" with pytest.raises(ValueError, match=msg): generate_bins_generic(values, [-3, -1], 'right')