Skip to content

Commit baa9d6e

Browse files
authored
Merge pull request #232 from effigies/deprecations
MNT: Address deprecations, update dependencies, apply numpy>1.21 style to doctests
2 parents 12dce19 + 2c67962 commit baa9d6e

18 files changed

+136
-325
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@ dist/
1414

1515
# setuptools_scm
1616
nitime/_version.py
17+
18+
# coverage
19+
.coverage
20+
coverage.xml
21+
22+
# tox
23+
.tox

min-requirements.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Auto-generated by tools/update_requirements.py
22
--only-binary numpy,scipy
33
--extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple
4-
matplotlib==3.5
5-
numpy==1.22
6-
scipy==1.8
7-
networkx==2.7
8-
nibabel==4.0
4+
matplotlib==3.7
5+
numpy==1.24
6+
scipy==1.10
7+
networkx==3.0
8+
nibabel==5.0

nitime/_compat.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# np.trapezoid was introduced and np.trapz deprecated in numpy 2.0
2+
try: # NP2
3+
from numpy import trapezoid
4+
except ImportError: # NP1
5+
from numpy import trapz as trapezoid

nitime/_mpl_units.py

Lines changed: 0 additions & 226 deletions
This file was deleted.

nitime/algorithms/tests/test_autoregressive.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import nitime.algorithms as tsa
55
import nitime.utils as utils
6+
from nitime._compat import trapezoid
67

78
# Set the random seed:
89
np.random.seed(1)
@@ -46,14 +47,14 @@ def test_AR_YW():
4647

4748
# evaluate this integral numerically from 0 to pi
4849
dw = np.pi / len(psd)
49-
avg_pwr_est = np.trapz(psd, dx=dw) / (2 * np.pi)
50+
avg_pwr_est = trapezoid(psd, dx=dw) / (2 * np.pi)
5051
# consistency on the order of 10**0 is pretty good for this test
5152
npt.assert_almost_equal(avg_pwr, avg_pwr_est, decimal=0)
5253

5354
# Test for providing the autocovariance as an input:
5455
ak, sigma_v = tsa.AR_est_YW(arsig, order, utils.autocov(arsig))
5556
w, psd = tsa.AR_psd(ak, sigma_v)
56-
avg_pwr_est = np.trapz(psd, dx=dw) / (2 * np.pi)
57+
avg_pwr_est = trapezoid(psd, dx=dw) / (2 * np.pi)
5758
npt.assert_almost_equal(avg_pwr, avg_pwr_est, decimal=0)
5859

5960

@@ -76,13 +77,13 @@ def test_AR_LD():
7677

7778
# evaluate this integral numerically from 0 to pi
7879
dw = np.pi / len(psd)
79-
avg_pwr_est = np.trapz(psd, dx=dw) / (2 * np.pi)
80+
avg_pwr_est = trapezoid(psd, dx=dw) / (2 * np.pi)
8081
npt.assert_almost_equal(avg_pwr, avg_pwr_est, decimal=0)
8182

8283
# Test for providing the autocovariance as an input:
8384
ak, sigma_v = tsa.AR_est_LD(arsig, order, utils.autocov(arsig))
8485
w, psd = tsa.AR_psd(ak, sigma_v)
85-
avg_pwr_est = np.trapz(psd, dx=dw) / (2 * np.pi)
86+
avg_pwr_est = trapezoid(psd, dx=dw) / (2 * np.pi)
8687
npt.assert_almost_equal(avg_pwr, avg_pwr_est, decimal=0)
8788

8889

