Skip to content

Commit

Permalink
Merge pull request #444 from jGaboardi/GH438_lint_format_maint
Browse files Browse the repository at this point in the history
re- lint & re-format repo – #438
  • Loading branch information
gegen07 authored Mar 18, 2024
2 parents 4f507bc + b5b8130 commit f8a12e9
Show file tree
Hide file tree
Showing 24 changed files with 210 additions and 226 deletions.
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: "spopt\/"
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
9 changes: 4 additions & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand All @@ -9,7 +8,6 @@
# import your package to obtain the version info to display on the docs website
import spopt


# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
Expand Down Expand Up @@ -46,7 +44,7 @@

# General information about the project.
project = "spopt"
copyright = "2020-, pysal developers"
copyright = "2020-, pysal developers" # noqa: A001
author = "pysal developers"

# The version info for the project you're documenting, acts as replacement for
Expand Down Expand Up @@ -85,7 +83,8 @@
html_theme_path = sphinx_bootstrap_theme.get_html_theme_path()
html_title = f"{project} v{version} Manual"

# (Optional) Logo of your package. Should be small enough to fit the navbar (ideally 24x24).
# (Optional) Logo of your package.
# Should be small enough to fit the navbar (ideally 24x24).
# Path should be relative to the ``_static`` files directory.
# html_logo = "_static/images/package_logo.jpg"

Expand Down Expand Up @@ -299,7 +298,7 @@ def setup(app):
\nbsphinxstartnotebook{\scriptsize\noindent\strut
\textcolor{gray}{The following section was generated from
\sphinxcode{\sphinxupquote{\strut {{ docname | escape_latex }}}} \dotfill}}
"""
""" # noqa: E501

# This is processed by Jinja2 and inserted after each notebook
nbsphinx_epilog = r"""
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ include = ["spopt", "spopt.*"]

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

[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
1 change: 1 addition & 0 deletions spopt/region/components.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Checking for connected components in a graph.
"""

__author__ = "Sergio J. Rey <srey@asu.edu>"


