From 0198ad62c1579ab2f57797941534f8a5b4511edc Mon Sep 17 00:00:00 2001 From: Kevin Sheppard Date: Wed, 13 Jul 2022 01:01:10 +0100 Subject: [PATCH] MAINT: Improve coverage Update setuptools requirements Remove distutils --- .coveragerc | 3 +++ arch/bootstrap/_samplers.pyx | 2 +- arch/tests/univariate/test_arch_in_mean.py | 14 +++++++++++ arch/tests/univariate/test_mean.py | 4 ++-- arch/typing.py | 27 +++++++--------------- arch/univariate/recursions.pyx | 2 +- pyproject.toml | 4 ++-- requirements-dev.txt | 1 + setup.py | 7 +++--- 9 files changed, 36 insertions(+), 28 deletions(-) diff --git a/.coveragerc b/.coveragerc index c43408c06f..8198d3c051 100644 --- a/.coveragerc +++ b/.coveragerc @@ -28,6 +28,9 @@ exclude_lines = elif TYPE_CHECKING # Cython function declarations cdef + # Cython functions with void + cdef void + include = */arch/* omit = diff --git a/arch/bootstrap/_samplers.pyx b/arch/bootstrap/_samplers.pyx index 754f99d5dc..e1649613c5 100644 --- a/arch/bootstrap/_samplers.pyx +++ b/arch/bootstrap/_samplers.pyx @@ -1,5 +1,5 @@ #!python -#cython: language_level=3, boundscheck=False, wraparound=False, cdivision=True +#cython: language_level=3, boundscheck=False, wraparound=False, cdivision=True, binding=True import numpy as np diff --git a/arch/tests/univariate/test_arch_in_mean.py b/arch/tests/univariate/test_arch_in_mean.py index 0a4307666d..7e69ab5b2a 100644 --- a/arch/tests/univariate/test_arch_in_mean.py +++ b/arch/tests/univariate/test_arch_in_mean.py @@ -123,6 +123,20 @@ def test_supported(good_vol): assert res2.params.shape == (n,) +def test_egarch_bad_params(): + aim = ARCHInMean(SP500, volatility=EGARCH(), form="log") + res = aim.fit(disp=False) + sv = res.params.copy() + sv["omega"] = 4 + sv["alpha[1]"] = 0.75 + sv["beta[1]"] = 0.999998 + res2 = aim.fit(disp=False, starting_values=sv) + n = res2.params.shape[0] + assert res.param_cov.shape == (n, n) + res3 = aim.fit(disp=False, starting_values=res.params) + assert res3.params.shape == (n,) + + @pytest.mark.parametrize("form", ["log", "vol", 1.5]) def test_simulate_arx(form): normal = Normal(seed=np.random.RandomState(0)) diff --git a/arch/tests/univariate/test_mean.py b/arch/tests/univariate/test_mean.py index b1988b4447..0f70dbbc98 100644 --- a/arch/tests/univariate/test_mean.py +++ b/arch/tests/univariate/test_mean.py @@ -1,4 +1,3 @@ -from distutils.version import LooseVersion from io import StringIO from itertools import product from string import ascii_lowercase @@ -15,6 +14,7 @@ assert_array_almost_equal, assert_equal, ) +from packaging.version import parse import pandas as pd from pandas.testing import assert_frame_equal, assert_series_equal import pytest @@ -71,7 +71,7 @@ RTOL = 1e-4 if struct.calcsize("P") < 8 else 1e-6 DISPLAY: Literal["off"] = "off" -SP_LT_14 = LooseVersion(scipy.__version__) < LooseVersion("1.4") +SP_LT_14 = parse(scipy.__version__) < parse("1.4") SP500 = 100 * sp500.load()["Adj Close"].pct_change().dropna() diff --git a/arch/typing.py b/arch/typing.py index 380a23a0bd..306257ce2f 100644 --- a/arch/typing.py +++ b/arch/typing.py @@ -1,7 +1,6 @@ from __future__ import annotations import datetime as dt -import sys from typing import ( TYPE_CHECKING, Any, @@ -9,6 +8,7 @@ Dict, Hashable, List, + Literal, Optional, Tuple, TypeVar, @@ -20,17 +20,6 @@ NP_GTE_121 = np.lib.NumpyVersion(np.__version__) >= np.lib.NumpyVersion("1.21.0") -if sys.version_info >= (3, 8): - from typing import Literal -elif TYPE_CHECKING: - from typing_extensions import Literal -else: - - class _Literal: - def __getitem__(self, item): - pass - - Literal = _Literal() __all__ = [ "NDArray", @@ -59,13 +48,13 @@ def __getitem__(self, item): NDArray = Union[np.ndarray] if NP_GTE_121 and TYPE_CHECKING: - Float64Array = np.ndarray[Any, np.dtype[np.float64]] - Int64Array = np.ndarray[Any, np.dtype[np.int64]] - Int32Array = np.ndarray[Any, np.dtype[np.int32]] - IntArray = np.ndarray[Any, np.dtype[np.int_]] - BoolArray = np.ndarray[Any, np.dtype[np.bool_]] - AnyArray = np.ndarray[Any, Any] - Uint32Array = np.ndarray[Any, np.dtype[np.uint32]] + Float64Array = np.ndarray[Any, np.dtype[np.float64]] # pragma: no cover + Int64Array = np.ndarray[Any, np.dtype[np.int64]] # pragma: no cover + Int32Array = np.ndarray[Any, np.dtype[np.int32]] # pragma: no cover + IntArray = np.ndarray[Any, np.dtype[np.int_]] # pragma: no cover + BoolArray = np.ndarray[Any, np.dtype[np.bool_]] # pragma: no cover + AnyArray = np.ndarray[Any, Any] # pragma: no cover + Uint32Array = np.ndarray[Any, np.dtype[np.uint32]] # pragma: no cover else: Uint32Array = ( IntArray diff --git a/arch/univariate/recursions.pyx b/arch/univariate/recursions.pyx index fdce9181a9..64f61d308f 100644 --- a/arch/univariate/recursions.pyx +++ b/arch/univariate/recursions.pyx @@ -1,5 +1,5 @@ #!python -#cython: language_level=3, boundscheck=False, wraparound=False, cdivision=True +#cython: language_level=3, boundscheck=False, wraparound=False, cdivision=True, binding=True import numpy as np diff --git a/pyproject.toml b/pyproject.toml index ef853dfa75..080a95b6ab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,8 @@ [build-system] requires = [ - "setuptools>=45", + "setuptools>=61", "wheel", - "setuptools_scm[toml]>=6.2", + "setuptools_scm[toml]>=7,<8", "oldest-supported-numpy", "numpy; python_version>='3.11'", "Cython>=0.29.24" diff --git a/requirements-dev.txt b/requirements-dev.txt index fd49fc265a..be892610a9 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,5 +1,6 @@ # versioning setuptools_scm>=6.4.2,<7.0.0 +packaging # Performance cython>=0.29.30 diff --git a/setup.py b/setup.py index 1529dfff35..b8327b7af5 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,9 @@ from setuptools import Command, Extension, find_packages, setup from setuptools.dist import Distribution +from setuptools.errors import CCompilerError, ExecError, PlatformError from collections import defaultdict -from distutils.errors import CCompilerError, DistutilsExecError, DistutilsPlatformError + import fnmatch import os import pathlib @@ -201,8 +202,8 @@ def run_setup(binary: bool = True) -> None: run_setup(binary=build_binary) except ( CCompilerError, - DistutilsExecError, - DistutilsPlatformError, + ExecError, + PlatformError, OSError, ValueError, ):