Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (pysal#736)
Browse files Browse the repository at this point in the history
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.3.5 → v0.5.0](astral-sh/ruff-pre-commit@v0.3.5...v0.5.0)

* fix errors

* format

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Martin Fleischmann <martin@martinfleischmann.net>
  • Loading branch information
pre-commit-ci[bot] and martinfleis authored Jul 2, 2024
1 parent a5fe4c0 commit 01c1f80
Show file tree
Hide file tree
Showing 37 changed files with 67 additions and 74 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: "libpysal\/"
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.3.5"
rev: "v0.5.0"
hooks:
- id: ruff
- id: ruff-format
Expand Down
15 changes: 5 additions & 10 deletions libpysal/cg/kdtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ def count_neighbors(self, other, r, p=2):
if r > 0.5 * self.circumference:
raise ValueError(
"r, must not exceed 1/2 circumference of the sphere (%f)."
% self.circumference
* 0.5
% (self.circumference * 0.5)
)
r = sphere.arcdist2linear(r, self.radius)
return temp_KDTree.count_neighbors(self, other, r)
Expand Down Expand Up @@ -208,8 +207,7 @@ def query_ball_point(self, x, r, p=2, eps=0):
if r > 0.5 * self.circumference:
raise ValueError(
"r, must not exceed 1/2 circumference of the sphere (%f)."
% self.circumference
* 0.5
% (self.circumference * 0.5)
)
r = sphere.arcdist2linear(r, self.radius) + FLOAT_EPS * 3
return temp_KDTree.query_ball_point(self, self._toXYZ(x), r, eps=eps)
Expand Down Expand Up @@ -248,8 +246,7 @@ def query_ball_tree(self, other, r, p=2, eps=0):
if r > 0.5 * self.circumference:
raise ValueError(
"r, must not exceed 1/2 circumference of the sphere (%f)."
% self.circumference
* 0.5
% (self.circumference * 0.5)
)
r = sphere.arcdist2linear(r, self.radius) + FLOAT_EPS * 3
return temp_KDTree.query_ball_tree(self, other, r, eps=eps)
Expand Down Expand Up @@ -277,8 +274,7 @@ def query_pairs(self, r, p=2, eps=0):
if r > 0.5 * self.circumference:
raise ValueError(
"r, must not exceed 1/2 circumference of the sphere (%f)."
% self.circumference
* 0.5
% (self.circumference * 0.5)
)
r = sphere.arcdist2linear(r, self.radius) + FLOAT_EPS * 3
return temp_KDTree.query_pairs(self, r, eps=eps)
Expand Down Expand Up @@ -311,8 +307,7 @@ def sparse_distance_matrix(self, other, max_distance, p=2):
if max_distance > 0.5 * self.circumference:
raise ValueError(
"max_distance, must not exceed 1/2 circumference of the sphere (%f)."
% self.circumference
* 0.5
% (self.circumference * 0.5)
)
max_distance = sphere.arcdist2linear(max_distance, self.radius) + FLOAT_EPS * 3
d = temp_KDTree.sparse_distance_matrix(self, other, max_distance)
Expand Down
6 changes: 3 additions & 3 deletions libpysal/cg/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def asShape(obj):
geo = obj.__geo_interface__ if hasattr(obj, "__geo_interface__") else obj

if hasattr(geo, "type"):
raise TypeError("%r does not appear to be a shape object." % (obj))
raise TypeError(f"{obj!r} does not appear to be a shape object.")

geo_type = geo["type"].lower()

Expand All @@ -68,7 +68,7 @@ def asShape(obj):
if geo_type in _geoJSON_type_to_Pysal_type:
obj = _geoJSON_type_to_Pysal_type[geo_type].__from_geo_interface__(geo)
else:
raise NotImplementedError("%s is not supported at this time." % geo_type)
raise NotImplementedError(f"{geo_type} is not supported at this time.")

return obj

Expand Down Expand Up @@ -942,7 +942,7 @@ def __from_geo_interface__(cls, geo: dict):
elif geo["type"].lower() == "multilinestring":
verts = [list(map(Point, part)) for part in geo["coordinates"]]
else:
raise TypeError("%r is not a Chain." % geo)
raise TypeError(f"{geo!r} is not a Chain.")
return cls(verts)

@property
Expand Down
2 changes: 1 addition & 1 deletion libpysal/cg/standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,7 @@ def distance_matrix(X, p=2.0, threshold=5e7):
X.shape = (X.shape[0], 1)

