Skip to content

Commit

Permalink
gpd & shp as hard reqs -- no optional testing -- #763 (#764)
Browse files Browse the repository at this point in the history
* RLS: v1.7.5.post1

* update pre-commit

* remove no-optional -- add GPD & SHP are hard reqs

* minor ruff linting

* GPD/SHP hard req in README

* forgot to remove no-opt yaml - proper shp pin

* proper gpd pin

* polish required imports
  • Loading branch information
jGaboardi committed Mar 24, 2024
1 parent 3fc7fe8 commit b463e1c
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 64 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
os: [ubuntu-latest]
environment-file:
- ci/310-oldest.yaml
- ci/310-no-optional.yaml
- ci/310-latest.yaml
- ci/311-latest.yaml
- ci/312-latest.yaml
Expand Down Expand Up @@ -59,9 +58,8 @@
micromamba info
micromamba list
- name: spatial versions (if geopandas is installed)
- name: spatial versions
run: 'python -c "import geopandas; geopandas.show_versions();"'
if: contains(matrix.environment-file, 'no-optional') != true

- name: run tests
run: |
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.1.9"
rev: "v0.3.3"
hooks:
- id: ruff
- id: ruff-format
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,12 @@ $ pip install git+https://github.com/pysal/spaghetti
## Requirements

