|
4 | 4 | )
|
5 | 5 |
|
6 | 6 | import numpy as np
|
| 7 | +from numpy.testing import assert_allclose |
7 | 8 | import pytest
|
8 | 9 |
|
9 | 10 | from pandas.compat import (
|
@@ -1099,11 +1100,7 @@ def test_rolling_var_numerical_issues(func, third_value, values):
|
1099 | 1100 | ds = Series([99999999999999999, 1, third_value, 2, 3, 1, 1])
|
1100 | 1101 | result = getattr(ds.rolling(2), func)()
|
1101 | 1102 | expected = Series([np.nan] + values)
|
1102 |
| - tm.assert_series_equal(result, expected) |
1103 |
| - # GH 42064 |
1104 |
| - # new `roll_var` will output 0.0 correctly |
1105 |
| - tm.assert_series_equal(result == 0, expected == 0) |
1106 |
| - |
| 1103 | + assert_allclose(result[1:].values, expected[1:].values, rtol=1e-5, atol=1e-8) |
1107 | 1104 |
|
1108 | 1105 | def test_timeoffset_as_window_parameter_for_corr(unit):
|
1109 | 1106 | # GH: 28266
|
@@ -1946,66 +1943,3 @@ def test_rolling_timedelta_window_non_nanoseconds(unit, tz):
|
1946 | 1943 | df.index = df.index.as_unit("ns")
|
1947 | 1944 |
|
1948 | 1945 | tm.assert_frame_equal(ref_df, df)
|
1949 |
| - |
1950 |
| - |
1951 |
| -class PrescribedWindowIndexer(BaseIndexer): |
1952 |
| - def __init__(self, start, end): |
1953 |
| - self._start = start |
1954 |
| - self._end = end |
1955 |
| - super().__init__() |
1956 |
| - |
1957 |
| - def get_window_bounds( |
1958 |
| - self, num_values=None, min_periods=None, center=None, closed=None, step=None |
1959 |
| - ): |
1960 |
| - if num_values is None: |
1961 |
| - num_values = len(self._start) |
1962 |
| - start = np.clip(self._start, 0, num_values) |
1963 |
| - end = np.clip(self._end, 0, num_values) |
1964 |
| - return start, end |
1965 |
| - |
1966 |
| - |
1967 |
| -class TestMinMax: |
1968 |
| - @pytest.mark.parametrize( |
1969 |
| - "is_max, has_nan, exp_list", |
1970 |
| - [ |
1971 |
| - (True, False, [3.0, 5.0, 2.0, 5.0, 1.0, 5.0, 6.0, 7.0, 8.0, 9.0]), |
1972 |
| - (True, True, [3.0, 4.0, 2.0, 4.0, 1.0, 4.0, 6.0, 7.0, 7.0, 9.0]), |
1973 |
| - (False, False, [3.0, 2.0, 2.0, 1.0, 1.0, 0.0, 0.0, 0.0, 7.0, 0.0]), |
1974 |
| - (False, True, [3.0, 2.0, 2.0, 1.0, 1.0, 1.0, 6.0, 6.0, 7.0, 1.0]), |
1975 |
| - ], |
1976 |
| - ) |
1977 |
| - def test_minmax(self, is_max, has_nan, exp_list): |
1978 |
| - nan_idx = [0, 5, 8] |
1979 |
| - df = DataFrame( |
1980 |
| - { |
1981 |
| - "data": [5.0, 4.0, 3.0, 2.0, 1.0, 0.0, 6.0, 7.0, 8.0, 9.0], |
1982 |
| - "start": [2, 0, 3, 0, 4, 0, 5, 5, 7, 3], |
1983 |
| - "end": [3, 4, 4, 5, 5, 6, 7, 8, 9, 10], |
1984 |
| - } |
1985 |
| - ) |
1986 |
| - if has_nan: |
1987 |
| - df.loc[nan_idx, "data"] = np.nan |
1988 |
| - expected = Series(exp_list, name="data") |
1989 |
| - r = df.data.rolling( |
1990 |
| - PrescribedWindowIndexer(df.start.to_numpy(), df.end.to_numpy()) |
1991 |
| - ) |
1992 |
| - if is_max: |
1993 |
| - result = r.max() |
1994 |
| - else: |
1995 |
| - result = r.min() |
1996 |
| - |
1997 |
| - tm.assert_series_equal(result, expected) |
1998 |
| - |
1999 |
| - def test_wrong_order(self): |
2000 |
| - start = np.array(range(5), dtype=np.int64) |
2001 |
| - end = start + 1 |
2002 |
| - end[3] = end[2] |
2003 |
| - start[3] = start[2] - 1 |
2004 |
| - |
2005 |
| - df = DataFrame({"data": start * 1.0, "start": start, "end": end}) |
2006 |
| - |
2007 |
| - r = df.data.rolling(PrescribedWindowIndexer(start, end)) |
2008 |
| - with pytest.raises( |
2009 |
| - ValueError, match="Start/End ordering requirement is violated at index 3" |
2010 |
| - ): |
2011 |
| - r.max() |
0 commit comments