Skip to content

Commit

Permalink
ENH: Add support for NumPy 3
Browse files Browse the repository at this point in the history
Add build support for NumPy 2
  • Loading branch information
bashtage committed Apr 16, 2024
1 parent 256887c commit d96ef51
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 44 deletions.
2 changes: 1 addition & 1 deletion arch/tests/bootstrap/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ def test_jackknife(bs_setup):

x = bs_setup.x_df
results_df = _loo_jackknife(bs_setup.func, len(x), (x,), {})
assert_equal(results, results_df)
assert_allclose(results, results_df)

y = bs_setup.y
results = _loo_jackknife(bs_setup.func, len(y), (y,), {})
Expand Down
2 changes: 1 addition & 1 deletion arch/tests/univariate/test_arch_in_mean.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

SP500 = 100 * sp500.load()["Adj Close"].pct_change().dropna()
SP500 = SP500.iloc[SP500.shape[0] // 2 :]
X = pd.concat([SP500, SP500], axis=1, copy=True)
X = pd.concat([SP500, SP500], axis=1)
X.columns = pd.Index([0, 1])
RANDOMSTATE = np.random.RandomState(12349876)
X.loc[:, :] = RANDOMSTATE.standard_normal(X.shape)
Expand Down
6 changes: 3 additions & 3 deletions arch/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
AnyArray = np.ndarray[Any, Any] # pragma: no cover
Uint32Array = np.ndarray[Any, np.dtype[np.uint32]] # pragma: no cover
else:
Uint32Array = (
IntArray
) = Float64Array = Int64Array = Int32Array = BoolArray = AnyArray = NDArray
Uint32Array = IntArray = Float64Array = Int64Array = Int32Array = BoolArray = (
AnyArray
) = NDArray

BootstrapIndexT = Union[
Int64Array, tuple[Int64Array, ...], tuple[list[Int64Array], dict[str, Int64Array]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
META = {"z_a": "negative", "z_t": "negative", "p_u": "positive", "p_z": "positive"}
CRITICAL_VALUES = (1, 5, 10)
PLOT = False
WINS: dict[int, int] = defaultdict(lambda: 0)
WINS: dict[int, int] = defaultdict(int)
# 1. Load data
# 2. Compute critical values

Expand Down
4 changes: 1 addition & 3 deletions arch/unitroot/unitroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1144,9 +1144,7 @@ def _compute_statistic(self) -> None:
self._stat_tau = sqrt(gamma0 / lam2) * ((rho - 1) / sigma) - 0.5 * (
(lam2 - gamma0) / lam
) * (n * sigma / s)
self._stat_rho = n * (rho - 1) - 0.5 * (n**2.0 * sigma2 / s2) * (
lam2 - gamma0
)
self._stat_rho = n * (rho - 1) - 0.5 * (n**2.0 * sigma2 / s2) * (lam2 - gamma0)

self._nobs = int(resols.nobs)
if self._test_type == "rho":
Expand Down
6 changes: 2 additions & 4 deletions arch/utility/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,15 @@ def ensure1d(
x: int | float | Sequence[int | float] | ArrayLike,
name: Hashable | None,
series: Literal[True] = ...,
) -> Series:
... # pragma: no cover
) -> Series: ... # pragma: no cover


@overload
def ensure1d(
x: int | float | Sequence[int | float] | ArrayLike,
name: Hashable | None,
series: Literal[False],
) -> np.ndarray:
... # pragma: no cover
) -> np.ndarray: ... # pragma: no cover


def ensure1d(
Expand Down
9 changes: 3 additions & 6 deletions arch/utility/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ def add_trend(
prepend: bool = ...,
nobs: int = ...,
has_constant: Literal["raise", "add", "skip"] = ...,
) -> Float64Array:
... # pragma: no cover
) -> Float64Array: ... # pragma: no cover


@overload
Expand All @@ -59,8 +58,7 @@ def add_trend(
prepend: bool = ...,
nobs: None = ...,
has_constant: Literal["raise", "add", "skip"] = ...,
) -> Float64Array:
... # pragma: no cover
) -> Float64Array: ... # pragma: no cover


@overload
Expand All @@ -70,8 +68,7 @@ def add_trend(
prepend: bool = ...,
nobs: None = ...,
has_constant: Literal["raise", "add", "skip"] = ...,
) -> pd.DataFrame:
... # pragma: no cover
) -> pd.DataFrame: ... # pragma: no cover