- [`esda`](https://pysal.org/esda/)
- [`geopandas`](https://geopandas.org/en/stable/)
- [`libpysal`](https://pysal.org/libpysal/)
- [`libspatialindex`](https://libspatialindex.org/en/stable/)
- [`numpy`](https://numpy.org/devdocs/)
- [`rtree`](https://rtree.readthedocs.io/en/stable/)
- [`scipy`](http://scipy.github.io/devdocs/)

## Soft Dependencies

- [`geopandas`](https://geopandas.org/en/stable/)
- [`shapely`](https://shapely.readthedocs.io/en/stable/)

## History
Expand Down
2 changes: 2 additions & 0 deletions ci/310-latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ dependencies:
- python=3.10
# required
- esda
- geopandas
- libpysal
- numpy
- pandas
- pip
- rtree
- scipy
- shapely
- watermark
# testing
- codecov
Expand Down
19 changes: 0 additions & 19 deletions ci/310-no-optional.yaml

This file was deleted.

5 changes: 2 additions & 3 deletions ci/310-oldest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ dependencies:
- python=3.10
# required
- esda=2.1
- geopandas=0.12
- libpysal=4.6
- numpy=1.22
- pandas=1.4
- pip
- rtree=1.0
- scipy=1.8
- shapely=2.0
# testing
- codecov
- pytest
- pytest-cov
- pytest-timeout
- pytest-xdist
# optional
- geopandas=0.12
- shapely=2.0
2 changes: 2 additions & 0 deletions ci/311-latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ dependencies:
- python=3.11
# required
- esda
- geopandas
- libpysal
- numpy
- pandas
- pip
- rtree
- scipy
- shapely
- watermark
# testing
- codecov
Expand Down
2 changes: 2 additions & 0 deletions ci/312-latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ dependencies:
- python=3.12
# required
- esda
- geopandas
- libpysal
- numpy
- pandas
- pip
- rtree
- scipy
- shapely
- watermark
# testing
- codecov
Expand Down
11 changes: 5 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ classifiers = [
requires-python = ">=3.10"
dependencies = [
"esda>=2.1",
"geopandas>=0.12",
"libpysal>=4.6",
"numpy>=1.22",
"pandas>=1.4,!=1.5.0",
"rtree>=1.0",
"scipy>=1.8",
"shapely>=2.0.1",
]

[project.urls]
Expand All @@ -47,10 +49,6 @@ docs = [
"sphinxcontrib-bibtex",
"sphinx_bootstrap_theme",
]
plus = [
"geopandas>=0.12",
"shapely>=2.0",
]
tests = [
"pytest",
"pytest-cov",
Expand Down Expand Up @@ -82,9 +80,10 @@ include = [

[tool.ruff]
line-length = 88
select = ["E", "F", "W", "I", "UP", "N", "B", "A", "C4", "SIM", "ARG"]
lint.select = ["E", "F", "W", "I", "UP", "N", "B", "A", "C4", "SIM", "ARG"]
exclude = ["spaghetti/tests/*", "docs/*"]
[tool.ruff.per-file-ignores]

[tool.ruff.lint.per-file-ignores]
"*__init__.py" = [
"F401", # imported but unused
"F403", # star import; unable to detect undefined names
Expand Down
5 changes: 1 addition & 4 deletions spaghetti/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import esda
import numpy
from libpysal import cg, weights
from libpysal.common import requires

from . import util
from .analysis import GlobalAutoK
Expand Down Expand Up @@ -2636,7 +2635,7 @@ def Moran(self, pp_name, permutations=999, graph=False): # noqa N802
counts = self.count_per_link(pointpat.obs_to_arc, graph=graph)

# Build the y vector
y = [counts[i] if i in counts else 0.0 for i in w.neighbors]
y = [counts.get(i, 0.0) for i in w.neighbors]

# Moran's I
moran = esda.moran.Moran(y, w, permutations=permutations)
Expand Down Expand Up @@ -3044,7 +3043,6 @@ def mst_weighted_sort(net, maximum, net_kws):
return spanning_tree


@requires("geopandas", "shapely")
def element_as_gdf(
net,
vertices=False,
Expand Down Expand Up @@ -3119,7 +3117,6 @@ def element_as_gdf(
When both network vertices and arcs are desired, the variable
declaration must be in the order: <vertices>, <arcs>.
This function requires ``geopandas``.
See also
--------
Expand Down
31 changes: 7 additions & 24 deletions spaghetti/util.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
from warnings import warn

import geopandas
import numpy
import pandas
import shapely
from libpysal import cg
from libpysal.common import requires
from rtree import Rtree

try:
import geopandas
import pandas
import shapely
from shapely.geometry import LineString
except ImportError:
warn(
"geopandas/shapely not available. Some functionality will be disabled.",
UserWarning,
stacklevel=1,
)
from shapely.geometry import LineString


def compute_length(v0, v1):
Expand Down Expand Up @@ -654,7 +643,6 @@ def build_chains(space_h, space_v, exterior, bounds, h=True):
return chains


@requires("geopandas", "shapely")
def _points_as_gdf(net, vertices, vertices_for_arcs, pp_name, snapped, id_col=None):
"""Internal function for returning a point ``geopandas.GeoDataFrame``
called from within ``spaghetti.element_as_gdf()``.
Expand Down Expand Up @@ -686,8 +674,7 @@ def _points_as_gdf(net, vertices, vertices_for_arcs, pp_name, snapped, id_col=No
Notes
-----
1. See ``spaghetti.element_as_gdf()`` for description of arguments.
2. This function requires ``geopandas``.
See ``spaghetti.element_as_gdf()`` for description of arguments.
"""

Expand Down Expand Up @@ -736,7 +723,6 @@ def _points_as_gdf(net, vertices, vertices_for_arcs, pp_name, snapped, id_col=No
return points


@requires("geopandas", "shapely")
def _arcs_as_gdf(net, points, id_col=None):
"""Internal function for returning an arc ``geopandas.GeoDataFrame``
called from within ``spaghetti.element_as_gdf()``.
Expand All @@ -751,8 +737,7 @@ def _arcs_as_gdf(net, points, id_col=None):
Notes
-----
1. See ``spaghetti.element_as_gdf()`` for description of arguments.
2. This function requires ``geopandas``.
See ``spaghetti.element_as_gdf()`` for description of arguments.
"""

Expand All @@ -776,7 +761,6 @@ def _line_coords(loc):
return arcs


@requires("geopandas", "shapely")
def _routes_as_gdf(paths, id_col):
"""Internal function for returning a shortest paths
``geopandas.GeoDataFrame`` called from within
Expand All @@ -793,8 +777,7 @@ def _routes_as_gdf(paths, id_col):
Notes
-----
1. See ``spaghetti.element_as_gdf()`` for description of arguments.
2. This function requires ``geopandas``.
See ``spaghetti.element_as_gdf()`` for description of arguments.
"""

Expand Down

0 comments on commit b463e1c

Please sign in to comment.