Skip to content

Commit 708cfe6

Browse files
committed
Revert "ERR: Raise NotImplementedError with BaseIndexer and certain rolling operations (pandas-dev#33057)"
This reverts commit 2bf54a8.
1 parent e24c64f commit 708cfe6

File tree

3 files changed

+2
-47
lines changed

3 files changed

+2
-47
lines changed

pandas/core/window/common.py

-24
Original file line numberDiff line numberDiff line change
@@ -324,27 +324,3 @@ def func(arg, window, min_periods=None):
324324
return cfunc(arg, window, min_periods)
325325

326326
return func
327-
328-
329-
def validate_baseindexer_support(func_name: Optional[str]) -> None:
330-
# GH 32865: These functions work correctly with a BaseIndexer subclass
331-
BASEINDEXER_WHITELIST = {
332-
"count",
333-
"min",
334-
"max",
335-
"mean",
336-
"sum",
337-
"median",
338-
"std",
339-
"var",
340-
"skew",
341-
"kurt",
342-
"quantile",
343-
"cov",
344-
"corr",
345-
}
346-
if isinstance(func_name, str) and func_name not in BASEINDEXER_WHITELIST:
347-
raise NotImplementedError(
348-
f"{func_name} is not supported with using a BaseIndexer "
349-
f"subclasses. You can use .apply() with {func_name}."
350-
)

pandas/core/window/rolling.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
calculate_center_offset,
4949
calculate_min_periods,
5050
get_weighted_roll_func,
51-
validate_baseindexer_support,
5251
zsqrt,
5352
)
5453
from pandas.core.window.indexers import (
@@ -393,12 +392,11 @@ def _get_cython_func_type(self, func: str) -> Callable:
393392
return self._get_roll_func(f"{func}_variable")
394393
return partial(self._get_roll_func(f"{func}_fixed"), win=self._get_window())
395394

396-
def _get_window_indexer(self, window: int, func_name: Optional[str]) -> BaseIndexer:
395+
def _get_window_indexer(self, window: int) -> BaseIndexer:
397396
"""
398397
Return an indexer class that will compute the window start and end bounds
399398
"""
400399
if isinstance(self.window, BaseIndexer):
401-
validate_baseindexer_support(func_name)
402400
return self.window
403401
if self.is_freq_type:
404402
return VariableWindowIndexer(index_array=self._on.asi8, window_size=window)
@@ -444,7 +442,7 @@ def _apply(
444442

445443
blocks, obj = self._create_blocks()
446444
block_list = list(blocks)
447-
window_indexer = self._get_window_indexer(window, name)
445+
window_indexer = self._get_window_indexer(window)
448446

449447
results = []
450448
exclude: List[Scalar] = []
@@ -1632,9 +1630,6 @@ def quantile(self, quantile, interpolation="linear", **kwargs):
16321630
"""
16331631

16341632
def cov(self, other=None, pairwise=None, ddof=1, **kwargs):
1635-
if isinstance(self.window, BaseIndexer):
1636-
validate_baseindexer_support("cov")
1637-
16381633
if other is None:
16391634
other = self._selected_obj
16401635
# only default unset
@@ -1781,9 +1776,6 @@ def _get_cov(X, Y):
17811776
)
17821777

17831778
def corr(self, other=None, pairwise=None, **kwargs):
1784-
if isinstance(self.window, BaseIndexer):
1785-
validate_baseindexer_support("corr")
1786-
17871779
if other is None:
17881780
other = self._selected_obj
17891781
# only default unset

pandas/tests/window/test_base_indexer.py

-13
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,6 @@ def get_window_bounds(self, num_values, min_periods, center, closed):
8282
df.rolling(indexer, win_type="boxcar")
8383

8484

85-
@pytest.mark.parametrize("func", [])
86-
def test_notimplemented_functions(func):
87-
# GH 32865
88-
class CustomIndexer(BaseIndexer):
89-
def get_window_bounds(self, num_values, min_periods, center, closed):
90-
return np.array([0, 1]), np.array([1, 2])
91-
92-
df = DataFrame({"values": range(2)})
93-
indexer = CustomIndexer()
94-
with pytest.raises(NotImplementedError, match=f"{func} is not supported"):
95-
getattr(df.rolling(indexer), func)()
96-
97-
9885
@pytest.mark.parametrize("constructor", [Series, DataFrame])
9986
@pytest.mark.parametrize(
10087
"func,np_func,expected,np_kwargs",

0 commit comments

Comments
 (0)