Skip to content

Commit 2ad7d7a

Browse files
authored
Merge pull request #462 from bashtage/optional-type-checking
MAINT: Make typing_extensions optional
2 parents ff0b6a6 + 379b037 commit 2ad7d7a

31 files changed

+172
-51
lines changed

arch/bootstrap/_samplers_python.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from arch.compat.numba import jit
24

35
from arch.typing import NDArray

arch/bootstrap/base.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import copy
24
from typing import (
35
Any,
@@ -796,7 +798,7 @@ def _bca_acceleration(
796798
jk_params = _loo_jackknife(func, nobs, self._args, self._kwargs, extra_kwags)
797799
return _get_acceleration(jk_params)
798800

799-
def clone(self, *args: ArrayLike, **kwargs: ArrayLike) -> "IIDBootstrap":
801+
def clone(self, *args: ArrayLike, **kwargs: ArrayLike) -> IIDBootstrap:
800802
"""
801803
Clones the bootstrap using different data with a fresh RandomState.
802804

arch/bootstrap/multiple_comparison.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1+
from __future__ import annotations
2+
13
import sys
2-
from typing import Any, Dict, Hashable, List, Optional, Sequence, Tuple, Union, cast
4+
from typing import (
5+
TYPE_CHECKING,
6+
Any,
7+
Dict,
8+
Hashable,
9+
List,
10+
Optional,
11+
Sequence,
12+
Tuple,
13+
Union,
14+
cast,
15+
)
316

4-
if sys.version_info < (3, 8):
5-
from typing_extensions import Literal
6-
else:
17+
if sys.version_info >= (3, 8):
718
from typing import Literal
19+
elif TYPE_CHECKING:
20+
from typing_extensions import Literal
821

922
import numpy as np
1023
import pandas as pd

arch/covariance/kernel.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from abc import ABC, abstractmethod
24
from typing import List, Optional
35

arch/typing.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import datetime as dt
24
from typing import Callable, Hashable, Optional, Tuple, TypeVar, Union
35

arch/unitroot/_engle_granger.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from typing import Optional
24

35
import numpy as np
@@ -32,7 +34,7 @@ def engle_granger(
3234
lags: Optional[int] = None,
3335
max_lags: Optional[int] = None,
3436
method: str = "bic",
35-
) -> "EngleGrangerTestResults":
37+
) -> EngleGrangerTestResults:
3638
r"""
3739
Test for cointegration within a set of time series.
3840

arch/unitroot/_phillips_ouliaris.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from typing import Optional
24

35
import numpy as np
@@ -42,7 +44,7 @@ def _po_ptests(
4244
kernel: str,
4345
bandwidth: Optional[int],
4446
force_int: bool,
45-
) -> "PhillipsOuliarisTestResults":
47+
) -> PhillipsOuliarisTestResults:
4648
nobs = z.shape[0]
4749
z_lead = z.iloc[1:]
4850
z_lag = add_trend(z.iloc[:-1], trend=trend)
@@ -94,7 +96,7 @@ def _po_ztests(
9496
kernel: str,
9597
bandwidth: Optional[int],
9698
force_int: bool,
97-
) -> "PhillipsOuliarisTestResults":
99+
) -> PhillipsOuliarisTestResults:
98100
# Za and Zt tests
99101
u = np.asarray(xsection.resid)[:, None]
100102
nobs = u.shape[0]
@@ -139,7 +141,7 @@ def phillips_ouliaris(
139141
kernel: str = "bartlett",
140142
bandwidth: Optional[int] = None,
141143
force_int: bool = False,
142-
) -> "PhillipsOuliarisTestResults":
144+
) -> PhillipsOuliarisTestResults:
143145
r"""
144146
Test for cointegration within a set of time series.
145147

arch/unitroot/_shared.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from typing import Any, Dict, NamedTuple, Optional, Tuple, Type
24

35
import pandas as pd
@@ -219,7 +221,7 @@ def resid(self) -> pd.Series:
219221

220222
def plot(
221223
self, axes: Optional["plt.Axes"] = None, title: Optional[str] = None
222-
) -> "plt.Figure":
224+
) -> plt.Figure:
223225
"""
224226
Plot the cointegration residuals.
225227

arch/unitroot/cointegration.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from typing import List, Optional, Sequence, Tuple
24

35
import numpy as np

arch/unitroot/critical_values/dfgls.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
These have been computed using the methodology of MacKinnon (1994) and (2010)
66
simulation. See dfgls_critival_values_simulation for implementation.
77
"""
8+
from __future__ import annotations
89

910
from numpy import array
1011

arch/unitroot/critical_values/dickey_fuller.py

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
did not appear in the original paper and have been computed using an identical
77
simulation.
88
"""
9+
from __future__ import annotations
10+
911
from typing import Dict
1012

