1111import numpy as np
1212from numpy .random import Generator , RandomState
1313import pandas as pd
14- import scipy . stats as stats
14+ from scipy import stats
1515
1616from arch .typing import (
1717 AnyArray ,
3636)
3737
3838__all__ = [
39- "IIDBootstrap" ,
40- "StationaryBootstrap" ,
4139 "CircularBlockBootstrap" ,
42- "MovingBlockBootstrap " ,
40+ "IIDBootstrap " ,
4341 "IndependentSamplesBootstrap" ,
42+ "MovingBlockBootstrap" ,
43+ "StationaryBootstrap" ,
4444 "optimal_block_length" ,
4545]
4646
@@ -64,10 +64,10 @@ def _get_random_integers(
6464 prng : Generator | RandomState , upper : int , * , size : int = 1
6565) -> Int64Array1D :
6666 if isinstance (prng , Generator ):
67- return cast (Int64Array1D , prng .integers (upper , size = size , dtype = np .int64 ))
67+ return cast (" Int64Array1D" , prng .integers (upper , size = size , dtype = np .int64 ))
6868 else :
6969 assert isinstance (prng , RandomState )
70- return cast (Int64Array1D , prng .randint (upper , size = size , dtype = np .int64 ))
70+ return cast (" Int64Array1D" , prng .randint (upper , size = size , dtype = np .int64 ))
7171
7272
7373def _single_optimal_block (x : Float64Array ) -> tuple [float , float ]:
@@ -198,7 +198,7 @@ def optimal_block_length(x: ArrayLike1D | ArrayLike2D) -> pd.DataFrame:
198198 elif isinstance (x , pd .Series ):
199199 idx = [x .name ]
200200 else :
201- idx = [ i for i in range (x_arr .shape [1 ])]
201+ idx = list ( range (x_arr .shape [1 ]))
202202 return pd .DataFrame (opt , index = idx , columns = ["stationary" , "circular" ])
203203
204204
@@ -263,13 +263,15 @@ def _loo_jackknife(
263263 args_copy : list [ArrayLike ] = []
264264 for arg in args :
265265 if isinstance (arg , (pd .Series , pd .DataFrame )):
266- args_copy .append (cast (Union [pd .Series , pd .DataFrame ], arg .iloc [items ]))
266+ args_copy .append (
267+ cast ("Union[pd.Series, pd.DataFrame]" , arg .iloc [items ])
268+ )
267269 else :
268270 args_copy .append (arg [items ])
269271 kwargs_copy : dict [str , ArrayLike ] = {}
270272 for k , v in kwargs .items ():
271273 if isinstance (v , (pd .Series , pd .DataFrame )):
272- kwargs_copy [k ] = cast (Union [pd .Series , pd .DataFrame ], v .iloc [items ])
274+ kwargs_copy [k ] = cast (" Union[pd.Series, pd.DataFrame]" , v .iloc [items ])
273275 else :
274276 kwargs_copy [k ] = v [items ]
275277 if extra_kwargs is not None :
@@ -412,10 +414,10 @@ def __init__(
412414 if args :
413415 self ._num_items = len (args [0 ])
414416 elif kwargs :
415- key = list ( kwargs .keys ())[ 0 ]
417+ key = next ( iter ( kwargs .keys ()))
416418 self ._num_items = len (kwargs [key ])
417419 all_args = list (args )
418- all_args .extend ([ v for v in kwargs .values ()] )
420+ all_args .extend (list ( kwargs .values ()) )
419421 if self ._common_size_required :
420422 for arg in all_args :
421423 if len (arg ) != self ._num_items :
@@ -510,7 +512,7 @@ def state(self, value: RandomStateState | Mapping[str, Any]) -> None:
510512 self ._generator .bit_generator .state = value
511513 else :
512514 assert isinstance (self ._generator , RandomState )
513- self ._generator .set_state (cast (RandomStateState , value ))
515+ self ._generator .set_state (cast (" RandomStateState" , value ))
514516
515517 def reset (self , use_seed : bool = True ) -> None :
516518 """
@@ -689,12 +691,11 @@ def conf_int(
689691 studentize_reps = studentize_reps if method == studentized else 0
690692 if sampling in ("semi" , "semi-parametric" , "semiparametric" ):
691693 sampling = "semiparametric"
692- else :
693- if sampling not in ("nonparametric" , "parametric" ):
694- raise ValueError (
695- 'sampling must be one of "nonparametric", "parametric", "semi", '
696- '"semi-parametric", or "semiparametric"'
697- )
694+ elif sampling not in ("nonparametric" , "parametric" ):
695+ raise ValueError (
696+ 'sampling must be one of "nonparametric", "parametric", "semi", '
697+ '"semi-parametric", or "semiparametric"'
698+ )
698699 _reuse = False
699700 if reuse :
700701 # check conditions for reuse
@@ -717,7 +718,7 @@ def conf_int(
717718 reps ,
718719 extra_kwargs ,
719720 std_err_func = std_err_func ,
720- studentize_reps = studentize_reps , # noqa
721+ studentize_reps = studentize_reps ,
721722 sampling = sampling ,
722723 )
723724
@@ -755,7 +756,7 @@ def conf_int(
755756 values = results
756757 if method == studentized :
757758 # studentized uses studentized parameter estimates
758- values = cast (Float64Array , studentized_results )
759+ values = cast (" Float64Array" , studentized_results )
759760
760761 if method in ("debiased" , "bc" , "bias-corrected" , "bca" ):
761762 # bias corrected uses modified percentiles, but is
@@ -1164,7 +1165,7 @@ def _resample(self) -> tuple[tuple[ArrayLike, ...], dict[str, ArrayLike]]:
11641165 """
11651166 Resample all data using the values in _index
11661167 """
1167- indices = cast (Union [Int64Array , tuple [Int64Array , ...]], self ._index )
1168+ indices = cast (" Union[Int64Array, tuple[Int64Array, ...]]" , self ._index )
11681169 pos_data : list [NDArray | pd .DataFrame | pd .Series ] = []
11691170 for values in self ._args :
11701171 if isinstance (values , (pd .Series , pd .DataFrame )):
@@ -1338,7 +1339,7 @@ def _resample(self) -> tuple[tuple[ArrayLike, ...], dict[str, ArrayLike]]:
13381339 Resample all data using the values in _index
13391340 """
13401341 pos_indices , kw_indices = cast (
1341- tuple [list [Int64Array ], dict [str , Int64Array ]], self ._index
1342+ " tuple[list[Int64Array], dict[str, Int64Array]]" , self ._index
13421343 )
13431344 pos_data : list [NDArray | pd .DataFrame | pd .Series ] = []
13441345 for i , values in enumerate (self ._args ):
@@ -1502,9 +1503,9 @@ def update_indices(self) -> Int64Array1D:
15021503 indices %= self ._num_items
15031504
15041505 if indices .shape [0 ] > self ._num_items :
1505- return cast (Int64Array1D , indices [: self ._num_items ])
1506+ return cast (" Int64Array1D" , indices [: self ._num_items ])
15061507 else :
1507- return cast (Int64Array1D , indices )
1508+ return cast (" Int64Array1D" , indices )
15081509
15091510
15101511class StationaryBootstrap (CircularBlockBootstrap ):
@@ -1701,7 +1702,7 @@ def update_indices(self) -> Int64Array1D:
17011702 indices = indices .flatten ()
17021703
17031704 if indices .shape [0 ] > self ._num_items :
1704- return cast (Int64Array1D , indices [: self ._num_items ])
1705+ return cast (" Int64Array1D" , indices [: self ._num_items ])
17051706 else :
17061707 return indices
17071708
0 commit comments