Skip to content

Commit b66e799

Browse files
committed
MAINT: Clean checks
CLean checks found with ruff Improve typing support
1 parent 07d817d commit b66e799

17 files changed

+265
-71
lines changed

arch/compat/numba.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def wrapper(*args: Any, **kwargs: Any) -> Callable[..., Any]:
3838
return wrapper
3939

4040
# Used as a decorator, e.g., @jit
41-
def wrap(func):
41+
def wrap(func: Callable[..., Any]) -> Callable[..., Any]:
4242
@functools.wraps(func)
4343
def wrapper(*args: Any, **kwargs: Any) -> Callable[..., Any]:
4444
import warnings

arch/covariance/kernel.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def one_sided_strict(self) -> Float64Array | DataFrame:
139139

140140

141141
@jit(nopython=True)
142-
def _cov_jit(df, k, num_weights, w, x):
142+
def _cov_jit(df: int, k: int, num_weights: int, w: np.ndarray, x: np.ndarray) -> np.ndarray:
143143
oss = np.zeros((k, k))
144144
for i in range(1, num_weights):
145145
oss += w[i] * (x[i:].T @ x[:-i]) / df

arch/unitroot/critical_values/simulation/engle_granger_simulation.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import os
1010
from random import shuffle
1111
import sys
12+
from typing import Sequence
1213