nitime/analysis/coherence.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def __init__(self, input=None, method=None, unwrap_phases=False):
3939
Examples
4040
--------
4141
>>> import nitime.timeseries as ts
42-
>>> np.set_printoptions(precision=4) # for doctesting
4342
>>> t1 = ts.TimeSeries(data = np.arange(0,1024,1).reshape(2,512),
4443
... sampling_rate=np.pi)
4544
>>> c1 = CoherenceAnalyzer(t1)
@@ -48,11 +47,11 @@ def __init__(self, input=None, method=None, unwrap_phases=False):
4847
>>> c1.method['this_method']
4948
'welch'
5049
>>> c1.coherence[0,1]
51-
array([ 0.9024, 0.9027, 0.9652, 0.9433, 0.9297, 0.9213, 0.9161,
52-
0.9126, 0.9102, 0.9085, 0.9072, 0.9063, 0.9055, 0.905 ,
53-
0.9045, 0.9041, 0.9038, 0.9036, 0.9034, 0.9032, 0.9031,
54-
0.9029, 0.9028, 0.9027, 0.9027, 0.9026, 0.9026, 0.9025,
55-
0.9025, 0.9025, 0.9025, 0.9026, 1. ])
50+
array([0.9024, 0.9027, 0.9652, 0.9433, 0.9297, 0.9213, 0.9161, 0.9126,
51+
0.9102, 0.9085, 0.9072, 0.9063, 0.9055, 0.905 , 0.9045, 0.9041,
52+
0.9038, 0.9036, 0.9034, 0.9032, 0.9031, 0.9029, 0.9028, 0.9027,
53+
0.9027, 0.9026, 0.9026, 0.9025, 0.9025, 0.9025, 0.9025, 0.9026,
54+
1. ])
5655
>>> c1.phase[0,1]
5756
array([ 0. , -0.035 , -0.4839, -0.4073, -0.3373, -0.2828, -0.241 ,
5857
-0.2085, -0.1826, -0.1615, -0.144 , -0.1292, -0.1164, -0.1054,

nitime/analysis/correlation.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ def __init__(self, input=None):
2424
2525
Examples
2626
--------
27-
>>> np.set_printoptions(precision=4) # for doctesting
2827
>>> t1 = ts.TimeSeries(data = np.sin(np.arange(0,
2928
... 10*np.pi,10*np.pi/100)).reshape(2,50),
3029
... sampling_rate=np.pi)

nitime/analysis/spectral.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ def __init__(self, input=None, method=None, BW=None, adaptive=False,
4343
4444
Examples
4545
--------
46-
>>> np.set_printoptions(precision=4) # for doctesting
4746
>>> t1 = ts.TimeSeries(data = np.arange(0,1024,1).reshape(2,512),
4847
... sampling_rate=np.pi)
4948
>>> s1 = SpectralAnalyzer(t1)
@@ -53,13 +52,13 @@ def __init__(self, input=None, method=None, BW=None, adaptive=False,
5352
3.1415926535... Hz
5453
>>> f,s = s1.psd
5554
>>> f
56-
array([ 0. , 0.0491, 0.0982, 0.1473, 0.1963, 0.2454, 0.2945,
57-
0.3436, 0.3927, 0.4418, 0.4909, 0.54 , 0.589 , 0.6381,
58-
0.6872, 0.7363, 0.7854, 0.8345, 0.8836, 0.9327, 0.9817,
59-
1.0308, 1.0799, 1.129 , 1.1781, 1.2272, 1.2763, 1.3254,
60-
1.3744, 1.4235, 1.4726, 1.5217, 1.5708])
55+
array([0. , 0.0491, 0.0982, 0.1473, 0.1963, 0.2454, 0.2945, 0.3436,
56+
0.3927, 0.4418, 0.4909, 0.54 , 0.589 , 0.6381, 0.6872, 0.7363,
57+
0.7854, 0.8345, 0.8836, 0.9327, 0.9817, 1.0308, 1.0799, 1.129 ,
58+
1.1781, 1.2272, 1.2763, 1.3254, 1.3744, 1.4235, 1.4726, 1.5217,
59+
1.5708])
6160
>>> s[0,0] # doctest: +ELLIPSIS
62-
1128276.92538360...
61+
1128276.9253836009
6362
"""
6463
BaseAnalyzer.__init__(self, input)
6564

nitime/conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import numpy as np
2+
import pytest
3+
4+
5+
@pytest.fixture(scope='session', autouse=True)
6+
def legacy_printoptions():
7+
np.set_printoptions(legacy='1.21', precision=4)

nitime/index_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ def tri(N, M=None, k=0, dtype=float):
4444
[1, 1, 1, 1, 1]])
4545
4646
>>> np.tri(3, 5, -1)
47-
array([[ 0., 0., 0., 0., 0.],
48-
[ 1., 0., 0., 0., 0.],
49-
[ 1., 1., 0., 0., 0.]])
47+
array([[0., 0., 0., 0., 0.],
48+
[1., 0., 0., 0., 0.],
49+
[1., 1., 0., 0., 0.]])
5050
5151
"""
5252
if M is None: M = N

0 commit comments

Comments
 (0)