if X.ndim > 2:
msg = "Should be 2D point coordinates: %s dimensions present." % X.ndim
msg = f"Should be 2D point coordinates: {X.ndim} dimensions present."
raise TypeError(msg)

n, k = X.shape
Expand Down
18 changes: 9 additions & 9 deletions libpysal/cg/tests/test_segmentLocator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ def setup_method(self):

def test_nearest_1(self):
# Center
assert [0, 1, 2, 3] == self.grid.nearest(Point((5.0, 5.0)))
assert self.grid.nearest(Point((5.0, 5.0))) == [0, 1, 2, 3]
# Left Edge
assert [0] == self.grid.nearest(Point((0.0, 5.0)))
assert self.grid.nearest(Point((0.0, 5.0))) == [0]
# Top Edge
assert [1] == self.grid.nearest(Point((5.0, 10.0)))
assert self.grid.nearest(Point((5.0, 10.0))) == [1]
# Right Edge
assert [2] == self.grid.nearest(Point((10.0, 5.0)))
assert self.grid.nearest(Point((10.0, 5.0))) == [2]
# Bottom Edge
assert [3] == self.grid.nearest(Point((5.0, 0.0)))
assert self.grid.nearest(Point((5.0, 0.0))) == [3]

def test_nearest_2(self):
# Left Edge
assert [0, 1, 3] == self.grid.nearest(Point((-100000.0, 5.0)))
assert self.grid.nearest(Point((-100000.0, 5.0))) == [0, 1, 3]
# Right Edge
assert [1, 2, 3] == self.grid.nearest(Point((100000.0, 5.0)))
assert self.grid.nearest(Point((100000.0, 5.0))) == [1, 2, 3]
# Bottom Edge
assert [0, 2, 3] == self.grid.nearest(Point((5.0, -100000.0)))
assert self.grid.nearest(Point((5.0, -100000.0))) == [0, 2, 3]
# Top Edge
assert [0, 1, 2] == self.grid.nearest(Point((5.0, 100000.0)))
assert self.grid.nearest(Point((5.0, 100000.0))) == [0, 1, 2]
4 changes: 1 addition & 3 deletions libpysal/graph/_set_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ def intersects(self, right):
intersection = self._adjacency.index.drop(self.isolates).intersection(
right._adjacency.index.drop(right.isolates)
)
if len(intersection) > 0:
return True
return False
return len(intersection) > 0

def intersection(self, right):
"""
Expand Down
4 changes: 1 addition & 3 deletions libpysal/graph/_spatial_lag.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ def _check_ties(focal):
"""

max_count = focal.weight.max()
if (focal.weight == max_count).sum() > 1:
return True
return False
return (focal.weight == max_count).sum() > 1


def _get_categorical_lag(focal, ties="random"):
Expand Down
4 changes: 2 additions & 2 deletions libpysal/io/fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def cast(self, key, typ):
except AssertionError:
raise TypeError("Cast objects must be callable.") from None
else:
raise KeyError("%s" % key)
raise KeyError(f"{key}")