1314
import colorama
1415
from joblib import Parallel, cpu_count, delayed
@@ -35,7 +36,7 @@
3536
def block(
3637
rg: Generator,
3738
trend: str,
38-
sample_sizes: list[int],
39+
sample_sizes: Sequence[int],
3940
cross_section_size: int,
4041
simulations: int,
4142
idx: int,

arch/unitroot/critical_values/simulation/phillips-ouliaris-simulation-process.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -229,23 +229,23 @@ def fit_pval_model(quantiles: pd.DataFrame | pd.Series) -> PvalueResult:
229229
plt.rc("figure", figsize=(16, 8))
230230
sns.set_style("darkgrid")
231231
pdf = matplotlib.backends.backend_pdf.PdfPages("output.pdf")
232-
for key in quantiles:
233-
temp = quantiles[key]
232+
for quantile_key in quantiles:
233+
temp = quantiles[quantile_key]
234234
y = temp.index.to_numpy()[:, None]
235235
x = temp.to_numpy()
236-
stat = key[0]
236+
stat = quantile_key[0]
237237
if stat in ("z_t", "z_a"):
238238
x = -1 * x
239239
if stat in ("p_u", "p_z"):
240240
y = 1 - y
241241
fig, ax = plt.subplots(1, 1)
242242
plt.plot(x, y)
243-
plt.title(key)
243+
plt.title(", ".join(quantile_key))
244244
pdf.savefig(fig)
245245
if stat in ("p_u", "p_z"):
246246
fig, ax = plt.subplots(1, 1)
247247
plt.plot(np.log(x), y)
248-
plt.title(f"Log {key[0]}, {key[1]}")
248+
plt.title(f"Log {quantile_key[0]}, {quantile_key[1]}")
249249
pdf.savefig(fig)
250250
pdf.close()
251251

arch/unitroot/critical_values/simulation/phillips-ouliaris-simulation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def worker(
314314
)
315315
last_print_remaining = remaining
316316
results = results.quantile(QUANTILES)
317-
results.to_hdf(full_path, "results")
317+
results.to_hdf(full_path, key="results")
318318
if os.path.exists(temp_file_name(full_path)):
319319
try:
320320
os.unlink(temp_file_name(full_path))

arch/univariate/mean.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def __init__(
309309

310310
self._init_model()
311311

312-
def _scale_changed(self):
312+
def _scale_changed(self) -> None:
313313
"""
314314
Called when the scale has changed. This allows the model
315315
to update any values that are affected by the scale changes,

doc/source/images/favicon.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
price = data["Adj Close"]
1919
rets = 100 * price.resample("M").last().pct_change()
2020

21-
l, u = rets.quantile([0.01, 0.99])
22-
bins = np.linspace(l, u, NBINS)
21+
lower, upper = rets.quantile([0.01, 0.99])
22+
bins = np.linspace(lower, upper, NBINS)
2323
fig = plt.figure(frameon=False)
2424
fig.set_size_inches(8, 8)
2525
ax = fig.add_subplot("111")

examples/bootstrap_examples.ipynb

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"metadata": {},
2121
"outputs": [],
2222
"source": [
23-
"%matplotlib inline\n",
2423
"import matplotlib.pyplot as plt\n",
2524
"import seaborn\n",
2625
"\n",
@@ -51,10 +50,11 @@
5150
"metadata": {},
5251
"outputs": [],
5352
"source": [
54-
"import arch.data.frenchdata\n",
5553
"import numpy as np\n",
5654
"import pandas as pd\n",
5755
"\n",
56+
"import arch.data.frenchdata\n",
57+
"\n",
5858
"ff = arch.data.frenchdata.load()"
5959
]
6060
},
@@ -654,7 +654,7 @@
654654
],
655655
"metadata": {
656656
"kernelspec": {
657-
"display_name": "Python 3",
657+
"display_name": "Python 3 (ipykernel)",
658658
"language": "python",
659659
"name": "python3"
660660
},
@@ -668,7 +668,7 @@
668668
"name": "python",
669669
"nbconvert_exporter": "python",
670670
"pygments_lexer": "ipython3",
671-
"version": "3.8.8"
671+
"version": "3.12.7"
672672
}
673673
},
674674
"nbformat": 4,

examples/multiple-comparison_examples.ipynb

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"metadata": {},
2121
"outputs": [],
2222
"source": [
23-
"%matplotlib inline\n",
2423
"import matplotlib.pyplot as plt\n",
2524
"import seaborn\n",
2625
"\n",
@@ -527,7 +526,7 @@
527526
],
528527
"metadata": {
529528
"kernelspec": {
530-
"display_name": "Python 3",
529+
"display_name": "Python 3 (ipykernel)",
531530
"language": "python",
532531
"name": "python3"
533532
},
@@ -541,7 +540,7 @@
541540
"name": "python",
542541
"nbconvert_exporter": "python",
543542
"pygments_lexer": "ipython3",
544-
"version": "3.8.8"
543+
"version": "3.12.7"
545544
}
546545
},
547546
"nbformat": 4,

examples/unitroot_cointegration_examples.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
},
2525
"outputs": [],
2626
"source": [
27-
"%matplotlib inline\n",
2827
"import matplotlib.pyplot as plt\n",
2928
"import seaborn\n",
3029
"\n",
@@ -66,6 +65,7 @@
6665
],
6766
"source": [
6867
"import numpy as np\n",
68+
"\n",
6969
"from arch.data import crude\n",
7070
"\n",
7171
"data = crude.load()\n",
@@ -815,7 +815,7 @@
815815
],
816816
"metadata": {
817817
"kernelspec": {
818-
"display_name": "Python 3",
818+
"display_name": "Python 3 (ipykernel)",
819819
"language": "python",
820820
"name": "python3"
821821
},
@@ -829,7 +829,7 @@
829829
"name": "python",
830830
"nbconvert_exporter": "python",
831831
"pygments_lexer": "ipython3",
832-
"version": "3.8.8"
832+
"version": "3.12.7"
833833
}
834834
},
835835
"nbformat": 4,

examples/unitroot_examples.ipynb

+18-19
Large diffs are not rendered by default.

examples/univariate_forecasting_with_exogenous_variables.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@
980980
"name": "python",
981981
"nbconvert_exporter": "python",
982982
"pygments_lexer": "ipython3",
983-
"version": "3.10.11"
983+
"version": "3.12.7"
984984
}
985985
},
986986
"nbformat": 4,

examples/univariate_using_fixed_variance.ipynb

+215-20
Large diffs are not rendered by default.

examples/univariate_volatility_forecasting.ipynb

+3-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"metadata": {},
2121
"outputs": [],
2222
"source": [
23-
"%matplotlib inline\n",
2423
"import matplotlib.pyplot as plt\n",
2524
"import seaborn as sns\n",
2625
"\n",
@@ -45,12 +44,12 @@
4544
"metadata": {},
4645
"outputs": [],
4746
"source": [
48-
"import datetime as dt\n",
4947
"import sys\n",
5048
"\n",
51-
"import arch.data.sp500\n",
5249
"import numpy as np\n",
5350
"import pandas as pd\n",
51+
"\n",
52+
"import arch.data.sp500\n",
5453
"from arch import arch_model\n",
5554
"\n",
5655
"data = arch.data.sp500.load()\n",
@@ -744,7 +743,7 @@
744743
"name": "python",
745744
"nbconvert_exporter": "python",
746745
"pygments_lexer": "ipython3",
747-
"version": "3.10.11"
746+
"version": "3.12.7"
748747
}
749748
},
750749
"nbformat": 4,

examples/univariate_volatility_modeling.ipynb

+3-2
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,8 @@
13491349
],
13501350
"source": [
13511351
"import numpy as np\n",
1352-
"from arch.univariate import GARCH, ConstantMean, SkewStudent\n",
1352+
"\n",
1353+
"from arch.univariate import ConstantMean, SkewStudent\n",
13531354
"\n",
13541355
"rs = np.random.RandomState([892380934, 189201902, 129129894, 9890437])\n",
13551356
"# Save the initial state to reset later\n",
@@ -1483,7 +1484,7 @@
14831484
"name": "python",
14841485
"nbconvert_exporter": "python",
14851486
"pygments_lexer": "ipython3",
1486-
"version": "3.10.11"
1487+
"version": "3.12.7"
14871488
},
14881489
"pycharm": {
14891490
"stem_cell": {

examples/univariate_volatility_scenarios.ipynb

+2-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"import numpy as np\n",
3030
"import pandas as pd\n",
3131
"import seaborn as sns\n",
32+
"\n",
3233
"from arch.univariate import GARCH, ConstantMean, Normal\n",
3334
"\n",
3435
"sns.set_style(\"darkgrid\")\n",
@@ -382,8 +383,6 @@
382383
}
383384
],
384385
"source": [
385-
"import pandas as pd\n",
386-
"\n",
387386
"df = pd.concat(\n",
388387
" [\n",
389388
" forecasts.residual_variance.iloc[-1],\n",
@@ -530,7 +529,7 @@
530529
"name": "python",
531530
"nbconvert_exporter": "python",
532531
"pygments_lexer": "ipython3",
533-
"version": "3.10.11"
532+
"version": "3.12.7"
534533
}
535534
},
536535
"nbformat": 4,

requirements-dev.txt

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ flake8
2323
mypy
2424
ruff
2525
pyupgrade>=3.4.0
26+
jupyterlab-code-formatter
2627

2728
# Documentation
2829
ipython>=7

0 commit comments

Comments
 (0)