Skip to content

Commit 3f69d62

Browse files
mroeschkejreback
authored andcommitted
REF: Create _lib/window directory (#29817)
1 parent d55258f commit 3f69d62

File tree

6 files changed

+25
-46
lines changed

6 files changed

+25
-46
lines changed

pandas/_libs/window/__init__.py

Whitespace-only changes.
File renamed without changes.

pandas/_libs/window_indexer.pyx pandas/_libs/window/indexers.pyx

+5-30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# cython: boundscheck=False, wraparound=False, cdivision=True
22

3+
from typing import Tuple
4+
35
import numpy as np
46
from numpy cimport ndarray, int64_t
57

@@ -8,33 +10,6 @@ from numpy cimport ndarray, int64_t
810
# These define start/end indexers to compute offsets
911

1012

11-
class MockFixedWindowIndexer:
12-
"""
13-
14-
We are just checking parameters of the indexer,
15-
and returning a consistent API with fixed/variable
16-
indexers.
17-
18-
Parameters
19-
----------
20-
values: ndarray
21-
values data array
22-
win: int64_t
23-
window size
24-
index: object
25-
index of the values
26-
closed: string
27-
closed behavior
28-
"""
29-
def __init__(self, ndarray values, int64_t win, object closed, object index=None):
30-
31-
self.start = np.empty(0, dtype='int64')
32-
self.end = np.empty(0, dtype='int64')
33-
34-
def get_window_bounds(self):
35-
return self.start, self.end
36-
37-
3813
class FixedWindowIndexer:
3914
"""
4015
create a fixed length window indexer object
@@ -66,7 +41,7 @@ class FixedWindowIndexer:
6641
end_e = start_e + win
6742
self.end = np.concatenate([end_s, end_e])[:N]
6843

69-
def get_window_bounds(self):
44+
def get_window_bounds(self) -> Tuple[np.ndarray, np.ndarray]:
7045
return self.start, self.end
7146

7247

@@ -108,7 +83,7 @@ class VariableWindowIndexer:
10883

10984
@staticmethod
11085
def build(const int64_t[:] index, int64_t win, bint left_closed,
111-
bint right_closed, int64_t N):
86+
bint right_closed, int64_t N) -> Tuple[np.ndarray, np.ndarray]:
11287

11388
cdef:
11489
ndarray[int64_t] start, end
@@ -161,5 +136,5 @@ class VariableWindowIndexer:
161136
end[i] -= 1
162137
return start, end
163138

164-
def get_window_bounds(self):
139+
def get_window_bounds(self) -> Tuple[np.ndarray, np.ndarray]:
165140
return self.start, self.end

pandas/core/window/ewm.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import numpy as np
44

5-
import pandas._libs.window as libwindow
5+
import pandas._libs.window.aggregations as window_aggregations
66
from pandas.compat.numpy import function as nv
77
from pandas.util._decorators import Appender, Substitution
88

@@ -228,11 +228,11 @@ def _apply(self, func, **kwargs):
228228

229229
# if we have a string function name, wrap it
230230
if isinstance(func, str):
231-
cfunc = getattr(libwindow, func, None)
231+
cfunc = getattr(window_aggregations, func, None)
232232
if cfunc is None:
233233
raise ValueError(
234234
"we do not support this function "
235-
"in libwindow.{func}".format(func=func)
235+
"in window_aggregations.{func}".format(func=func)
236236
)
237237

238238
def func(arg):
@@ -284,7 +284,7 @@ def var(self, bias=False, *args, **kwargs):
284284
nv.validate_window_func("var", args, kwargs)
285285

286286
def f(arg):
287-
return libwindow.ewmcov(
287+
return window_aggregations.ewmcov(
288288
arg,
289289
arg,
290290
self.com,
@@ -328,7 +328,7 @@ def cov(self, other=None, pairwise=None, bias=False, **kwargs):
328328
def _get_cov(X, Y):
329329
X = self._shallow_copy(X)
330330
Y = self._shallow_copy(Y)
331-
cov = libwindow.ewmcov(
331+
cov = window_aggregations.ewmcov(
332332
X._prep_values(),
333333
Y._prep_values(),
334334
self.com,
@@ -375,7 +375,7 @@ def _get_corr(X, Y):
375375
Y = self._shallow_copy(Y)
376376

377377
def _cov(x, y):
378-
return libwindow.ewmcov(
378+
return window_aggregations.ewmcov(
379379
x,
380380
y,
381381
self.com,

pandas/core/window/rolling.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
import numpy as np
1212

13-
import pandas._libs.window as libwindow
14-
import pandas._libs.window_indexer as libwindow_indexer
13+
import pandas._libs.window.aggregations as window_aggregations
14+
import pandas._libs.window.indexers as window_indexers
1515
from pandas.compat._optional import import_optional_dependency
1616
from pandas.compat.numpy import function as nv
1717
from pandas.util._decorators import Appender, Substitution, cache_readonly
@@ -381,11 +381,11 @@ def _get_roll_func(self, func_name: str) -> Callable:
381381
-------
382382
func : callable
383383
"""
384-
window_func = getattr(libwindow, func_name, None)
384+
window_func = getattr(window_aggregations, func_name, None)
385385
if window_func is None:
386386
raise ValueError(
387387
"we do not support this function "
388-
"in libwindow.{func_name}".format(func_name=func_name)
388+
"in window_aggregations.{func_name}".format(func_name=func_name)
389389
)
390390
return window_func
391391

@@ -406,8 +406,8 @@ def _get_window_indexer(self):
406406
Return an indexer class that will compute the window start and end bounds
407407
"""
408408
if self.is_freq_type:
409-
return libwindow_indexer.VariableWindowIndexer
410-
return libwindow_indexer.FixedWindowIndexer
409+
return window_indexers.VariableWindowIndexer
410+
return window_indexers.FixedWindowIndexer
411411

412412
def _apply(
413413
self,

setup.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -344,13 +344,13 @@ class CheckSDist(sdist_class):
344344
"pandas/_libs/tslibs/resolution.pyx",
345345
"pandas/_libs/tslibs/parsing.pyx",
346346
"pandas/_libs/tslibs/tzconversion.pyx",
347-
"pandas/_libs/window_indexer.pyx",
347+
"pandas/_libs/window/indexers.pyx",
348348
"pandas/_libs/writers.pyx",
349349
"pandas/io/sas/sas.pyx",
350350
]
351351

352352
_cpp_pyxfiles = [
353-
"pandas/_libs/window.pyx",
353+
"pandas/_libs/window/aggregations.pyx",
354354
"pandas/io/msgpack/_packer.pyx",
355355
"pandas/io/msgpack/_unpacker.pyx",
356356
]
@@ -683,8 +683,12 @@ def srcpath(name=None, suffix=".pyx", subdir="src"):
683683
"sources": np_datetime_sources,
684684
},
685685
"_libs.testing": {"pyxfile": "_libs/testing"},
686-
"_libs.window": {"pyxfile": "_libs/window", "language": "c++", "suffix": ".cpp"},
687-
"_libs.window_indexer": {"pyxfile": "_libs/window_indexer"},
686+
"_libs.window.aggregations": {
687+
"pyxfile": "_libs/window/aggregations",
688+
"language": "c++",
689+
"suffix": ".cpp"
690+
},
691+
"_libs.window.indexers": {"pyxfile": "_libs/window/indexers"},
688692
"_libs.writers": {"pyxfile": "_libs/writers"},
689693
"io.sas._sas": {"pyxfile": "io/sas/sas"},
690694
"io.msgpack._packer": {

0 commit comments

Comments
 (0)