Expand Down
1 change: 1 addition & 0 deletions spopt/region/csgraph_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[compressed sparse graph routines](
https://docs.scipy.org/doc/scipy/reference/sparse.csgraph.html).
"""

import numpy as np
from scipy.sparse import csgraph as csg
from scipy.sparse import csr_matrix
Expand Down
2 changes: 1 addition & 1 deletion spopt/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pytest
import warnings

import geopandas
import numpy
import pytest
import shapely

from spopt.locate.util import simulated_geo_points
Expand Down
3 changes: 1 addition & 2 deletions spopt/tests/test_azp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import libpysal
import geopandas
import libpysal
import numpy

from packaging.version import Version

from spopt.region import AZP
Expand Down
33 changes: 17 additions & 16 deletions spopt/tests/test_c_p_median.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
from spopt.locate.base import (
FacilityModelBuilder,
LocateSolver,
T_FacModel,
SpecificationError,
)
import os

import numpy
import pandas
import geopandas
import pulp
import spaghetti
import pytest

from spopt.locate import PMedian
from spopt.locate.util import simulated_geo_points
import pytest
import os
from spopt.locate.base import (
SpecificationError,
)


class TestSyntheticLocate:
Expand Down Expand Up @@ -160,9 +155,12 @@ def test_infeasibility_predefined_facilities_fulfillment_error(self):
schools_priority_3_arr = numpy.array(schools_priority_3)
with pytest.raises(
SpecificationError,
match="Problem is infeasible. The predefined facilities can't be fulfilled, ",
match=(
"Problem is infeasible. "
"The predefined facilities can't be fulfilled, "
),
):
pmedian = PMedian.from_cost_matrix(
PMedian.from_cost_matrix(
self.cost_matrix,
self.demand,
self.p_facility,
Expand All @@ -174,9 +172,12 @@ def test_infeasibility_predefined_facilities_fulfillment_error(self):
def test_no_capacity_data_predefined_facilities_error(self):
with pytest.raises(
SpecificationError,
match="Data on the capacity of the facility is missing, so the model cannot be calculated.",
match=(
"Data on the capacity of the facility is missing, "
"so the model cannot be calculated."
),
):
pmedian = PMedian.from_cost_matrix(
PMedian.from_cost_matrix(
self.cost_matrix,
self.demand,
self.p_facility,
Expand All @@ -190,7 +191,7 @@ def test_infeasibility_capacity_smaller_than_demand_error(self):
SpecificationError,
match="Problem is infeasible. The highest possible capacity",
):
pmedian = PMedian.from_cost_matrix(
PMedian.from_cost_matrix(
self.cost_matrix,
demand_test,
self.p_facility,
Expand Down
7 changes: 3 additions & 4 deletions spopt/tests/test_clscp-so.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# ruff: noqa: N999

import numpy
import geopandas
import pulp
import spaghetti
import pytest

from spopt.locate import LSCP
from spopt.locate.util import simulated_geo_points
import pytest


class TestSyntheticLocate:
Expand Down
17 changes: 6 additions & 11 deletions spopt/tests/test_knearest_p_median.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import numpy
import geopandas
import pandas
import numpy
import pulp
import pytest
from shapely.geometry import Point

from spopt.locate.p_median import KNearestPMedian
from spopt.locate.base import SpecificationError
import os
import pickle
import platform
import pytest
import warnings
from spopt.locate.p_median import KNearestPMedian


class TestKNearestPMedian:
Expand Down Expand Up @@ -50,11 +45,11 @@ def test_knearest_p_median_from_geodataframe_no_results(self):
assert isinstance(result, KNearestPMedian)

with pytest.raises(AttributeError):
result.cli2fac
result.cli2fac # noqa: B018
with pytest.raises(AttributeError):
result.fac2cli
result.fac2cli # noqa: B018
with pytest.raises(AttributeError):
result.mean_dist
result.mean_dist # noqa: B018

def test_solve(self):
self.k_nearest_pmedian.solve(self.solver)
Expand Down
2 changes: 1 addition & 1 deletion spopt/tests/test_locate_util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
import spaghetti

from spopt.locate.util import simulated_geo_points


Expand Down
41 changes: 19 additions & 22 deletions spopt/tests/test_lscp.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
from spopt.locate.base import FacilityModelBuilder
import numpy
import os
import pickle
import platform
import warnings

import geopandas
import numpy
import pandas
import pulp
import spaghetti
import pytest
from shapely.geometry import Point, Polygon

from spopt.locate import LSCP
from spopt.locate.util import simulated_geo_points
import os
import pickle
import platform
import pytest
import warnings
from spopt.locate.base import FacilityModelBuilder

operating_system = platform.platform()[:7].lower()
if operating_system == "windows":
WINDOWS = True
else:
WINDOWS = False
WINDOWS = platform.platform()[:7].lower() == "windows"


class TestSyntheticLocate:
Expand All @@ -44,9 +39,9 @@ def test_lscp_from_cost_matrix_no_results(self):
assert isinstance(result, LSCP)

with pytest.raises(AttributeError):
result.cli2fac
result.cli2fac # noqa: B018
with pytest.raises(AttributeError):
result.fac2cli
result.fac2cli # noqa: B018

def test_lscp_facility_client_array_from_cost_matrix(self):
with open(self.dirpath + "lscp_fac2cli.pkl", "rb") as f:
Expand Down Expand Up @@ -254,13 +249,15 @@ def test_attribute_error_add_set_covering_constraint(self):
)

def test_error_lscp_different_crs(self):
with pytest.warns(
UserWarning, match="Facility geodataframe contains mixed type"
with (
pytest.warns(
UserWarning, match="Facility geodataframe contains mixed type"
),
pytest.raises(ValueError, match="Geodataframes crs are different: "),
):
with pytest.raises(ValueError, match="Geodataframes crs are different: "):
LSCP.from_geodataframe(
self.gdf_dem_crs, self.gdf_fac, "geometry", "geometry", 10
)
LSCP.from_geodataframe(
self.gdf_dem_crs, self.gdf_fac, "geometry", "geometry", 10
)

def test_warning_lscp_demand_geodataframe(self):
with pytest.warns(UserWarning, match="Demand geodataframe contains mixed type"):
Expand Down
44 changes: 22 additions & 22 deletions spopt/tests/test_lscpb.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import numpy
import os
import pickle
import warnings

import geopandas
import numpy
import pandas
import pulp
import spaghetti
import pytest
from shapely.geometry import Point, Polygon

from spopt.locate import LSCPB
from spopt.locate.base import FacilityModelBuilder
from spopt.locate.util import simulated_geo_points

import os
import pickle
import warnings
import pytest


class TestSyntheticLocate:
Expand Down Expand Up @@ -47,11 +45,11 @@ def test_lscpb_from_cost_matrix_no_results(self):
assert isinstance(result, LSCPB)

with pytest.raises(AttributeError):
result.cli2fac
result.cli2fac # noqa: B018
with pytest.raises(AttributeError):
result.fac2cli
result.fac2cli # noqa: B018
with pytest.raises(AttributeError):
result.backup_perc
result.backup_perc # noqa: B018

def test_lscpb_facility_client_array_from_cost_matrix(self):
with open(self.dirpath + "lscpb_fac2cli.pkl", "rb") as f:
Expand Down Expand Up @@ -278,18 +276,20 @@ def setup_method(self) -> None:
self.gdf_dem_buffered["geometry"] = self.gdf_dem.buffer(2)

def test_error_lscpb_different_crs(self):
with pytest.warns(
UserWarning, match="Facility geodataframe contains mixed type"
with (
pytest.warns(
UserWarning, match="Facility geodataframe contains mixed type"
),
pytest.raises(ValueError, match="Geodataframes crs are different: "),
):
with pytest.raises(ValueError, match="Geodataframes crs are different: "):
LSCPB.from_geodataframe(
self.gdf_dem_crs,
self.gdf_fac,
"geometry",
"geometry",
10,
pulp.PULP_CBC_CMD(msg=False),
)
LSCPB.from_geodataframe(
self.gdf_dem_crs,
self.gdf_fac,
"geometry",
"geometry",
10,
pulp.PULP_CBC_CMD(msg=False),
)

def test_warning_lscpb_demand_geodataframe(self):
with pytest.warns(UserWarning, match="Demand geodataframe contains mixed type"):
Expand Down
5 changes: 2 additions & 3 deletions spopt/tests/test_maxp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import libpysal
import numpy
import pytest
from packaging.version import Version
from shapely.geometry import box

from spopt.region import MaxPHeuristic
from spopt.region.base import (
form_single_component,
Expand All @@ -11,9 +13,6 @@
plot_components,
)

from packaging.version import Version


# see gh:spopt#437
LIBPYSAL_GE_48 = Version(libpysal.__version__) >= Version("4.8.0")
w_kwargs = {"use_index": True} if LIBPYSAL_GE_48 else {}
Expand Down
Loading

0 comments on commit f8a12e9

Please sign in to comment.