1113
from numpy import array, asarray, inf

arch/unitroot/critical_values/engle_granger.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import numpy as np
24

35
eg_num_variables = np.arange(1, 13)

arch/unitroot/critical_values/kpss.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from numpy import asarray
24

35
kpss_critical_values = {}

arch/unitroot/critical_values/phillips_ouliaris.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
P-type statistics with trend ct based on 11,250,000 simulations
1111
P-type statistics with trend ctt based on 13,250,000 simulations
1212
"""
13+
from __future__ import annotations
1314

1415
from math import inf
1516

arch/unitroot/critical_values/simulation/adf_simulation.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
from __future__ import annotations
2+
13
import os
24
import platform
35
import sys
4-
from typing import Optional, Union
6+
from typing import TYPE_CHECKING, Optional, Union
57

68
from numpy import arange, array, cumsum, dot, ones, vstack
79
from numpy.linalg import pinv
810
from numpy.random import Generator, RandomState
911

1012
if sys.version_info >= (3, 8):
1113
from typing import Literal
12-
else:
14+
elif TYPE_CHECKING:
1315
from typing_extensions import Literal
1416

1517
# Storage Location

arch/unitroot/critical_values/simulation/adf_z_critical_values_simulation_joblib.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
"""
22
Simulation of ADF z-test critical values. Closely follows MacKinnon (2010).
33
"""
4+
from __future__ import annotations
5+
46
import argparse
57
import os
68
import random
79
import sys
8-
from typing import cast
10+
from typing import TYPE_CHECKING, cast
911

1012
if sys.version_info >= (3, 8):
1113
from typing import Literal
12-
else:
14+
elif TYPE_CHECKING:
1315
from typing_extensions import Literal
1416

1517
from adf_simulation import (

arch/unitroot/critical_values/simulation/adf_z_critical_values_simulation_large_cluster.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
This version has been optimized for execution on a large cluster and should
1111
scale well with 128 or more engines.
1212
"""
13+
from __future__ import annotations
14+
1315
import datetime
1416
import sys
1517
import time
16-
from typing import cast
18+
from typing import TYPE_CHECKING, cast
1719

1820
from ipyparallel import Client, DirectView
1921
from numpy import array, nan, ndarray, percentile, savez
@@ -22,7 +24,7 @@
2224

2325
if sys.version_info >= (3, 8):
2426
from typing import Literal
25-
else:
27+
elif TYPE_CHECKING:
2628
from typing_extensions import Literal
2729

2830
# Time in seconds to sleep before checking if ready

arch/unitroot/critical_values/simulation/dfgls_critical_values_simulation.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
to MacKinnon (2010). Makes use of parallel_fun in statsmodels which works
44
best when joblib is installed.
55
"""
6+
from __future__ import annotations
7+
68
import datetime
79
import sys
8-
from typing import Optional, cast
10+
from typing import TYPE_CHECKING, Optional, cast
911

1012
if sys.version_info >= (3, 8):
1113
from typing import Literal
12-
else:
14+
elif TYPE_CHECKING:
1315
from typing_extensions import Literal
1416

1517
import numpy as np

arch/unitroot/critical_values/zivot_andrews.py

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
The p-values are generated through Monte Carlo simulation using 100,000
88
replications and 2000 data points.
99
"""
10+
from __future__ import annotations
11+
1012
from numpy import array
1113

1214
# constant-only model

arch/unitroot/unitroot.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from abc import ABCMeta, abstractmethod
24
from typing import Dict, List, Optional, Sequence, Tuple, Union
35
import warnings
@@ -25,6 +27,7 @@
2527
isnan,
2628
log,
2729
nan,
30+
ndarray,
2831
ones,
2932
pi,
3033
polyval,
@@ -237,8 +240,8 @@ def _autolag_ols_low_memory(
237240
m = rhs.shape[1]
238241
xpx = empty((m + maxlag, m + maxlag)) * nan
239242
xpy = empty((m + maxlag, 1)) * nan
240-
assert isinstance(xpx, NDArray)
241-
assert isinstance(xpy, NDArray)
243+
assert isinstance(xpx, ndarray)
244+
assert isinstance(xpy, ndarray)
242245
xpy[:m] = rhs.T @ lhs
243246
xpx[:m, :m] = rhs.T @ rhs
244247
for i in range(maxlag):

arch/univariate/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from arch.univariate import recursions_python
24
from arch.univariate.distribution import (
35
Distribution,

0 commit comments

Comments
 (0)