Skip to content

Commit

Permalink
change numpy representations just within the test
Browse files Browse the repository at this point in the history
instead of setting an environment-specific number representation within
numpy, this commit sets the number representation per test case and with
a suggestion on how to change it once numpy>=2.0 is the minimal
requirement.
  • Loading branch information
floesche committed Dec 16, 2024
1 parent 3f2d47e commit d1ce83d
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 1 deletion.
5 changes: 5 additions & 0 deletions navis/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,12 @@ def convert_units(
Examples
--------
(Set up numpy number representation within the test, see NEP51.
Once numpy<=2 is dropped from requirements, the doctest comparissons
should become `np.float32(266476.88)` instead of `266476.8`)
>>> import navis
>>> if int(np.version.version.split('.')[0])>=2:
np.set_printoptions(legacy="1.25")
>>> n = navis.example_neurons(1)
>>> n.units
<Quantity(8, 'nanometer')>
Expand Down
5 changes: 5 additions & 0 deletions navis/core/skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,12 @@ def snap(self, locs, to='nodes'):
Examples
--------
(Set up numpy number representation within the test, see NEP51.
Once numpy<=2 is dropped from requirements, the doctest comparissons
should become `np.int32(1124)` instead of `1124`)
>>> import navis
>>> if int(np.version.version.split('.')[0])>=2:
np.set_printoptions(legacy="1.25")
>>> n = navis.example_neurons(1)
>>> id, dist = n.snap([0, 0, 0])
>>> id
Expand Down
5 changes: 5 additions & 0 deletions navis/graph/graph_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,12 @@ def find_main_branchpoint(
Examples
--------
(Set up numpy number representation within the test, see NEP51.
Once numpy<=2 is dropped from requirements, the doctest comparissons
should become `np.int32(110)` instead of `110`)
>>> import navis
>>> if int(np.version.version.split('.')[0])>=2:
np.set_printoptions(legacy="1.25")
>>> n = navis.example_neurons(1)
>>> navis.find_main_branchpoint(n, reroot_soma=True)
110
Expand Down
7 changes: 7 additions & 0 deletions navis/intersection/intersect.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,14 @@ def in_volume(x: Union['core.NeuronObject', Sequence, pd.DataFrame],
--------
Prune neuron to volume
(Set up numpy number representation within the test, see NEP51.
Once numpy<=2 is dropped from requirements, the doctest comparissons
should become `array([False, False, False, ..., False, False, False], shape=(4465,))`
instead of `array([False, False, False, ..., False, False, False])`)
>>> import navis
>>> if int(np.version.version.split('.')[0])>=2:
np.set_printoptions(legacy="1.25")
>>> n = navis.example_neurons(1)
>>> lh = navis.example_volume('LH')
>>> n_lh = navis.in_volume(n, lh, inplace=False)
Expand Down
38 changes: 37 additions & 1 deletion navis/morpho/mmetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,13 @@ def strahler_index(
Examples
--------
(Set up numpy number representation within the test, see NEP51.
Once numpy<=2 is dropped from requirements, the doctest comparissons
should become `np.int16(6)` instead of `91234`)
>>> import navis
>>> if int(np.version.version.split('.')[0])>=2:
np.set_printoptions(legacy="1.25")
>>> n = navis.example_neurons(2, kind='skeleton')
>>> n.reroot(n.soma, inplace=True)
>>> _ = navis.strahler_index(n)
Expand Down Expand Up @@ -550,7 +556,13 @@ def arbor_segregation_index(x: "core.NeuronObject") -> "core.NeuronObject":
Examples
--------
(Set up numpy number representation within the test, see NEP51.
Once numpy<=2 is dropped from requirements, the doctest comparissons
should become `np.float64(0.277)` instead of `0.277`)
>>> import navis
>>> if int(np.version.version.split('.')[0])>=2:
np.set_printoptions(legacy="1.25")
>>> n = navis.example_neurons(1)
>>> n.reroot(n.soma, inplace=True)
>>> _ = navis.arbor_segregation_index(n)
Expand Down Expand Up @@ -699,7 +711,13 @@ def bending_flow(x: "core.NeuronObject") -> "core.NeuronObject":
Examples
--------
(Set up numpy number representation within the test, see NEP51.
Once numpy<=2 is dropped from requirements, the doctest comparissons
should become `np.int64(785645)` instead of `785645`)
>>> import navis
>>> if int(np.version.version.split('.')[0])>=2:
np.set_printoptions(legacy="1.25")
>>> n = navis.example_neurons(1)
>>> n.reroot(n.soma, inplace=True)
>>> _ = navis.bending_flow(n)
Expand Down Expand Up @@ -969,7 +987,13 @@ def synapse_flow_centrality(
Examples
--------
(Set up numpy number representation within the test, see NEP51.
Once numpy<=2 is dropped from requirements, the doctest comparissons
should become `np.int64(786969)` instead of `786969`)
>>> import navis
>>> if int(np.version.version.split('.')[0])>=2:
np.set_printoptions(legacy="1.25")
>>> n = navis.example_neurons(2)
>>> n.reroot(n.soma, inplace=True)
>>> _ = navis.synapse_flow_centrality(n)
Expand Down Expand Up @@ -1174,7 +1198,13 @@ def flow_centrality(x: "core.NeuronObject") -> "core.NeuronObject":
Examples
--------
(Set up numpy number representation within the test, see NEP51.
Once numpy<=2 is dropped from requirements, the doctest comparissons
should become `np.int64(91234)` instead of `91234`)
>>> import navis
>>> if int(np.version.version.split('.')[0])>=2:
np.set_printoptions(legacy="1.25")
>>> n = navis.example_neurons(2)
>>> n.reroot(n.soma, inplace=True)
>>> _ = navis.flow_centrality(n)
Expand Down Expand Up @@ -1326,7 +1356,7 @@ def tortuosity(
should become `np.float64(1.074)` instead of `1.074`)
>>> import navis
>>> if int(np.version.version.split('.')[0])>=2:
np.set_printoptions(legacy="1.25")
np.set_printoptions(legacy="1.25")
>>> n = navis.example_neurons(1)
>>> # Calculate tortuosity as-is
>>> T = navis.tortuosity(n)
Expand Down Expand Up @@ -1635,7 +1665,13 @@ def betweeness_centrality(
Examples
--------
(Set up numpy number representation within the test, see NEP51.
Once numpy<=2 is dropped from requirements, the doctest comparissons
should become `np.int64(436866)` instead of `436866`)
>>> import navis
>>> if int(np.version.version.split('.')[0])>=2:
np.set_printoptions(legacy="1.25")
>>> n = navis.example_neurons(2, kind='skeleton')
>>> n.reroot(n.soma, inplace=True)
>>> _ = navis.betweeness_centrality(n)
Expand Down
5 changes: 5 additions & 0 deletions navis/nbl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,12 @@ def update_scores(queries, targets, scores_ex, nblast_func, **kwargs):
Mostly for testing but also illustrates the principle:
(Set up numpy number representation within the test, see NEP51.
Once numpy<=2 is dropped from requirements, the doctest comparissons
should become `np.True_` instead of `True`)
>>> import navis
>>> if int(np.version.version.split('.')[0])>=2:
np.set_printoptions(legacy="1.25")
>>> import numpy as np
>>> nl = navis.example_neurons(n=5)
>>> dp = navis.make_dotprops(nl, k=5) / 125
Expand Down

0 comments on commit d1ce83d

Please sign in to comment.