Skip to content

Commit

Permalink
re-enable Kats linting
Browse files Browse the repository at this point in the history
Summary: Apply `pyfmt` to Kats.

Reviewed By: iamxiaodong

Differential Revision: D38137035

fbshipit-source-id: 876881d16c8a6b9fd1067f2f0abf9a593aeef941
  • Loading branch information
michaelbrundage authored and facebook-github-bot committed Jul 28, 2022
1 parent e760471 commit 573b765
Show file tree
Hide file tree
Showing 88 changed files with 1,787 additions and 693 deletions.
20 changes: 17 additions & 3 deletions kats/compat/sklearn.py
Expand Up @@ -21,7 +21,13 @@ def mean_squared_error(
squared: bool = True,
) -> float:
# sklearn >= 1.0 expects args beyond the first two to be passed as named kwargs
return mse(y_true, y_pred, sample_weight=sample_weight, multioutput=multioutput, squared=squared)
return mse(
y_true,
y_pred,
sample_weight=sample_weight,
multioutput=multioutput,
squared=squared,
)


def mean_squared_log_error(
Expand All @@ -32,11 +38,19 @@ def mean_squared_log_error(
squared: bool = True,
) -> float:
if version <= "0.24":
result = msle(y_true, y_pred, sample_weight=sample_weight, multioutput=multioutput)
result = msle(
y_true, y_pred, sample_weight=sample_weight, multioutput=multioutput
)
if not squared:
result = np.sqrt(result)
else:
# sklearn >= 1.0 expects args beyond the first two to be passed as named kwargs
# pyre-ignore
result = msle(y_true, y_pred, sample_weight=sample_weight, multioutput=multioutput, squared=squared)
result = msle(
y_true,
y_pred,
sample_weight=sample_weight,
multioutput=multioutput,
squared=squared,
)
return result
3 changes: 1 addition & 2 deletions kats/compat/statsmodels.py
Expand Up @@ -38,7 +38,6 @@ def __init__(self, results: holtwinters.HoltWintersResults) -> None:
results.level,
results.trend,
results.season,

results.params_formatted,
results.resid,
results.k,
Expand Down Expand Up @@ -69,7 +68,7 @@ def __init__(
initial_trend: Optional[float] = None,
missing: str = "none",
seasonal_periods: Optional[int] = None,
use_boxcox: bool = False
use_boxcox: bool = False,
) -> None:
if version < "0.12":
self._use_boxcox = use_boxcox
Expand Down
4 changes: 2 additions & 2 deletions kats/data/utils.py
Expand Up @@ -22,7 +22,7 @@
import os
import pkgutil
import sys
from typing import Union, overload
from typing import overload, Union

if sys.version_info >= (3, 8):
from typing import Literal
Expand All @@ -33,7 +33,7 @@
from kats.consts import TimeSeriesData


def load_data(file_name: str, reset_columns:bool=False) -> pd.DataFrame:
def load_data(file_name: str, reset_columns: bool = False) -> pd.DataFrame:
"""load data for tests and tutorial notebooks"""
ROOT = "kats"
if "kats" in os.getcwd().lower():
Expand Down
12 changes: 7 additions & 5 deletions kats/detectors/bocpd.py
Expand Up @@ -16,24 +16,24 @@
from enum import Enum
from typing import (
Any,
Callable,
cast,
Dict,
List,
Optional,
Sequence,
Tuple,
Type,
Union,
cast,
Callable,
)

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from kats.consts import TimeSeriesChangePoint, TimeSeriesData, SearchMethodEnum
from kats.consts import SearchMethodEnum, TimeSeriesChangePoint, TimeSeriesData
from kats.detectors.detector import Detector
from scipy.special import logsumexp # @manual
from scipy.stats import invgamma, linregress, norm, nbinom # @manual
from scipy.stats import invgamma, linregress, nbinom, norm # @manual

try:
import kats.utils.time_series_parameter_tuning as tpt
Expand Down Expand Up @@ -758,7 +758,9 @@ def __init__(
self.P = 1
self._ts_slice = 0
data_df = self.data.to_dataframe()
self._ts_names = [x for x in data_df.columns if x != self.data.time_col_name]
self._ts_names = [
x for x in data_df.columns if x != self.data.time_col_name
]

self.data_values = np.expand_dims(data.value.values, axis=1)

Expand Down
7 changes: 6 additions & 1 deletion kats/detectors/bocpd_model.py
Expand Up @@ -104,7 +104,12 @@ def fit_predict(
if historical_data is not None:
historical_data.extend(data, validate=False)
data = TimeSeriesData(
pd.DataFrame({"time": list(historical_data.time), "value": list(historical_data.value)})
pd.DataFrame(
{
"time": list(historical_data.time),
"value": list(historical_data.value),
}
)
)

bocpd_model = BOCPDetector(data=data)
Expand Down

0 comments on commit 573b765

Please sign in to comment.