def _cast(self, row) -> list:
"""
Expand All @@ -294,7 +294,7 @@ def _cast(self, row) -> list:
r = []
for f, v in zip(self._spec, row, strict=True):
try:
if not v and f != str:
if not v and not isinstance(f, str):
raise ValueError
r.append(f(v))
except ValueError:
Expand Down
2 changes: 1 addition & 1 deletion libpysal/io/iohandlers/arcgis_dbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def write(self, obj, useIdIndex=False):
self.pos = self.file.pos

else:
raise TypeError("Expected a PySAL weights object, got: %s." % (type(obj)))
raise TypeError(f"Expected a PySAL weights object, got: {type(obj)}.")

def flush(self):
self._complain_ifclosed(self.closed)
Expand Down
2 changes: 1 addition & 1 deletion libpysal/io/iohandlers/arcgis_swm.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def write(self, obj, useIdIndex=False): # noqa: N803
self._complain_ifclosed(self.closed)

if not issubclass(type(obj), W):
raise TypeError("Expected a PySAL weights object, got: %s." % (type(obj)))
raise TypeError(f"Expected a PySAL weights object, got: {type(obj)}.")

if (type(obj.id_order[0]) not in (np.int32, np.int64, int)) and not useIdIndex:
raise TypeError("ArcGIS SWM files support only integer IDs.")
Expand Down
4 changes: 2 additions & 2 deletions libpysal/io/iohandlers/arcgis_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ def write(self, obj, useIdIndex=False): # noqa: N803
id2i = obj.id2i
obj = remap_ids(obj, id2i)

header = "%s\n" % self.varName
header = f"{self.varName}\n"
self.file.write(header)
self._writelines(obj)
else:
raise TypeError("Expected a PySAL weights object, got: %s." % (type(obj)))
raise TypeError(f"Expected a PySAL weights object, got: {type(obj)}.")
2 changes: 1 addition & 1 deletion libpysal/io/iohandlers/dat.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,4 @@ def write(self, obj):
if issubclass(type(obj), W):
self._writelines(obj)
else:
raise TypeError("Expected a PySAL weights object, got: %s." % (type(obj)))
raise TypeError(f"Expected a PySAL weights object, got: {type(obj)}.")
2 changes: 1 addition & 1 deletion libpysal/io/iohandlers/gal.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def write(self, obj):
self.file.write(" ".join(map(str, neighbors)) + "\n")
self.pos += 1
else:
raise TypeError("Expected a PySAL weights object, got: %s." % (type(obj)))
raise TypeError(f"Expected a PySAL weights object, got: {type(obj)}.")

def close(self):
self.file.close()
Expand Down
6 changes: 3 additions & 3 deletions libpysal/io/iohandlers/geobugs_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,13 @@ def write(self, obj):
weights.extend(obj.weights[i])

self.file.write("list(")
self.file.write("num=c(%s)," % ",".join(map(str, cardinalities)))
self.file.write("adj=c(%s)," % ",".join(map(str, neighbors)))
self.file.write("num=c({}),".format(",".join(map(str, cardinalities))))
self.file.write("adj=c({}),".format(",".join(map(str, neighbors))))
self.file.write("sumNumNeigh=%i)" % sum(cardinalities))
self.pos += 1

else:
raise TypeError("Expected a PySAL weights object, got: %s." % (type(obj)))
raise TypeError(f"Expected a PySAL weights object, got: {type(obj)}.")

def close(self):
self.file.close()
Expand Down
2 changes: 1 addition & 1 deletion libpysal/io/iohandlers/gwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def write(self, obj):
self._writelines(obj)

else:
raise TypeError("Expected a PySAL weights object, got: %s." % (type(obj)))
raise TypeError(f"Expected a PySAL weights object, got: {type(obj)}.")

def close(self):
self.file.close()
Expand Down
2 changes: 1 addition & 1 deletion libpysal/io/iohandlers/mat.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def write(self, obj):
sio.savemat(self.file, {"WEIGHT": w})
self.pos += 1
else:
raise TypeError("Expected a PySAL weights object, got: %s." % (type(obj)))
raise TypeError(f"Expected a PySAL weights object, got: {type(obj)}.")

def close(self):
self.file.close()
Expand Down
2 changes: 1 addition & 1 deletion libpysal/io/iohandlers/mtx.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def write(self, obj):
)
self.pos += 1
else:
raise TypeError("Expected a PySAL weights object, got: %s." % (type(obj)))
raise TypeError(f"Expected a PySAL weights object, got: {type(obj)}.")

def close(self):
self.file.close()
Expand Down
2 changes: 1 addition & 1 deletion libpysal/io/iohandlers/pyDbfIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def _get_col(self, key: str) -> list:
"""

if key not in self._col_index:
raise AttributeError("Field: %s does not exist in header." % key)
raise AttributeError(f"Field: {key} does not exist in header.")

