Skip to content

Commit

Permalink
update docstring tests -- numpy-2.0 failures (#769)
Browse files Browse the repository at this point in the history
* RLS: v1.7.5.post1

* temporarily disable doctests

* update pre-commit

* update pre-commit [2]

* update doctests & ruff

* try skipping doctests for 3.10 oldest

* try skipping doctests for 3.10 oldest [2]

* try skipping doctests for 3.10 oldest [3]
  • Loading branch information
jGaboardi committed Jun 20, 2024
1 parent 17a411c commit e2c54d6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 23 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,15 @@
- name: spatial versions
run: 'python -c "import geopandas; geopandas.show_versions();"'


- name: declare doctest run
run: |
if [[ $matrix.environment-file == 'ci/310-oldest.yaml' ]]; then
echo "DOCTEST='--doctest-modules'" >> "$GITHUB_ENV"
else
echo "DOCTEST=''" >> "$GITHUB_ENV"
fi
- name: run tests
run: |
pytest \
Expand All @@ -73,8 +81,8 @@
--cov-append \
--cov-report term-missing \
--cov-report xml \
--doctest-modules \
--timeout 60
--timeout 60 \
${{ env.DOCTEST }}
- name: codecov
uses: codecov/codecov-action@v4
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
files: "spaghetti\/"
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.3.5"
rev: "v0.4.9"
hooks:
- id: ruff
- id: ruff-format
Expand Down
2 changes: 1 addition & 1 deletion spaghetti/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def validatedistribution(self):

valid_distributions = ["uniform"]
if self.distribution not in valid_distributions:
msg = "%s distribution not currently supported." % self.distribution
msg = f"{self.distribution} distribution not currently supported."
raise RuntimeError(msg)

def computeenvelope(self):
Expand Down
25 changes: 13 additions & 12 deletions spaghetti/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,12 @@ class Network:
>>> import numpy
>>> list(numpy.unique(ntw.network_component_labels))
[0]
[np.int32(0)]
Show whether each component of the network is an isolated ring (or not).
>>> ntw.network_component_is_ring
{0: False}
{np.int32(0): False}
Show how many network arcs are associated with the component.
Expand All @@ -246,9 +246,9 @@ class Network:
>>> ntw.graph_n_components
1
>>> list(numpy.unique(ntw.graph_component_labels))
[0]
[np.int32(0)]
>>> ntw.graph_component_is_ring
{0: False}
{np.int32(0): False}
>>> edges = len(ntw.graph_component2edge[ntw.graph_component_labels[0]])
>>> edges
179
Expand Down Expand Up @@ -1018,7 +1018,7 @@ def distancebandweights(
There are ``8`` units with ``3`` neighbors in the ``W`` object.
>>> w.histogram[-1]
(8, 3)
(np.int64(8), np.int64(3))
"""

Expand Down Expand Up @@ -1718,7 +1718,7 @@ def allneighbordistances(
the distance between one observation and another will be positive value.
>>> s2s_dist[0,0], s2s_dist[1,0]
(nan, 3105.189475447081)
(np.float64(nan), np.float64(3105.189475447081))
If calculating a ``type-a`` to ``type-b`` distance matrix
the distance between all observations will likely be positive
Expand Down Expand Up @@ -1993,7 +1993,8 @@ def nearestneighbordistances(
>>> nn = ntw.nearestneighbordistances("crimes", keep_zero_dist=True)
>>> nn[11], nn[18]
(([18, 19], 165.33982412719126), ([19], 0.0))
(([18, 19], np.float64(165.33982412719126)), ([19], np.float64(0.0)))
This may be remedied by setting the ``keep_zero_dist`` keyword
argument to ``False``. With this parameter set, observation ``11``
Expand All @@ -2003,13 +2004,13 @@ def nearestneighbordistances(
>>> nn = ntw.nearestneighbordistances("crimes", keep_zero_dist=False)
>>> nn[11], nn[18]
(([18, 19], 165.33982412719126), ([11], 165.33982412719126))
(([18, 19], np.float64(165.33982412719126)), ([11], np.float64(165.33982412719126)))
There are valid reasons for both retaining or masking zero distance
neighbors. When conducting analysis, thought must be given as to
which model more accurately represents the specific scenario.
"""
""" # noqa: E501

# raise exception is the specified point pattern does not exist
if sourcepattern not in self.pointpatterns:
Expand Down Expand Up @@ -2618,7 +2619,7 @@ def Moran(self, pp_name, permutations=999, graph=False): # noqa N802
>>> moran_res, _ = ntw.Moran(crimes)
>>> round(moran_res.I, 6)
0.005193
np.float64(0.005193)
Notes
-----
Expand Down Expand Up @@ -2748,7 +2749,7 @@ def extract_component(net, component_id, weightings=None):
>>> longest.network_n_components
1
>>> longest.network_component_lengths
{0: 13508.169276875526}
{np.int32(0): 13508.169276875526}
"""

Expand Down Expand Up @@ -3150,7 +3151,7 @@ def element_as_gdf(
Calculate the total length of the network.
>>> arcs_df.geometry.length.sum()
104414.09200823458
np.float64(104414.09200823458)
"""

Expand Down
12 changes: 6 additions & 6 deletions spaghetti/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def get_neighbor_distances(ntw, v0, link):
>>> ntw = spaghetti.Network(examples.get_path("streets.shp"))
>>> neighs = spaghetti.util.get_neighbor_distances(ntw, 0, ntw.arc_lengths)
>>> numpy.round(neighs[1], 10)
102.6235345344
np.float64(102.6235345344)
"""

Expand Down Expand Up @@ -107,9 +107,9 @@ def generatetree(pred):
>>> distance, pred = spaghetti.util.dijkstra(ntw, 0)
>>> tree = spaghetti.util.generatetree(pred)
>>> tree[3]
[23, 22, 20, 19, 170, 2, 0]
[np.int64(23), np.int64(22), np.int64(20), np.int64(19), np.int64(170), np.int64(2), np.int64(0)]
"""
""" # noqa: E501

# instantiate tree lookup
tree = {}
Expand Down Expand Up @@ -181,7 +181,7 @@ def dijkstra(ntw, v0, initial_dist=numpy.inf):
>>> round(distance[196], 4)
5505.6682
>>> pred[196]
133
np.int64(133)
"""

Expand Down Expand Up @@ -269,7 +269,7 @@ def dijkstra_mp(ntw_vertex):
>>> round(distance[196], 4)
5505.6682
>>> pred[196]
133
np.int64(133)
"""

Expand Down Expand Up @@ -305,7 +305,7 @@ def squared_distance_point_link(point, link):
>>> import spaghetti
>>> point, link = (1,1), ((0,0), (2,0))
>>> spaghetti.util.squared_distance_point_link(point, link)
(1.0, array([1., 0.]))
(np.float64(1.0), array([1., 0.]))
"""

Expand Down

0 comments on commit e2c54d6

Please sign in to comment.