Skip to content

Commit

Permalink
Add an upper limit on the numpy version due to incompatabilities with…
Browse files Browse the repository at this point in the history
… tslearn. Replaced np.NaN with np.nan for future numpy compatability.
  • Loading branch information
joshuabmoore committed Aug 24, 2024
1 parent 5c87883 commit db9af18
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyspi/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def multivariate(self,data):
""" Compute the dependency statistics for the entire multivariate dataset
"""
A = np.empty((data.n_processes,data.n_processes))
A[:] = np.NaN
A[:] = np.nan

for j in range(data.n_processes):
for i in [ii for ii in range(data.n_processes) if ii != j]:
Expand Down
6 changes: 3 additions & 3 deletions pyspi/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def load_dataset(self, dataset):
self._table = pd.DataFrame(
data=np.full(
(self.dataset.n_processes, self.n_spis * self.dataset.n_processes),
np.NaN,
np.nan,
),
columns=columns,
index=self._dataset.procnames,
Expand All @@ -289,13 +289,13 @@ def compute(self):
S = self._spis[spi].multivariate(self.dataset)

# Ensure the diagonal is NaN (sometimes set within the functions)
np.fill_diagonal(S, np.NaN)
np.fill_diagonal(S, np.nan)

# Save results
self._table[spi] = S
except Exception as err:
warnings.warn(f'Caught {type(err)} for SPI "{spi}": {err}')
self._table[spi] = np.NaN
self._table[spi] = np.nan
pbar.close()
print(f"\nCalculation complete. Time taken: {pbar.format_dict['elapsed']:.4f}s")
inspect_calc_results(self)
Expand Down
6 changes: 3 additions & 3 deletions pyspi/statistics/infotheory.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def bivariate(self, data, i=None, j=None, verbose=False):
logging.warning(
"MI calcs failed. Maybe check input data for Cholesky factorisation?"
)
return np.NaN
return np.nan


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


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


class CrossmapEntropy(JIDTBase, Directed):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pytest
h5py
scikit-learn
scipy
numpy
numpy<2.0.0
pandas
statsmodels
pyyaml
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'h5py',
'scikit-learn',
'scipy',
'numpy',
'numpy<2.0.0',
'pandas',
'statsmodels',
'pyyaml',
Expand Down
2 changes: 1 addition & 1 deletion tests/test_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_pass_dataset_with_nan_into_calculator(nan_loc, expected_output):
"""Check whether ValueError is raised when a dataset containing a NaN is passed into the calculator object"""
base_dataset = np.random.randn(5, 100)
for loc in nan_loc:
base_dataset[loc, 0] = np.NaN
base_dataset[loc, 0] = np.nan
with pytest.raises(ValueError) as excinfo:
calc = Calculator(dataset=base_dataset)
assert f"non-numerics (NaNs) in processes: {expected_output}" in str(excinfo), "NaNs not detected in dataset when loading into Calculator!"
Expand Down

0 comments on commit db9af18

Please sign in to comment.