prevPos = self.tell()
idx, offset = self._col_index[key]
Expand Down
2 changes: 1 addition & 1 deletion libpysal/io/iohandlers/pyShpIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def __writer(self, shape):
"""

if TYPE_TO_STRING[type(shape)] != self.type:
raise TypeError("This file only supports %s type shapes." % self.type)
raise TypeError(f"This file only supports {self.type} type shapes.")

rec = {}
rec["Shape Type"] = shp_file.SHAPE_TYPES[self.type]
Expand Down
6 changes: 3 additions & 3 deletions libpysal/io/iohandlers/stata_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def write(self, obj, matrix_form=False):
self._complain_ifclosed(self.closed)

if issubclass(type(obj), W):
header = "%s\n" % obj.n
header = f"{obj.n}\n"
self.file.write(header)
if matrix_form:

Expand All @@ -271,9 +271,9 @@ def wgt2line(obs_id, neighbor, _):

for id_ in obj.id_order:
line = wgt2line(id_, obj.neighbors[id_], obj.weights[id_])
self.file.write("%s\n" % " ".join(line))
self.file.write("{}\n".format(" ".join(line)))
else:
raise TypeError("Expected a PySAL weights object, got: %s." % (type(obj)))
raise TypeError(f"Expected a PySAL weights object, got: {type(obj)}.")

def close(self):
self.file.close()
Expand Down
4 changes: 2 additions & 2 deletions libpysal/io/iohandlers/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def foobar(c):
self.pos += 1

else:
raise TypeError("Expected a string, got: %s." % (type(obj)))
raise TypeError(f"Expected a string, got: {type(obj)}.")

# default is to raise "NotImplementedError"
def flush(self):
Expand Down Expand Up @@ -150,7 +150,7 @@ def write(self, obj):
self.fileObj.write(result + "\n")
self.pos += 1
else:
raise TypeError("Expected a string, got: %s" % (type(obj)))
raise TypeError(f"Expected a string, got: {type(obj)}")

def flush(self):
self._complain_ifclosed(self.closed)
Expand Down
2 changes: 1 addition & 1 deletion libpysal/io/iohandlers/tests/test_arcgis_dbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_read(self):
)
assert w.n == 88
assert w.mean_neighbors == 5.25
assert [1.0, 1.0, 1.0, 1.0] == list(w[1].values())
assert list(w[1].values()) == [1.0, 1.0, 1.0, 1.0]

def test_seek(self):
self.test_read()
Expand Down
2 changes: 1 addition & 1 deletion libpysal/io/iohandlers/tests/test_arcgis_swm.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_read(self):
w = self.obj.read()
assert w.n == 88
assert w.mean_neighbors == 5.25
assert [1.0, 1.0, 1.0, 1.0] == list(w[1].values())
assert list(w[1].values()) == [1.0, 1.0, 1.0, 1.0]

def test_seek(self):
self.test_read()
Expand Down
2 changes: 1 addition & 1 deletion libpysal/io/iohandlers/tests/test_arcgis_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_read(self):
) in str(warn[0].message)
assert w.n == 3
assert w.mean_neighbors == 2.0
assert [0.1, 0.05] == list(w[2].values())
assert list(w[2].values()) == [0.1, 0.05]

def test_seek(self):
self.test_read()
Expand Down
2 changes: 1 addition & 1 deletion libpysal/io/iohandlers/tests/test_dat.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_read(self):
w = self.obj.read()
assert w.n == 49
assert w.mean_neighbors == 4.7346938775510203
assert [0.5, 0.5] == list(w[5.0].values())
assert list(w[5.0].values()) == [0.5, 0.5]

def test_seek(self):
self.test_read()
Expand Down
2 changes: 1 addition & 1 deletion libpysal/io/iohandlers/tests/test_gal.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def setup_method(self):
self.obj = GalIO(test_file, "r")

def test___init__(self):
assert self.obj._typ == str
assert self.obj._typ == str # noqa: E721

def test_close(self):
f = self.obj
Expand Down
4 changes: 2 additions & 2 deletions libpysal/io/iohandlers/tests/test_geobugs_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def test_read(self):
w_scot = self.obj_scot.read()
assert w_scot.n == 56
assert w_scot.mean_neighbors == 4.1785714285714288
assert [1.0, 1.0, 1.0] == list(w_scot[1].values())
assert list(w_scot[1].values()) == [1.0, 1.0, 1.0]

w_col = self.obj_col.read()
assert w_col.n == 49
assert w_col.mean_neighbors == 4.6938775510204085
assert [0.5, 0.5] == list(w_col[1].values())
assert list(w_col[1].values()) == [0.5, 0.5]

def test_seek(self):
self.test_read()
Expand Down
2 changes: 1 addition & 1 deletion libpysal/io/iohandlers/tests/test_gwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_read(self):
assert w.n == 168
assert w.mean_neighbors == 16.678571428571427
w.transform = "B"
assert [1.0] == list(w[1].values())
assert list(w[1].values()) == [1.0]

def test_seek(self):
self.test_read()
Expand Down
2 changes: 1 addition & 1 deletion libpysal/io/iohandlers/tests/test_mat.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_read(self):
w = self.obj.read()
assert w.n == 46
assert w.mean_neighbors == 4.0869565217391308
assert [1.0, 1.0, 1.0, 1.0] == list(w[1].values())
assert list(w[1].values()) == [1.0, 1.0, 1.0, 1.0]

def test_seek(self):
self.test_read()
Expand Down
Loading

0 comments on commit 01c1f80

Please sign in to comment.