def add_trend(
Expand Down
25 changes: 12 additions & 13 deletions ci/azure/azure_template_posix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ jobs:
python39_numpy120:
python.version: '3.9'
MATPLOTLIB: 3.3.0
NUMPY: 1.20.0
SCIPY: 1.7.0
PANDAS: 1.2.0
NUMPY: 1.22.3
SCIPY: 1.8.0
PANDAS: 1.4.0
python_310_no_binary:
python.version: '3.10'
ARCH_NO_BINARY: true
PYTEST_OPTS: '--skip-slow'
PANDAS: 1.4.0
PANDAS: 1.5.0
USE_NUMBA: true
python_39_no_binary_environment:
python.version: '3.9'
Expand All @@ -62,22 +62,22 @@ jobs:
PYTEST_OPTS: '--skip-slow'
python_39_no_numba:
python.version: '3.9'
NUMPY: 1.21.0
NUMPY: 1.24.0
USE_NUMBA: false
MATPLOTLIB: 3.3.0
MATPLOTLIB: 3.5.0
PANDAS: 1.5.0
PYTEST_PATTERN: "(slow or not slow)"
python_39_numpy_118:
python.version: '3.9'
NUMPY: 1.22.0
NUMPY: 1.24.0
USE_NUMBA: false
PYTEST_PATTERN: "(slow or not slow)"
python_minimums:
python.version: '3.9'
NUMPY: 1.19.0
SCIPY: 1.5.0
MATPLOTLIB: 3.3.0
PANDAS: 1.1.0
NUMPY: 1.23.0
SCIPY: 1.9.0
MATPLOTLIB: 3.4.0
PANDAS: 1.4.0
python312_pre:
python.version: '3.12'
pip.pre: true
Expand Down Expand Up @@ -176,9 +176,8 @@ jobs:
testRunTitle: 'Python $(python.version)'
condition: succeededOrFailed()

- task: PublishCodeCoverageResults@1
- task: PublishCodeCoverageResults@2
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/coverage.xml'
condition: and(eq(variables['coverage'], 'true'), ne(variables['test.install'], 'true'))

Expand Down
2 changes: 1 addition & 1 deletion ci/azure/install-posix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ else
fi

python -m pip install --upgrade pip "setuptools>=61" wheel
python -m pip install cython "pytest>=7" pytest-xdist coverage pytest-cov ipython jupyter notebook nbconvert "property_cached>=1.6.3" black isort flake8 nbconvert setuptools_scm colorama
python -m pip install cython "pytest>=7,<8" pytest-xdist coverage pytest-cov ipython jupyter notebook nbconvert "property_cached>=1.6.3" black isort flake8 nbconvert setuptools_scm colorama

if [[ -n ${NUMPY} ]]; then CMD="$CMD~=${NUMPY}"; fi;
CMD="$CMD scipy"
Expand Down
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,16 @@ requires = [
"setuptools>=61",
"wheel",
"setuptools_scm[toml]>=8.0.3,<9",
"oldest-supported-numpy>=2022.11.19",
"cython>=0.29.34", # Works with 3.0.0b2

"cython>=3.0.10",
"numpy>=2.0.0rc1,<3"
]
build-backend = "setuptools.build_meta"

[tool.setuptools.dynamic]
dependencies = { file = ["requirements.txt"] }

[tool.black]
target-version = ['py39', 'py310', 'py311']
target-version = ['py39', 'py310', 'py311', 'py312']
exclude = '''
(
\.egg
Expand Down
7 changes: 3 additions & 4 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
# versioning
setuptools_scm[toml]>=8.0.3,<9
packaging
oldest-supported-numpy>=2022.11.19

# Performance
cython>=0.29.34 # Works with 3.0.0b2
cython>=3.0.10
numba>=0.49,!=0.50.*;python_version<"3.12"

# Graphics
matplotlib>=3
seaborn

# Tests
pytest>=7.3
pytest>=7.3,<8
pytest-xdist
pytest-cov

# formatting
black[jupyter]==23.12.1
black[jupyter]~=24.4.0
isort~=5.0
colorama
flake8
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
numpy>=1.19
scipy>=1.5
pandas>=1.1
numpy>=1.22.3
scipy>=1.8
pandas>=1.4
statsmodels>=0.12

0 comments on commit d96ef51

Please sign in to comment.