zhengruifeng commented on code in PR #36063:
URL: https://github.com/apache/spark/pull/36063#discussion_r845759689
##########
python/pyspark/pandas/window.py:
##########
@@ -1749,6 +1752,177 @@ def var(self) -> FrameLike:
return super().var()
+class ExponentialMovingLike(Generic[FrameLike], metaclass=ABCMeta):
+ def __init__(
+ self,
+ window: WindowSpec,
+ com: Optional[float] = None,
+ span: Optional[float] = None,
+ halflife: Optional[float] = None,
+ alpha: Optional[float] = None,
+ min_periods: Optional[int] = None,
+ ):
+ if (min_periods is not None) and (min_periods < 0):
+ raise ValueError("min_periods must be >= 0")
+ if min_periods is None:
+ min_periods = 0
+
+ self._window = window
+ # This unbounded Window is later used to handle 'min_periods' for now.
+ self._unbounded_window =
Window.orderBy(NATURAL_ORDER_COLUMN_NAME).rowsBetween(
+ Window.unboundedPreceding, Window.currentRow
+ )
+ self._min_periods = min_periods
+
+ opt_count = 0
+
+ if com is not None:
+ if com < 0:
+ raise ValueError("com must be >= 0")
+ self._alpha = 1.0 / (1 + com)
+ opt_count += 1
+
+ if span is not None:
+ if span < 1:
+ raise ValueError("span must be >= 1")
+ self._alpha = 2.0 / (1 + span)
+ opt_count += 1
+
+ if halflife is not None:
+ if halflife <= 0:
+ raise ValueError("halflife must be > 0")
+ self._alpha = 1.0 - np.exp(-np.log(2) / halflife)
+ opt_count += 1
+
+ if alpha is not None:
+ if alpha <= 0 or alpha > 1:
+ raise ValueError("alpha must be in (0, 1]")
+ self._alpha = alpha
+ opt_count += 1
+
+ if opt_count == 0:
+ raise ValueError("Must pass one of comass, span, halflife, or
alpha")
Review Comment:
yep. I copied this error msg from pandas, it should be a typo in pandas.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]