Enable PD in flake8 and ruff
This commit is contained in:
parent
f266adad45
commit
95f08bc96d
12 changed files with 36 additions and 15 deletions
|
|
@ -212,6 +212,7 @@ def lint_code(session: nox.Session) -> None:
|
|||
"flake8-unused-arguments",
|
||||
"isort",
|
||||
"mypy",
|
||||
"pandas-vet",
|
||||
"pep8-naming",
|
||||
"pydoclint[flake8]",
|
||||
"ruff",
|
||||
|
|
|
|||
|
|
@ -111,6 +111,7 @@ dev = [
|
|||
"flake8-todos (>=0.3.1,<0.4.0)",
|
||||
"flake8-unused-arguments (>=0.0.14,<0.1.0)",
|
||||
"mypy (>=2.4.1,<3.0.0)",
|
||||
"pandas-vet (>=2023.8.2)",
|
||||
"pep8-naming (>=0.15.1,<0.16.0)",
|
||||
"pydoclint[flake8] (>=0.12.0,<0.13.0)",
|
||||
"ruff (>=0.17.6,<0.18.0)",
|
||||
|
|
@ -239,6 +240,8 @@ select = [
|
|||
"T00",
|
||||
# flake8-unused-arguments => declared function arguments must be used
|
||||
"U100",
|
||||
# pandas-vet => Idiomatic `pandas`
|
||||
"PD0",
|
||||
# pep8-naming => PEP8 naming conventions
|
||||
"N8",
|
||||
# pydoclint => docstring matches implementation
|
||||
|
|
@ -272,6 +275,8 @@ extend-ignore = [
|
|||
# Comply with black's style.
|
||||
# Source: https://github.com/psf/black/blob/master/docs/compatible_configs.md#flake8
|
||||
"E203", "W503",
|
||||
# Every `.add()` looks like `pandas` to this rule (`ruff` omits it).
|
||||
"PD005",
|
||||
# Let's not do `@pytest.mark.no_cover()` instead of `@pytest.mark.no_cover`.
|
||||
"PT023",
|
||||
# `ruff`'s RET504 does this better, as it allows statements in between.
|
||||
|
|
@ -501,6 +506,8 @@ select = [
|
|||
"ISC",
|
||||
# pep8-naming => PEP8 naming conventions
|
||||
"N",
|
||||
# pandas-vet => Idiomatic `pandas`
|
||||
"PD",
|
||||
# flake8-pytest-style => enforce a consistent style with pytest
|
||||
"PT",
|
||||
# flake8-quotes => use double quotes everywhere
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ def predict(
|
|||
# Re-seed R every time it is used to ensure reproducibility.
|
||||
robjects.r("set.seed(42)")
|
||||
|
||||
if training_ts.isnull().any():
|
||||
if training_ts.isna().any():
|
||||
raise ValueError("`training_ts` must not contain `NaN` values")
|
||||
|
||||
# Copy the data from Python to R.
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ def stl( # noqa:C901,PLR0912,PLR0913,PLR0915
|
|||
"""
|
||||
# Validate all arguments and set default values.
|
||||
|
||||
if time_series.isnull().any():
|
||||
if time_series.isna().any():
|
||||
raise ValueError("`time_series` must not contain `NaN` values")
|
||||
|
||||
if ns % 2 == 0 or ns < 7:
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ def predict(
|
|||
# Re-seed R every time it is used to ensure reproducibility.
|
||||
robjects.r("set.seed(42)")
|
||||
|
||||
if training_ts.isnull().any():
|
||||
if training_ts.isna().any():
|
||||
raise ValueError("`training_ts` must not contain `NaN` values")
|
||||
|
||||
# Copy the data from Python to R.
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ def predict(
|
|||
ValueError: if `training_ts` contains `NaN` values or some predictions
|
||||
could not be made for time steps in the `forecast_interval`
|
||||
"""
|
||||
if training_ts.isnull().any():
|
||||
if training_ts.isna().any():
|
||||
raise ValueError("`training_ts` must not contain `NaN` values")
|
||||
|
||||
extrapolated_ts = pd.Series(index=forecast_interval, dtype=float)
|
||||
|
|
@ -60,7 +60,7 @@ def predict(
|
|||
idx += seasonal_lag
|
||||
|
||||
# Sanity check.
|
||||
if extrapolated_ts.isnull().any(): # pragma: no cover
|
||||
if extrapolated_ts.isna().any(): # pragma: no cover
|
||||
raise ValueError("missing predictions in the `forecast_interval`")
|
||||
|
||||
return pd.DataFrame(
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ class HorizontalETSModel(base.ForecastingModelABC):
|
|||
predictions.insert(loc=0, column="actual", value=actuals_ts)
|
||||
|
||||
# Sanity checks.
|
||||
if predictions.isnull().sum().any(): # pragma: no cover
|
||||
if predictions.isna().sum().any(): # pragma: no cover
|
||||
raise RuntimeError("missing predictions in hets model")
|
||||
if predict_at not in predictions.index: # pragma: no cover
|
||||
raise RuntimeError("missing prediction for `predict_at`")
|
||||
|
|
@ -121,7 +121,7 @@ class HorizontalSMAModel(base.ForecastingModelABC):
|
|||
predictions = pd.DataFrame(
|
||||
data={
|
||||
"actual": actuals_ts,
|
||||
"prediction": training_ts.values.mean(),
|
||||
"prediction": training_ts.to_numpy().mean(),
|
||||
"low80": float("NaN"),
|
||||
"high80": float("NaN"),
|
||||
"low95": float("NaN"),
|
||||
|
|
@ -131,9 +131,7 @@ class HorizontalSMAModel(base.ForecastingModelABC):
|
|||
)
|
||||
|
||||
# Sanity checks.
|
||||
if (
|
||||
predictions[["actual", "prediction"]].isnull().any().any()
|
||||
): # pragma: no cover
|
||||
if predictions[["actual", "prediction"]].isna().any().any(): # pragma: no cover
|
||||
raise RuntimeError("missing predictions in hsma model")
|
||||
if predict_at not in predictions.index: # pragma: no cover
|
||||
raise RuntimeError("missing prediction for `predict_at`")
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ class TrivialModel(base.ForecastingModelABC):
|
|||
)
|
||||
|
||||
# Sanity checks.
|
||||
if predictions["actual"].isnull().any(): # pragma: no cover
|
||||
if predictions["actual"].isna().any(): # pragma: no cover
|
||||
raise RuntimeError("missing actuals in trivial model")
|
||||
if predict_at not in predictions.index: # pragma: no cover
|
||||
raise RuntimeError("missing prediction for `predict_at`")
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ class RealtimeARIMAModel(base.ForecastingModelABC):
|
|||
# Sanity checks.
|
||||
if len(predictions) != 1: # pragma: no cover
|
||||
raise RuntimeError("real-time models should predict exactly one time step")
|
||||
if predictions.isnull().sum().any(): # pragma: no cover
|
||||
if predictions.isna().sum().any(): # pragma: no cover
|
||||
raise RuntimeError("missing predictions in rtarima model")
|
||||
if predict_at not in predictions.index: # pragma: no cover
|
||||
raise RuntimeError("missing prediction for `predict_at`")
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ class VerticalARIMAModel(base.ForecastingModelABC):
|
|||
# Sanity checks.
|
||||
if len(predictions) <= 1: # pragma: no cover
|
||||
raise RuntimeError("vertical models should predict several time steps")
|
||||
if predictions.isnull().sum().any(): # pragma: no cover
|
||||
if predictions.isna().sum().any(): # pragma: no cover
|
||||
raise RuntimeError("missing predictions in varima model")
|
||||
if predict_at not in predictions.index: # pragma: no cover
|
||||
raise RuntimeError("missing prediction for `predict_at`")
|
||||
|
|
|
|||
|
|
@ -131,8 +131,8 @@ class TestGenericForecastingModelProperties:
|
|||
train_horizon=test_config.LONG_TRAIN_HORIZON,
|
||||
)
|
||||
|
||||
assert not result["actual"].isnull().any()
|
||||
assert not result["prediction"].isnull().any()
|
||||
assert not result["actual"].isna().any()
|
||||
assert not result["prediction"].isna().any()
|
||||
|
||||
@pytest.mark.db
|
||||
@pytest.mark.r
|
||||
|
|
|
|||
15
uv.lock
generated
15
uv.lock
generated
|
|
@ -2409,6 +2409,19 @@ wheels = [
|
|||
{ url = "https://files.pythonhosted.org/packages/08/ab/cce173d73200410f06306a89dbbb5f2125bd64f66ca5eff393d53d813288/pandas-3.1.1-cp315-cp315t-win_arm64.whl", hash = "sha256:4e6f9a3036fc6a40c5ba00efe4092a45844212bdb6a63eda4ad5a5a4c8da45eb", size = 10604158, upload-time = "2026-11-04T15:07:59.733Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pandas-vet"
|
||||
version = "2023.8.2"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "attrs" },
|
||||
{ name = "flake8" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/f5/57/2c8350ff48cece1f6009012a0f42413e9e6d5ca54bec7f3b5726b6e33e1b/pandas_vet-2023.8.2.tar.gz", hash = "sha256:ee6b80b40f5a74de41c29393e4dce373447b363faaa3e0677e4f36799ea865c3", size = 9029, upload-time = "2023-08-11T15:09:03.945Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/17/dd/128ade78c67d4ac1a6202f320112aaa7934eaf8f7b0d861517e7c960dd3f/pandas_vet-2023.8.2-py3-none-any.whl", hash = "sha256:761c07b4479f24fc507465047111c7d21374ec678b7aba58e454fd5d3f8055fe", size = 7396, upload-time = "2023-08-11T15:09:04.842Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pandocfilters"
|
||||
version = "1.5.1"
|
||||
|
|
@ -3846,6 +3859,7 @@ dev = [
|
|||
{ name = "isort" },
|
||||
{ name = "mypy" },
|
||||
{ name = "nox" },
|
||||
{ name = "pandas-vet" },
|
||||
{ name = "pep8-naming" },
|
||||
{ name = "pre-commit" },
|
||||
{ name = "pydoclint", extra = ["flake8"] },
|
||||
|
|
@ -3916,6 +3930,7 @@ dev = [
|
|||
{ name = "isort", specifier = ">=9.0.2,<10.0.0" },
|
||||
{ name = "mypy", specifier = ">=2.4.1,<3.0.0" },
|
||||
{ name = "nox", specifier = ">=2026.10.20" },
|
||||
{ name = "pandas-vet", specifier = ">=2023.8.2" },
|
||||
{ name = "pep8-naming", specifier = ">=0.15.1,<0.16.0" },
|
||||
{ name = "pre-commit", specifier = ">=4.7.0,<5.0.0" },
|
||||
{ name = "pydoclint", extras = ["flake8"], specifier = ">=0.12.0,<0.13.0" },
|
||||
|
|
|
|||
Loading…
Reference in a new issue