Skip to content

Conversation

@Moritz-Alexander-Kern
Copy link
Member

This pull request ensures compatibility with NumPy >2.0.

This adresses #652

max_occs_size_dur,
bins=np.arange(min_occ,
np.max(max_occs_size_dur) + 2))
np.max(max_occs_size_dur).astype(np.int16) + 2))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

max_occs_size_dur is uint which will cause an overflow in arange.

el) >= self.min_spikes])

def test_parameters_3d_min_occ(self):
# test min_occ parameter
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

split test in two tests to be more precise when debugging.


self.assertGreater(auc, 0.95)
self.assertGreater(auc, 0.95)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use sub tests to ensure garbage collection is carried out in between. Otherwise excessive amounts of memory are used.

@coveralls
Copy link
Collaborator

coveralls commented Feb 13, 2025

Coverage Status

coverage: 88.303%. remained the same
when pulling 36d4410 on INM-6:support_numpy_2
into febc7ce on NeuralEnsemble:master.

@@ -1,5 +1,5 @@
neo>=0.10.0
numpy>=1.19.5, <2
numpy>=1.19.5
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

numpy>2.0 ?


f_matrix /= (2 * self.sigma)
f_matrix = f_matrix / (2 * self.sigma)
return f_matrix
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Moritz-Alexander-Kern Moritz-Alexander-Kern added this to the v1.2.0 milestone Mar 4, 2025
@kohlerca
Copy link
Collaborator

kohlerca commented May 26, 2025

A comment regarding the changes, as several are due to the change in the string representation of NumPy types (obtained by the built-in repr). An alternative to avoid having the types in the docstring examples is to set NumPy to use the legacy formatters available, e.g., np.set_printoptions(legacy='1.25'). This affects only the formatting in NumPy and could be set by each module in Elephant.

We can also wrap the pprint to use the np.printoptions context manager locally, avoiding setting a global NumPy formatter. We could add the wrapped version to the utils module. However, this would work only for the examples with explicit pprint statements, not with examples where a variable or return is used directly (e.g., line 48 in elephant/kernels.py).

A third option would be to reconfigure Sphinx and DocTest instantiation to include the formatter in the initialization. The doctest_global_setup directive (details here). This seems the cleanest solution as it only affects the documentation generation and testing, not the imported Elephant code.

@kohlerca
Copy link
Collaborator

kohlerca commented Jun 2, 2025

The last changes fix the doctests to work with NumPy 2.0 while keeping the old-style NumPy formatting in the docstrings (NumPy 1.25).

The solution was to create a conftest.py dynamically when running the doctests job in the CI, which sets the formatter behavior for those tests.

This solution was chosen as doctest_global_setup was used only if running doctests as a specific Sphinx build, which is not the case (the CI uses pytest for the doctests). Also, disabled the doctest extension in Sphinx's conf.py to make it explicit that the runner is pytest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants