Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix numpy doctest local #177

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
41 changes: 41 additions & 0 deletions 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 @@ -1321,7 +1351,12 @@ def tortuosity(

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(1.074)` instead of `1.074`)
>>> import navis
>>> if int(np.version.version.split('.')[0])>=2:
... np.set_printoptions(legacy="1.25")
>>> n = navis.example_neurons(1)
>>> # Calculate tortuosity as-is
>>> T = navis.tortuosity(n)
Expand Down Expand Up @@ -1630,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,8 +199,13 @@ 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
>>> import numpy as np
>>> if int(np.version.version.split('.')[0])>=2:
... np.set_printoptions(legacy="1.25")
>>> nl = navis.example_neurons(n=5)
>>> dp = navis.make_dotprops(nl, k=5) / 125
>>> # Full NBLAST
Expand Down
4 changes: 2 additions & 2 deletions navis/plotting/plot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def make_tube(segments, radii=1.0, tube_points=8, use_normals=True):
faces : np.ndarray

"""
vertices = np.empty((0, 3), dtype=np.float_)
vertices = np.empty((0, 3), dtype=np.float64)
indices = np.empty((0, 3), dtype=np.uint32)

if not isinstance(radii, Iterable):
Expand Down Expand Up @@ -219,7 +219,7 @@ def make_tube(segments, radii=1.0, tube_points=8, use_normals=True):
# Vertices for each point on the circle
verts = np.repeat(points, tube_points, axis=0)

v = np.arange(tube_points, dtype=np.float_) / tube_points * 2 * np.pi
v = np.arange(tube_points, dtype=np.float64) / tube_points * 2 * np.pi

all_cx = (
radius
Expand Down
Loading