Skip to content

Commit 0599336

Browse files
TST: parametrize single_bin_edge_adjustment re mroeschke's review
1 parent b286300 commit 0599336

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

pandas/tests/reshape/test_cut.py

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -410,29 +410,20 @@ def test_single_bin(data, length):
410410
tm.assert_series_equal(result, expected)
411411

412412

413-
def test_single_bin_edge_adjustment():
414-
# gh-58517 - test edge adjustment when all values are the same
415-
# mutation on _nbins_to_bins
416-
data = [0.1, 0.1, 0.1]
417-
result, bins = cut(data, 3, retbins=True)
413+
@pytest.mark.parametrize(
414+
"values,threshold",
415+
[
416+
([0.1, 0.1, 0.1], 0.001), # small positive values
417+
([-0.1, -0.1, -0.1], 0.001), # negative values
418+
([0.01, 0.01, 0.01], 0.0001), # very small values
419+
],
420+
)
421+
def test_single_bin_edge_adjustment(values, threshold):
422+
# gh-58517 - edge adjustment mutation when all values are same
423+
result, bins = cut(values, 3, retbins=True)
418424

419-
# mutation would create large bin sizes
420425
bin_range = bins[-1] - bins[0]
421-
assert bin_range < 0.001
422-
423-
# Test negative values
424-
data_neg = [-0.1, -0.1, -0.1]
425-
result_neg, bins_neg = cut(data_neg, 3, retbins=True)
426-
427-
bin_range_neg = bins_neg[-1] - bins_neg[0]
428-
assert bin_range_neg < 0.001
429-
430-
# Test very small values
431-
data_tiny = [0.01, 0.01, 0.01]
432-
result_tiny, bins_tiny = cut(data_tiny, 3, retbins=True)
433-
434-
bin_range_tiny = bins_tiny[-1] - bins_tiny[0]
435-
assert bin_range_tiny < 0.0001
426+
assert bin_range < threshold
436427

437428

438429
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)