7
7
"""
8
8
from __future__ import division
9
9
10
- import warnings
11
- import numpy as np
12
10
from collections import defaultdict
13
11
from datetime import timedelta
12
+ from textwrap import dedent
13
+ import warnings
14
+
15
+ import numpy as np
16
+
17
+ import pandas ._libs .window as libwindow
18
+ import pandas .compat as compat
19
+ from pandas .compat .numpy import function as nv
20
+ from pandas .util ._decorators import Appender , Substitution , cache_readonly
14
21
15
- from pandas .core .dtypes .generic import (
16
- ABCSeries ,
17
- ABCDataFrame ,
18
- ABCDatetimeIndex ,
19
- ABCTimedeltaIndex ,
20
- ABCPeriodIndex ,
21
- ABCDateOffset )
22
22
from pandas .core .dtypes .common import (
23
- is_integer ,
24
- is_bool ,
25
- is_float_dtype ,
26
- is_integer_dtype ,
27
- needs_i8_conversion ,
28
- is_timedelta64_dtype ,
29
- is_list_like ,
30
- ensure_float64 ,
31
- is_scalar )
23
+ ensure_float64 , is_bool , is_float_dtype , is_integer , is_integer_dtype ,
24
+ is_list_like , is_scalar , is_timedelta64_dtype , needs_i8_conversion )
25
+ from pandas .core .dtypes .generic import (
26
+ ABCDataFrame , ABCDateOffset , ABCDatetimeIndex , ABCPeriodIndex , ABCSeries ,
27
+ ABCTimedeltaIndex )
32
28
33
29
from pandas .core .base import PandasObject , SelectionMixin
34
- from pandas .core .groupby .base import GroupByMixin
35
30
import pandas .core .common as com
36
- import pandas ._libs .window as _window
37
-
38
- from pandas import compat
39
- from pandas .compat .numpy import function as nv
40
- from pandas .util ._decorators import (Substitution , Appender ,
41
- cache_readonly )
42
31
from pandas .core .generic import _shared_docs
43
- from textwrap import dedent
44
-
32
+ from pandas .core .groupby .base import GroupByMixin
45
33
46
34
_shared_docs = dict (** _shared_docs )
47
35
_doc_template = """
@@ -688,10 +676,10 @@ def _apply_window(self, mean=True, **kwargs):
688
676
689
677
def f (arg , * args , ** kwargs ):
690
678
minp = _use_window (self .min_periods , len (window ))
691
- return _window .roll_window (np .concatenate ((arg ,
692
- additional_nans ))
693
- if center else arg , window , minp ,
694
- avg = mean )
679
+ return libwindow .roll_window (np .concatenate ((arg ,
680
+ additional_nans ))
681
+ if center else arg , window , minp ,
682
+ avg = mean )
695
683
696
684
result = np .apply_along_axis (f , self .axis , values )
697
685
@@ -848,10 +836,10 @@ def _apply(self, func, name=None, window=None, center=None,
848
836
849
837
# if we have a string function name, wrap it
850
838
if isinstance (func , compat .string_types ):
851
- cfunc = getattr (_window , func , None )
839
+ cfunc = getattr (libwindow , func , None )
852
840
if cfunc is None :
853
841
raise ValueError ("we do not support this function "
854
- "in _window.{0 }" .format (func ))
842
+ "in libwindow.{func }" .format (func = func ))
855
843
856
844
def func (arg , window , min_periods = None , closed = None ):
857
845
minp = check_minp (min_periods , window )
@@ -995,7 +983,7 @@ def f(arg, window, min_periods, closed):
995
983
minp = _use_window (min_periods , window )
996
984
if not raw :
997
985
arg = Series (arg , index = self .obj .index )
998
- return _window .roll_generic (
986
+ return libwindow .roll_generic (
999
987
arg , window , minp , indexi ,
1000
988
closed , offset , func , raw , args , kwargs )
1001
989
@@ -1160,8 +1148,8 @@ def std(self, ddof=1, *args, **kwargs):
1160
1148
1161
1149
def f (arg , * args , ** kwargs ):
1162
1150
minp = _require_min_periods (1 )(self .min_periods , window )
1163
- return _zsqrt (_window .roll_var (arg , window , minp , indexi ,
1164
- self .closed , ddof ))
1151
+ return _zsqrt (libwindow .roll_var (arg , window , minp , indexi ,
1152
+ self .closed , ddof ))
1165
1153
1166
1154
return self ._apply (f , 'std' , check_minp = _require_min_periods (1 ),
1167
1155
ddof = ddof , ** kwargs )
@@ -1331,15 +1319,15 @@ def quantile(self, quantile, interpolation='linear', **kwargs):
1331
1319
def f (arg , * args , ** kwargs ):
1332
1320
minp = _use_window (self .min_periods , window )
1333
1321
if quantile == 1.0 :
1334
- return _window .roll_max (arg , window , minp , indexi ,
1335
- self .closed )
1322
+ return libwindow .roll_max (arg , window , minp , indexi ,
1323
+ self .closed )
1336
1324
elif quantile == 0.0 :
1337
- return _window .roll_min (arg , window , minp , indexi ,
1338
- self .closed )
1325
+ return libwindow .roll_min (arg , window , minp , indexi ,
1326
+ self .closed )
1339
1327
else :
1340
- return _window .roll_quantile (arg , window , minp , indexi ,
1341
- self .closed , quantile ,
1342
- interpolation )
1328
+ return libwindow .roll_quantile (arg , window , minp , indexi ,
1329
+ self .closed , quantile ,
1330
+ interpolation )
1343
1331
1344
1332
return self ._apply (f , 'quantile' , quantile = quantile ,
1345
1333
** kwargs )
@@ -2262,10 +2250,10 @@ def _apply(self, func, **kwargs):
2262
2250
2263
2251
# if we have a string function name, wrap it
2264
2252
if isinstance (func , compat .string_types ):
2265
- cfunc = getattr (_window , func , None )
2253
+ cfunc = getattr (libwindow , func , None )
2266
2254
if cfunc is None :
2267
2255
raise ValueError ("we do not support this function "
2268
- "in _window.{0 }" .format (func ))
2256
+ "in libwindow.{func }" .format (func = func ))
2269
2257
2270
2258
def func (arg ):
2271
2259
return cfunc (arg , self .com , int (self .adjust ),
@@ -2300,9 +2288,9 @@ def var(self, bias=False, *args, **kwargs):
2300
2288
nv .validate_window_func ('var' , args , kwargs )
2301
2289
2302
2290
def f (arg ):
2303
- return _window .ewmcov (arg , arg , self .com , int (self .adjust ),
2304
- int (self .ignore_na ), int (self .min_periods ),
2305
- int (bias ))
2291
+ return libwindow .ewmcov (arg , arg , self .com , int (self .adjust ),
2292
+ int (self .ignore_na ), int (self .min_periods ),
2293
+ int (bias ))
2306
2294
2307
2295
return self ._apply (f , ** kwargs )
2308
2296
@@ -2320,9 +2308,10 @@ def cov(self, other=None, pairwise=None, bias=False, **kwargs):
2320
2308
def _get_cov (X , Y ):
2321
2309
X = self ._shallow_copy (X )
2322
2310
Y = self ._shallow_copy (Y )
2323
- cov = _window .ewmcov (X ._prep_values (), Y ._prep_values (), self .com ,
2324
- int (self .adjust ), int (self .ignore_na ),
2325
- int (self .min_periods ), int (bias ))
2311
+ cov = libwindow .ewmcov (X ._prep_values (), Y ._prep_values (),
2312
+ self .com , int (self .adjust ),
2313
+ int (self .ignore_na ), int (self .min_periods ),
2314
+ int (bias ))
2326
2315
return X ._wrap_result (cov )
2327
2316
2328
2317
return _flex_binary_moment (self ._selected_obj , other ._selected_obj ,
@@ -2344,10 +2333,10 @@ def _get_corr(X, Y):
2344
2333
Y = self ._shallow_copy (Y )
2345
2334
2346
2335
def _cov (x , y ):
2347
- return _window .ewmcov (x , y , self .com , int (self .adjust ),
2348
- int (self .ignore_na ),
2349
- int (self .min_periods ),
2350
- 1 )
2336
+ return libwindow .ewmcov (x , y , self .com , int (self .adjust ),
2337
+ int (self .ignore_na ),
2338
+ int (self .min_periods ),
2339
+ 1 )
2351
2340
2352
2341
x_values = X ._prep_values ()
2353
2342
y_values = Y ._prep_values ()
0 commit comments