| 1667 | @pytest.mark.parametrize("pct", [True, False]) |
| 1668 | @pytest.mark.parametrize("test_data", ["default", "duplicates", "nans"]) |
| 1669 | def test_rank(window, method, pct, ascending, test_data): |
| 1670 | length = 20 |
| 1671 | if test_data == "default": |
| 1672 | ser = Series(data=np.random.default_rng(2).random(length)) |
| 1673 | elif test_data == "duplicates": |
| 1674 | ser = Series(data=np.random.default_rng(2).choice(3, length)) |
| 1675 | elif test_data == "nans": |
| 1676 | ser = Series( |
| 1677 | data=np.random.default_rng(2).choice( |
| 1678 | [1.0, 0.25, 0.75, np.nan, np.inf, -np.inf], length |
| 1679 | ) |
| 1680 | ) |
| 1681 | |
| 1682 | expected = ser.rolling(window).apply( |
| 1683 | lambda x: x.rank(method=method, pct=pct, ascending=ascending).iloc[-1] |
| 1684 | ) |
| 1685 | result = ser.rolling(window).rank(method=method, pct=pct, ascending=ascending) |
| 1686 | |
| 1687 | tm.assert_series_equal(result, expected) |
| 1688 | |
| 1689 | |
| 1690 | @pytest.mark.parametrize("window", [1, 3, 10, 20]) |