Skip to content

Commit 9c5f59b

Browse files
MuellerSebdfm
andauthored
Compat fix for older numpy versions (#517)
* Compat fix for older numpy versions * Adding test environment for old numpy versions * Fixing lint --------- Co-authored-by: Dan Foreman-Mackey <dfm@dfm.io>
1 parent 9433c91 commit 9c5f59b

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

.github/workflows/tests.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,17 @@ jobs:
4949
COVERALLS_PARALLEL: true
5050
COVERALLS_FLAG_NAME: ${{ matrix.python-version }}-${{ matrix.os }}
5151

52-
leading_edge:
52+
numpy_edge:
5353
runs-on: ${{ matrix.os }}
5454
strategy:
5555
matrix:
5656
python-version: ["3.12"]
57+
numpy-version: ["numpy>=2.0.0rc1"]
5758
os: ["ubuntu-latest"]
59+
include:
60+
- python-version: "3.9"
61+
numpy-version: "numpy<1.25"
62+
os: "ubuntu-latest"
5863

5964
steps:
6065
- name: Checkout
@@ -68,7 +73,7 @@ jobs:
6873
- name: Install dependencies
6974
run: |
7075
python -m pip install -U pip
71-
python -m pip install pip install pytest "numpy>=2.0.0rc1"
76+
python -m pip install pip install pytest "${{ matrix.numpy-version }}"
7277
python -m pip install -e.
7378
- name: Run tests
7479
run: pytest

src/emcee/ensemble.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
# for py2.7, will be an Exception in 3.8
2222
from collections import Iterable
2323

24+
try:
25+
# Try to import from numpy.exceptions (available in NumPy 1.25 and later)
26+
from numpy.exceptions import VisibleDeprecationWarning
27+
except ImportError:
28+
# Fallback to the top-level numpy import (for older versions)
29+
from numpy import VisibleDeprecationWarning
30+
2431

2532
class EnsembleSampler(object):
2633
"""An ensemble MCMC sampler
@@ -511,7 +518,7 @@ def compute_log_prob(self, coords):
511518
try:
512519
with warnings.catch_warnings(record=True):
513520
warnings.simplefilter(
514-
"error", np.exceptions.VisibleDeprecationWarning
521+
"error", VisibleDeprecationWarning
515522
)
516523
try:
517524
dt = np.atleast_1d(blob[0]).dtype

0 commit comments

Comments
 (0)