@@ -25,51 +25,34 @@ def _get_alpha(
25
25
span : float | None = None ,
26
26
halflife : float | None = None ,
27
27
alpha : float | None = None ,
28
- ) -> float :
29
- # pandas defines in terms of com (converting to alpha in the algo)
30
- # so use its function to get a com and then convert to alpha
31
-
32
- com = _get_center_of_mass (com , span , halflife , alpha )
33
- return 1 / (1 + com )
34
-
35
-
36
- def _get_center_of_mass (
37
- comass : float | None ,
38
- span : float | None ,
39
- halflife : float | None ,
40
- alpha : float | None ,
41
28
) -> float :
42
29
"""
43
- Vendored from pandas.core.window.common._get_center_of_mass
44
-
45
- See licenses/PANDAS_LICENSE for the function's license
30
+ Convert com, span, halflife to alpha.
46
31
"""
47
- valid_count = count_not_none (comass , span , halflife , alpha )
32
+ valid_count = count_not_none (com , span , halflife , alpha )
48
33
if valid_count > 1 :
49
- raise ValueError ("comass , span, halflife, and alpha are mutually exclusive" )
34
+ raise ValueError ("com , span, halflife, and alpha are mutually exclusive" )
50
35
51
- # Convert to center of mass; domain checks ensure 0 < alpha <= 1
52
- if comass is not None :
53
- if comass < 0 :
54
- raise ValueError ("comass must satisfy: comass >= 0" )
36
+ # Convert to alpha
37
+ if com is not None :
38
+ if com < 0 :
39
+ raise ValueError ("commust satisfy: com>= 0" )
40
+ return 1 / (com + 1 )
55
41
elif span is not None :
56
42
if span < 1 :
57
43
raise ValueError ("span must satisfy: span >= 1" )
58
- comass = (span - 1 ) / 2.0
44
+ return 2 / (span + 1 )
59
45
elif halflife is not None :
60
46
if halflife <= 0 :
61
47
raise ValueError ("halflife must satisfy: halflife > 0" )
62
- decay = 1 - np .exp (np .log (0.5 ) / halflife )
63
- comass = 1 / decay - 1
48
+ return 1 - np .exp (np .log (0.5 ) / halflife )
64
49
elif alpha is not None :
65
- if alpha <= 0 or alpha > 1 :
50
+ if not 0 < alpha <= 1 :
66
51
raise ValueError ("alpha must satisfy: 0 < alpha <= 1" )
67
- comass = ( 1.0 - alpha ) / alpha
52
+ return alpha
68
53
else :
69
54
raise ValueError ("Must pass one of comass, span, halflife, or alpha" )
70
55
71
- return float (comass )
72
-
73
56
74
57
class RollingExp (Generic [T_DataWithCoords ]):
75
58
"""
0 commit comments