def test_bucket_float_1(self): # float grids type with 1 digit after decimal point column_names, bound_lows, bound_ups = _make_bucket_column_names( feature_grids=[1.2, 2.5, 3.5], endpoint=True) assert column_names == ["< 1.2", "[1.2, 2.5)", "[2.5, 3.5]", "> 3.5"] assert bound_lows == [np.nan, 1.2, 2.5, 3.5] assert bound_ups == [1.2, 2.5, 3.5, np.nan]
def test_bucket_no_endpoint(self): # without endpoint column_names, bound_lows, bound_ups = _make_bucket_column_names( feature_grids=[1, 2, 3], endpoint=False) assert column_names == ["< 1", "[1, 2)", "[2, 3)", ">= 3"] assert bound_lows == [np.nan, 1, 2, 3] assert bound_ups == [1, 2, 3, np.nan]
def test_bucket_float_0(self): # float grids type with 0 digit after decimal point column_names, bound_lows, bound_ups = _make_bucket_column_names( feature_grids=[1.0, 2.0, 3.0], endpoint=True) assert column_names == ["< 1", "[1, 2)", "[2, 3]", "> 3"] assert bound_lows == [np.nan, 1.0, 2.0, 3.0] assert bound_ups == [1.0, 2.0, 3.0, np.nan]
def test_bucket_default(self): # default settings column_names, bound_lows, bound_ups = _make_bucket_column_names( feature_grids=[1, 2, 3], endpoint=True) assert column_names == ["< 1", "[1, 2)", "[2, 3]", "> 3"] assert bound_lows == [np.nan, 1, 2, 3] assert bound_ups == [1, 2, 3, np.nan]
def test_bucket_value_close(self): # float grids type with 2 digit after decimal point # grid points very close in value column_names, bound_lows, bound_ups = _make_bucket_column_names(feature_grids=[1.234, 2.54322, 2.54332], endpoint=True) assert column_names == ['< 1.23', '[1.23, 2.54)', '[2.54, 2.54]', '> 2.54'] assert bound_lows == [np.nan, 1.234, 2.54322, 2.54332] assert bound_ups == [1.234, 2.54322, 2.54332, np.nan]
def test_bucket_float_more(self): # float grids type with more than 2 digits after decimal point # all round to 2 column_names, bound_lows, bound_ups = _make_bucket_column_names(feature_grids=[1.234, 2.54322, 3.54332], endpoint=True) assert column_names == ['< 1.23', '[1.23, 2.54)', '[2.54, 3.54]', '> 3.54'] assert bound_lows == [np.nan, 1.234, 2.54322, 3.54332] assert bound_ups == [1.234, 2.54322, 3.54332, np.nan]
def test_bucket_float_0(self): # float grids type with 0 digit after decimal point column_names, bound_lows, bound_ups = _make_bucket_column_names(feature_grids=[1., 2., 3.], endpoint=True) assert column_names == ['< 1', '[1, 2)', '[2, 3]', '> 3'] assert bound_lows == [np.nan, 1., 2., 3.] assert bound_ups == [1., 2., 3., np.nan]
def test_bucket_default(self): # default settings column_names, bound_lows, bound_ups = _make_bucket_column_names(feature_grids=[1, 2, 3], endpoint=True) assert column_names == ['< 1', '[1, 2)', '[2, 3]', '> 3'] assert bound_lows == [np.nan, 1, 2, 3] assert bound_ups == [1, 2, 3, np.nan]