Skip to content

Commit

Permalink
Merge pull request #745 from bashtage/ruff-clean
Browse files Browse the repository at this point in the history
MAINT: Clean checks
  • Loading branch information
bashtage authored Oct 21, 2024
2 parents e6bfdbe + a65e186 commit 5fe440e
Show file tree
Hide file tree
Showing 17 changed files with 288 additions and 126 deletions.
2 changes: 1 addition & 1 deletion arch/compat/numba.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def wrapper(*args: Any, **kwargs: Any) -> Callable[..., Any]:
return wrapper

# Used as a decorator, e.g., @jit
def wrap(func):
def wrap(func: Callable[..., Any]) -> Callable[..., Any]:
@functools.wraps(func)
def wrapper(*args: Any, **kwargs: Any) -> Callable[..., Any]:
import warnings
Expand Down
2 changes: 1 addition & 1 deletion arch/covariance/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def one_sided_strict(self) -> Float64Array | DataFrame:


@jit(nopython=True)
def _cov_jit(df, k, num_weights, w, x):
def _cov_jit(df: int, k: int, num_weights: int, w: np.ndarray, x: np.ndarray) -> np.ndarray:
oss = np.zeros((k, k))
for i in range(1, num_weights):
oss += w[i] * (x[i:].T @ x[:-i]) / df
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
from random import shuffle
import sys
from typing import Sequence

import colorama
from joblib import Parallel, cpu_count, delayed
Expand All @@ -35,7 +36,7 @@
def block(
rg: Generator,
trend: str,
sample_sizes: list[int],
sample_sizes: Sequence[int],
cross_section_size: int,
simulations: int,
idx: int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,23 +229,23 @@ def fit_pval_model(quantiles: pd.DataFrame | pd.Series) -> PvalueResult:
plt.rc("figure", figsize=(16, 8))
sns.set_style("darkgrid")
pdf = matplotlib.backends.backend_pdf.PdfPages("output.pdf")
for key in quantiles:
temp = quantiles[key]
for quantile_key in quantiles:
temp = quantiles[quantile_key]
y = temp.index.to_numpy()[:, None]
x = temp.to_numpy()
stat = key[0]
stat = quantile_key[0]
if stat in ("z_t", "z_a"):
x = -1 * x
if stat in ("p_u", "p_z"):
y = 1 - y
fig, ax = plt.subplots(1, 1)
plt.plot(x, y)
plt.title(key)
plt.title(", ".join(quantile_key))
pdf.savefig(fig)
if stat in ("p_u", "p_z"):
fig, ax = plt.subplots(1, 1)
plt.plot(np.log(x), y)
plt.title(f"Log {key[0]}, {key[1]}")
plt.title(f"Log {quantile_key[0]}, {quantile_key[1]}")
pdf.savefig(fig)
pdf.close()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def worker(
)
last_print_remaining = remaining
results = results.quantile(QUANTILES)
results.to_hdf(full_path, "results")
results.to_hdf(full_path, key="results")
if os.path.exists(temp_file_name(full_path)):
try:
os.unlink(temp_file_name(full_path))
Expand Down
2 changes: 1 addition & 1 deletion arch/univariate/mean.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def __init__(

self._init_model()

def _scale_changed(self):
def _scale_changed(self) -> None:
"""
Called when the scale has changed. This allows the model
to update any values that are affected by the scale changes,
Expand Down
4 changes: 2 additions & 2 deletions doc/source/images/favicon.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
price = data["Adj Close"]
rets = 100 * price.resample("M").last().pct_change()

l, u = rets.quantile([0.01, 0.99])
bins = np.linspace(l, u, NBINS)
lower, upper = rets.quantile([0.01, 0.99])
bins = np.linspace(lower, upper, NBINS)
fig = plt.figure(frameon=False)
fig.set_size_inches(8, 8)
ax = fig.add_subplot("111")
Expand Down
8 changes: 4 additions & 4 deletions examples/bootstrap_examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
"import seaborn\n",
"\n",
Expand Down Expand Up @@ -51,10 +50,11 @@
"metadata": {},
"outputs": [],
"source": [
"import arch.data.frenchdata\n",
"import numpy as np\n",
"import pandas as pd\n",
"\n",
"import arch.data.frenchdata\n",
"\n",
"ff = arch.data.frenchdata.load()"
]
},
Expand Down Expand Up @@ -654,7 +654,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -668,7 +668,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
5 changes: 2 additions & 3 deletions examples/multiple-comparison_examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
"import seaborn\n",
"\n",
Expand Down Expand Up @@ -527,7 +526,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -541,7 +540,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
6 changes: 3 additions & 3 deletions examples/unitroot_cointegration_examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
"import seaborn\n",
"\n",
Expand Down Expand Up @@ -66,6 +65,7 @@
],
"source": [
"import numpy as np\n",
"\n",
"from arch.data import crude\n",
"\n",
"data = crude.load()\n",
Expand Down Expand Up @@ -815,7 +815,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -829,7 +829,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
37 changes: 18 additions & 19 deletions examples/unitroot_examples.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.11"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
235 changes: 215 additions & 20 deletions examples/univariate_using_fixed_variance.ipynb

Large diffs are not rendered by default.

85 changes: 26 additions & 59 deletions examples/univariate_volatility_forecasting.ipynb

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions examples/univariate_volatility_modeling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,8 @@
],
"source": [
"import numpy as np\n",
"from arch.univariate import GARCH, ConstantMean, SkewStudent\n",
"\n",
"from arch.univariate import ConstantMean, SkewStudent\n",
"\n",
"rs = np.random.RandomState([892380934, 189201902, 129129894, 9890437])\n",
"# Save the initial state to reset later\n",
Expand Down Expand Up @@ -1483,7 +1484,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.11"
"version": "3.12.7"
},
"pycharm": {
"stem_cell": {
Expand Down
5 changes: 2 additions & 3 deletions examples/univariate_volatility_scenarios.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"import numpy as np\n",
"import pandas as pd\n",
"import seaborn as sns\n",
"\n",
"from arch.univariate import GARCH, ConstantMean, Normal\n",
"\n",
"sns.set_style(\"darkgrid\")\n",
Expand Down Expand Up @@ -382,8 +383,6 @@
}
],
"source": [
"import pandas as pd\n",
"\n",
"df = pd.concat(\n",
" [\n",
" forecasts.residual_variance.iloc[-1],\n",
Expand Down Expand Up @@ -530,7 +529,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.11"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ flake8
mypy
ruff
pyupgrade>=3.4.0
jupyterlab-code-formatter

# Documentation
ipython>=7
Expand Down

0 comments on commit 5fe440e

Please sign in to comment.