Repository: scipy/scipy
File: scipy/stats/tests/test_morestats.py (Python)

Code before:
    236093, 885778, 335969, 49266, 381430, 307437, 350077, 34346, 49340,
    84715, 527120, 40163, 46898, 4609439, 617038, 2239574, 159905, 118337,
    120357, 430778, 3799158, 3516745, 54198, 2970796, 729239, 97848, 6317375,
    887345, 58198, 88111, 867595, 210136, 1572103, 1420760, 574046, 845988,
    509743, 397927, 1119016, 189955, 3883644, 291051, 126467, 1239907, 2556229,
    411058, 657444, 2025234, 1211368, 93151, 577594, 4842264, 1531713, 305084,
    479251, 20591, 1466166, 137417, 897756, 594767, 3606337, 32844, 82426,
    1294831, 57174, 290167, 322066, 813146, 5671804, 4425684, 895607, 450598,
    1048958, 232844, 56871, 46113, 70366, 701618, 97739, 157113, 865047,
    194810, 1501615, 1765727, 38125, 2733376, 40642, 437590, 127337, 106310,
    4167579, 665303, 809250, 1210317, 45750, 1853687, 348954, 156786, 90793,
    1885504, 281501, 3902273, 359546, 797540, 623508, 3672775, 55330, 648221,
    266831, 90030, 7118372, 735521, 1009925, 283901, 806005, 2434897, 94321,
    309571, 4213597, 2213280, 120339, 64403, 8155209, 1686948, 4327743,
    1868312, 135670, 3189615, 1569446, 706058, 58056, 2438625, 520619, 105201,
    141961, 179990, 1351440, 3148662, 2804457, 2760144, 70775, 33807, 1926518,
    2362142, 186761, 240941, 97860, 1040429, 1431035, 78892, 484039, 57845,
    724126, 3166209, 175913, 159211, 1182095, 86734, 1921472, 513546, 326016,
    1891609
]


class TransformTest:
    def test_nan_policy(self):
        transform = getattr(stats, self.transform)
        normmax = getattr(stats, self.transform+"_normmax")
        special_transform = getattr(special, self.transform, _yeojohnson_transform)

        rng = np.random.default_rng(5908294582456923546)
        x = rng.random(10)
        x[3] = np.nan

        # lmb provided
        lmb = 1.0

        with pytest.raises(ValueError, match="The input contains nan values"):
            transform(x, lmb, nan_policy='raise')

        res = transform(x, lmb, nan_policy='propagate')
        np.testing.assert_allclose(res, special_transform(x, 1.))

        res = transform(x, lmb, nan_policy='omit')
        np.testing.assert_allclose(res, transform(x, lmb, nan_policy='propagate'))

        # lmb not provided
        with pytest.raises(ValueError, match="The input contains nan values"):
            transform(x, nan_policy='raise')

        res = transform(x, nan_policy='propagate')
        np.testing.assert_allclose(res[0], special_transform(x, np.nan))
        np.testing.assert_equal(res[1], np.nan)

Review comment (suggestion):
```suggestion
        normmax = getattr(stats, f"{self.transform}_normmax")
```

Code after:
    236093, 885778, 335969, 49266, 381430, 307437, 350077, 34346, 49340,
    84715, 527120, 40163, 46898, 4609439, 617038, 2239574, 159905, 118337,
    120357, 430778, 3799158, 3516745, 54198, 2970796, 729239, 97848, 6317375,
    887345, 58198, 88111, 867595, 210136, 1572103, 1420760, 574046, 845988,
    509743, 397927, 1119016, 189955, 3883644, 291051, 126467, 1239907, 2556229,
    411058, 657444, 2025234, 1211368, 93151, 577594, 4842264, 1531713, 305084,
    479251, 20591, 1466166, 137417, 897756, 594767, 3606337, 32844, 82426,
    1294831, 57174, 290167, 322066, 813146, 5671804, 4425684, 895607, 450598,
    1048958, 232844, 56871, 46113, 70366, 701618, 97739, 157113, 865047,
    194810, 1501615, 1765727, 38125, 2733376, 40642, 437590, 127337, 106310,
    4167579, 665303, 809250, 1210317, 45750, 1853687, 348954, 156786, 90793,
    1885504, 281501, 3902273, 359546, 797540, 623508, 3672775, 55330, 648221,
    266831, 90030, 7118372, 735521, 1009925, 283901, 806005, 2434897, 94321,
    309571, 4213597, 2213280, 120339, 64403, 8155209, 1686948, 4327743,
    1868312, 135670, 3189615, 1569446, 706058, 58056, 2438625, 520619, 105201,
    141961, 179990, 1351440, 3148662, 2804457, 2760144, 70775, 33807, 1926518,
    2362142, 186761, 240941, 97860, 1040429, 1431035, 78892, 484039, 57845,
    724126, 3166209, 175913, 159211, 1182095, 86734, 1921472, 513546, 326016,
    1891609
]


class TransformTest:
    def test_nan_policy(self):
        transform = getattr(stats, self.transform)
        normmax = getattr(stats, f"{self.transform}_normmax")
        special_transform = getattr(special, self.transform, _yeojohnson_transform)

        rng = np.random.default_rng(5908294582456923546)
        x = rng.random(10)
        x[3] = np.nan

        # lmb provided
        lmb = 1.0

        with pytest.raises(ValueError, match="The input contains nan values"):
            transform(x, lmb, nan_policy='raise')

        res = transform(x, lmb, nan_policy='propagate')
        np.testing.assert_allclose(res, special_transform(x, 1.))

        res = transform(x, lmb, nan_policy='omit')
        np.testing.assert_allclose(res, transform(x, lmb, nan_policy='propagate'))

        # lmb not provided
        with pytest.raises(ValueError, match="The input contains nan values"):
            transform(x, nan_policy='raise')

        res = transform(x, nan_policy='propagate')
        np.testing.assert_equal(res[0], special_transform(x, np.nan))
        np.testing.assert_equal(res[1], np.nan)