Skip to content

Commit

Permalink
Merge pull request #704 from bashtage/numpy-2
Browse files Browse the repository at this point in the history
MAINT: Add NumPy 2 compat
  • Loading branch information
bashtage committed Jan 2, 2024
2 parents a7103d3 + 0354117 commit 2d5cb94
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
8 changes: 7 additions & 1 deletion arch/compat/pandas.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from typing import TYPE_CHECKING

from packaging.version import parse
import pandas as pd

if TYPE_CHECKING:
from pandas.api.types import is_datetime64_any_dtype
else:
Expand All @@ -8,4 +11,7 @@
except ImportError:
from pandas.core.common import is_datetime64_any_dtype

__all__ = ["is_datetime64_any_dtype"]
PD_LT_22 = parse(pd.__version__) < parse("2.1.99")
MONTH_END = "M" if PD_LT_22 else "ME"

__all__ = ["is_datetime64_any_dtype", "MONTH_END"]
4 changes: 3 additions & 1 deletion arch/tests/unitroot/cointegration_data.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from arch.compat.pandas import MONTH_END

import numpy as np
import pandas as pd
import pytest
Expand Down Expand Up @@ -60,7 +62,7 @@ def trivariate_data(request) -> tuple[ArrayLike2D, ArrayLike2D]:
idx += 1
y = y @ rot
if request.param:
dt_index = pd.date_range("1-1-2000", periods=nobs, freq="M")
dt_index = pd.date_range("1-1-2000", periods=nobs, freq=MONTH_END)
cols = [f"y{i}" for i in range(1, 4)]
data = pd.DataFrame(y, columns=cols, index=dt_index)
return data.iloc[:, :1], data.iloc[:, 1:]
Expand Down
4 changes: 3 additions & 1 deletion arch/tests/univariate/test_mean.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from arch.compat.pandas import MONTH_END

from io import StringIO
from itertools import product
from string import ascii_lowercase
Expand Down Expand Up @@ -820,7 +822,7 @@ def test_date_first_last_obs(self):
assert_equal(res.resid.values, res2.resid.values)

def test_align(self):
dates = pd.date_range("2000-01-01", "2010-01-01", freq="M")
dates = pd.date_range("2000-01-01", "2010-01-01", freq=MONTH_END)
columns = ["h." + f"{h + 1:>02}" for h in range(10)]
forecasts = pd.DataFrame(self.rng.randn(120, 10), index=dates, columns=columns)

Expand Down
1 change: 0 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ variables:
VML_NUM_THREADS: 1
OPENBLAS_NUM_THREADS: 1
PYTHONHASHSEED: 12345678 # Ensure tests are correctly gathered by xdist
# SETUPTOOLS_USE_DISTUTILS: "stdlib"
TEST_INSTALL: false
MPLBACKEND: agg
PYTEST_PATTERN: "(not slow)"
Expand Down
Empty file added meson.build
Empty file.
6 changes: 2 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@
# prevent setup.py from crashing by calling import numpy before numpy is installed
class build_ext(_build_ext):
def build_extensions(self) -> None:
ref = importlib.resources.files("numpy") / "core/include"
with importlib.resources.as_file(ref) as path:
numpy_incl = str(path)

import numpy as np
numpy_incl = np.get_include()
for ext in self.extensions:
if hasattr(ext, "include_dirs") and numpy_incl not in ext.include_dirs:
ext.include_dirs.append(numpy_incl)
Expand Down

0 comments on commit 2d5cb94

Please sign in to comment.