Skip to content

Commit df25558

Browse files
authored
Merge pull request #75 from DynamicsAndNeuralSystems/jmoo2880-test-tlmi-update
Fix numy nan deprecation
2 parents 5c87883 + 48c6599 commit df25558

File tree

6 files changed

+13
-11
lines changed

6 files changed

+13
-11
lines changed

pyspi/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def multivariate(self,data):
8686
""" Compute the dependency statistics for the entire multivariate dataset
8787
"""
8888
A = np.empty((data.n_processes,data.n_processes))
89-
A[:] = np.NaN
89+
A[:] = np.nan
9090

9191
for j in range(data.n_processes):
9292
for i in [ii for ii in range(data.n_processes) if ii != j]:

pyspi/calculator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def load_dataset(self, dataset):
266266
self._table = pd.DataFrame(
267267
data=np.full(
268268
(self.dataset.n_processes, self.n_spis * self.dataset.n_processes),
269-
np.NaN,
269+
np.nan,
270270
),
271271
columns=columns,
272272
index=self._dataset.procnames,
@@ -289,13 +289,13 @@ def compute(self):
289289
S = self._spis[spi].multivariate(self.dataset)
290290

291291
# Ensure the diagonal is NaN (sometimes set within the functions)
292-
np.fill_diagonal(S, np.NaN)
292+
np.fill_diagonal(S, np.nan)
293293

294294
# Save results
295295
self._table[spi] = S
296296
except Exception as err:
297297
warnings.warn(f'Caught {type(err)} for SPI "{spi}": {err}')
298-
self._table[spi] = np.NaN
298+
self._table[spi] = np.nan
299299
pbar.close()
300300
print(f"\nCalculation complete. Time taken: {pbar.format_dict['elapsed']:.4f}s")
301301
inspect_calc_results(self)

pyspi/statistics/infotheory.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def bivariate(self, data, i=None, j=None, verbose=False):
297297
logging.warning(
298298
"MI calcs failed. Maybe check input data for Cholesky factorisation?"
299299
)
300-
return np.NaN
300+
return np.nan
301301

302302

303303
class TimeLaggedMutualInfo(MutualInfo):
@@ -331,7 +331,7 @@ def bivariate(self, data, i=None, j=None, verbose=False):
331331
logging.warning(
332332
"Time-lagged MI calcs failed. Maybe check input data for Cholesky factorisation?"
333333
)
334-
return np.NaN
334+
return np.nan
335335

336336

337337
class TransferEntropy(JIDTBase, Directed):
@@ -405,7 +405,7 @@ def bivariate(self, data, i=None, j=None, verbose=False):
405405
return self._calc.computeAverageLocalOfObservations()
406406
except Exception as err:
407407
logging.warning(f"TE calcs failed: {err}.")
408-
return np.NaN
408+
return np.nan
409409

410410

411411
class CrossmapEntropy(JIDTBase, Directed):

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pytest
22
h5py
33
scikit-learn
44
scipy
5-
numpy
5+
numpy<2.0.0
66
pandas
77
statsmodels
88
pyyaml
@@ -20,3 +20,4 @@ oct2py
2020
tslearn
2121
mne==0.23.0
2222
seaborn
23+
future

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
'h5py',
1212
'scikit-learn',
1313
'scipy',
14-
'numpy',
14+
'numpy<2.0.0',
1515
'pandas',
1616
'statsmodels',
1717
'pyyaml',
@@ -28,7 +28,8 @@
2828
'oct2py',
2929
'tslearn',
3030
'mne==0.23.0',
31-
'seaborn'
31+
'seaborn',
32+
'future'
3233
]
3334

3435
testing_extras = [

tests/test_calc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def test_pass_dataset_with_nan_into_calculator(nan_loc, expected_output):
9898
"""Check whether ValueError is raised when a dataset containing a NaN is passed into the calculator object"""
9999
base_dataset = np.random.randn(5, 100)
100100
for loc in nan_loc:
101-
base_dataset[loc, 0] = np.NaN
101+
base_dataset[loc, 0] = np.nan
102102
with pytest.raises(ValueError) as excinfo:
103103
calc = Calculator(dataset=base_dataset)
104104
assert f"non-numerics (NaNs) in processes: {expected_output}" in str(excinfo), "NaNs not detected in dataset when loading into Calculator!"

0 commit comments

Comments
 (0)