Skip to content

Commit

Permalink
address new ruff failures (#360)
Browse files Browse the repository at this point in the history
* address new ruff failures

* proper stacklevel

* update precommit

* revisit stacklevels
  • Loading branch information
jGaboardi authored Apr 9, 2023
1 parent af3dca5 commit c66cf64
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
files: 'spopt\/'
repos:
- repo: https://github.com/psf/black
rev: 23.1.0
rev: 23.3.0
hooks:
- id: black
language_version: python3
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.257"
rev: "v0.0.261"
hooks:
- id: ruff

Expand Down
12 changes: 6 additions & 6 deletions spopt/locate/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,11 +424,11 @@ def from_geodataframe(
"sure deriving centroid from geometries doesn't affect the results."
)
if len(dem_type_geom) > 1 or "Point" not in dem_type_geom:
warnings.warn(f"Demand{_msg}", UserWarning)
warnings.warn(f"Demand{_msg}", UserWarning, stacklevel=2)
dem = dem.centroid

if len(fac_type_geom) > 1 or "Point" not in fac_type_geom:
warnings.warn(f"Facility{_msg}", UserWarning)
warnings.warn(f"Facility{_msg}", UserWarning, stacklevel=2)
fac = fac.centroid

dem_data = np.array([dem.x.to_numpy(), dem.y.to_numpy()]).T
Expand Down Expand Up @@ -866,11 +866,11 @@ def from_geodataframe(
"sure deriving centroid from geometries doesn't affect the results."
)
if len(dem_type_geom) > 1 or "Point" not in dem_type_geom:
warnings.warn(f"Demand{_msg}", UserWarning)
warnings.warn(f"Demand{_msg}", UserWarning, stacklevel=2)
dem = dem.centroid

if len(fac_type_geom) > 1 or "Point" not in fac_type_geom:
warnings.warn(f"Facility{_msg}", UserWarning)
warnings.warn(f"Facility{_msg}", UserWarning, stacklevel=2)
fac = fac.centroid

dem_data = np.array([dem.x.to_numpy(), dem.y.to_numpy()]).T
Expand Down Expand Up @@ -1312,11 +1312,11 @@ def from_geodataframe(
"sure deriving centroid from geometries doesn't affect the results."
)
if len(dem_type_geom) > 1 or "Point" not in dem_type_geom:
warnings.warn(f"Demand{_msg}", UserWarning)
warnings.warn(f"Demand{_msg}", UserWarning, stacklevel=2)
dem = dem.centroid

if len(fac_type_geom) > 1 or "Point" not in fac_type_geom:
warnings.warn(f"Facility{_msg}", UserWarning)
warnings.warn(f"Facility{_msg}", UserWarning, stacklevel=2)
fac = fac.centroid

dem_data = np.array([dem.x.to_numpy(), dem.y.to_numpy()]).T
Expand Down
4 changes: 2 additions & 2 deletions spopt/locate/p_center.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,11 @@ def from_geodataframe(
"sure deriving centroid from geometries doesn't affect the results."
)
if len(dem_type_geom) > 1 or "Point" not in dem_type_geom:
warnings.warn(f"Demand{_msg}", UserWarning)
warnings.warn(f"Demand{_msg}", UserWarning, stacklevel=2)
dem = dem.centroid

if len(fac_type_geom) > 1 or "Point" not in fac_type_geom:
warnings.warn(f"Facility{_msg}", UserWarning)
warnings.warn(f"Facility{_msg}", UserWarning, stacklevel=2)
fac = fac.centroid

dem_data = np.array([dem.x.to_numpy(), dem.y.to_numpy()]).T
Expand Down
1 change: 1 addition & 0 deletions spopt/locate/p_dispersion.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ def from_geodataframe(
"geometries doesn't affect the results."
),
UserWarning,
stacklevel=2,
)
fac = fac.centroid

Expand Down
4 changes: 2 additions & 2 deletions spopt/locate/p_median.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,11 @@ def from_geodataframe(
"sure deriving centroid from geometries doesn't affect the results."
)
if len(dem_type_geom) > 1 or "Point" not in dem_type_geom:
warnings.warn(f"Demand{_msg}", UserWarning)
warnings.warn(f"Demand{_msg}", UserWarning, stacklevel=2)
dem = dem.centroid

if len(fac_type_geom) > 1 or "Point" not in fac_type_geom:
warnings.warn(f"Facility{_msg}", UserWarning)
warnings.warn(f"Facility{_msg}", UserWarning, stacklevel=2)
fac = fac.centroid

dem_data = np.array([dem.x.to_numpy(), dem.y.to_numpy()]).T
Expand Down
5 changes: 3 additions & 2 deletions spopt/region/skater.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def __init__(
"Both the `affinity` and `dissimilarity` arguments "
"were passed in. Defaulting `dissimilarity`.",
UserWarning,
stacklevel=3,
)
affinity = None

Expand Down Expand Up @@ -170,7 +171,7 @@ def fit(
warnings.warn(
f"By default, the graph is disconnected! {chosen_warning}",
OptimizeWarning,
stacklevel=2,
stacklevel=3,
)
if not ignoring_islands:
n_clusters += current_n_subtrees
Expand Down Expand Up @@ -214,7 +215,7 @@ def fit(
f"{n_clusters - current_n_subtrees} subtrees."
),
OptimizeWarning,
stacklevel=2,
stacklevel=3,
)
self.current_labels_ = current_labels
self.minimum_spanning_forest_ = MSF
Expand Down
5 changes: 3 additions & 2 deletions spopt/region/spenclib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ def check_weights(W, X=None):
components, labels = csg.connected_components(graph)
if components > 1:
warn(
"Spatial affinity matrix is disconnected, and has {} subcomponents."
"This will certainly affect the solution output."
f"Spatial affinity matrix is disconnected, and has {components} "
"subcomponents. This will certainly affect the solution output.",
stacklevel=3,
)
return W

Expand Down

0 comments on commit c66cf64

Please sign in to comment.