diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 1bb52d29..bb55f562 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -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 \ @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cb11834e..9eecb2a7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/spaghetti/analysis.py b/spaghetti/analysis.py index 93f10008..5992542b 100644 --- a/spaghetti/analysis.py +++ b/spaghetti/analysis.py @@ -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): diff --git a/spaghetti/network.py b/spaghetti/network.py index ce930142..a0591db7 100644 --- a/spaghetti/network.py +++ b/spaghetti/network.py @@ -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. @@ -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 @@ -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)) """ @@ -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 @@ -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`` @@ -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: @@ -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 ----- @@ -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} """ @@ -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) """ diff --git a/spaghetti/util.py b/spaghetti/util.py index ef0d7b99..3c08b6bc 100644 --- a/spaghetti/util.py +++ b/spaghetti/util.py @@ -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) """ @@ -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 = {} @@ -181,7 +181,7 @@ def dijkstra(ntw, v0, initial_dist=numpy.inf): >>> round(distance[196], 4) 5505.6682 >>> pred[196] - 133 + np.int64(133) """ @@ -269,7 +269,7 @@ def dijkstra_mp(ntw_vertex): >>> round(distance[196], 4) 5505.6682 >>> pred[196] - 133 + np.int64(133) """ @@ -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.])) """