Skip to content

Commit

Permalink
Fix lints.
Browse files Browse the repository at this point in the history
  • Loading branch information
shunping committed Mar 8, 2025
1 parent fc5ea49 commit 5901a43
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion sdks/python/apache_beam/ml/anomaly/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def learn_one(self, x: beam.Row) -> None:
raise NotImplementedError

@abc.abstractmethod
def score_one(self, x: beam.Row) -> float:
def score_one(self, x: beam.Row) -> Optional[float]:
"""Scores a single data instance for anomalies.
Args:
Expand Down
2 changes: 2 additions & 0 deletions sdks/python/apache_beam/ml/anomaly/detectors/robust_zscore.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from apache_beam.ml.anomaly.univariate.mad import MadTracker


# pylint: disable=line-too-long
@specifiable
class RobustZScore(AnomalyDetector):
"""Robust Z-Score anomaly detector.
Expand Down Expand Up @@ -62,6 +63,7 @@ class RobustZScore(AnomalyDetector):
.. [#] Yilmaz, Selim & Kozat, Suleyman. (2020). PySAD: A Streaming Anomaly Detection Framework in Python. 10.48550/arXiv.2009.02572.
.. [#] Zhao, Y., Nasrullah, Z. and Li, Z.. (2019). PyOD: A Python Toolbox for Scalable Outlier Detection. Journal of machine learning research (JMLR), 20(96), pp.1-7.
"""
# pylint: enable=line-too-long
SCALE_FACTOR = 0.6745

def __init__(self, mad_tracker: Optional[MadTracker] = None, **kwargs):
Expand Down
3 changes: 3 additions & 0 deletions sdks/python/apache_beam/ml/anomaly/detectors/zscore.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
DEFAULT_WINDOW_SIZE = 1000


# pylint: disable=line-too-long
@specifiable
class ZScore(AnomalyDetector):
"""Z-Score anomaly detector.
Expand Down Expand Up @@ -66,6 +67,8 @@ class ZScore(AnomalyDetector):
.. [#] Yilmaz, Selim & Kozat, Suleyman. (2020). PySAD: A Streaming Anomaly Detection Framework in Python. 10.48550/arXiv.2009.02572.
.. [#] Jacob Montiel, Max Halford, Saulo Martiello Mastelini, Geoffrey Bolmier, Raphaël Sourty, et al.. (2021). River: machine learning for streaming data in Python. Journal of Machine Learning Research, 2021, 22, pp.1-8.
"""

# pylint: enable=line-too-long
def __init__(
self,
sub_stat_tracker: Optional[MeanTracker] = None,
Expand Down
4 changes: 2 additions & 2 deletions sdks/python/apache_beam/ml/anomaly/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class _BaseThresholdDoFn(beam.DoFn):
"""
def __init__(self, threshold_fn_spec: Spec):
self._threshold_fn_spec = threshold_fn_spec
self._threshold_fn: Optional[ThresholdFn] = None
self._threshold_fn: ThresholdFn

def _apply_threshold_to_predictions(
self, result: AnomalyResult) -> AnomalyResult:
Expand Down Expand Up @@ -300,7 +300,7 @@ def expand(
input
| beam.ParDo(_StatelessThresholdDoFn(self._threshold_fn.to_spec())))
else:
ret: Any = input
ret = input

return ret

Expand Down
4 changes: 2 additions & 2 deletions sdks/python/apache_beam/ml/anomaly/transforms_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def _prediction_is_equal_to(a: AnomalyPrediction, b: AnomalyPrediction):
return False

if a.score != b.score:
if not (a is not None and b is not None and math.isnan(a.score) and
math.isnan(b.score)):
if not (a.score is not None and b.score is not None and
math.isnan(a.score) and math.isnan(b.score)):
return False

if a.label != b.label:
Expand Down

0 comments on commit 5901a43

Please sign in to comment.