Skip to content

Commit

Permalink
Merge pull request #660 from jGaboardi/noqa_colon_top_level
Browse files Browse the repository at this point in the history
correct in-line `ruff` syntax
  • Loading branch information
martinfleis authored Nov 19, 2023
2 parents 3816631 + c8d3c89 commit 9e45960
Show file tree
Hide file tree
Showing 56 changed files with 113 additions and 113 deletions.
4 changes: 2 additions & 2 deletions libpysal/cg/alpha_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def nb_dist(x, y):
1.4142135623730951
"""
sum_ = 0
for x_i, y_i in zip(x, y): # noqa B905
for x_i, y_i in zip(x, y): # noqa: B905
sum_ += (x_i - y_i) ** 2
dist = np.sqrt(sum_)
return dist
Expand Down Expand Up @@ -651,7 +651,7 @@ def _construct_centers(a, b, radius):
return down_x, down_y


def _filter_holes(geoms, points): # noqa ARG001
def _filter_holes(geoms, points): # noqa: ARG001
"""
Filter hole polygons using a computational geometry solution
"""
Expand Down
2 changes: 1 addition & 1 deletion libpysal/cg/locators.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ def nearest(self, query_point, rule="vertex"):
>>> try: n = pl.nearest(Point((-1, 1)))
... except NotImplementedError: print("future test: str(min(n.vertices())) == (0.0, 1.0)")
future test: str(min(n.vertices())) == (0.0, 1.0)
""" # noqa E501
""" # noqa: E501
raise NotImplementedError

def region(self, region_rect):
Expand Down
2 changes: 1 addition & 1 deletion libpysal/cg/ops/_accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
def get_attr(df, geom_col="geometry", inplace=False, attr=None):
outval = df[geom_col].apply(lambda x: x.__getattribute__(attr))
if inplace:
outcol = f"shape_{func.__name__}" # noqa F821
outcol = f"shape_{func.__name__}" # noqa: F821
df[outcol] = outval
return None
return outval
Expand Down
4 changes: 2 additions & 2 deletions libpysal/cg/ops/_shapely.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ def unary_union(df, geom_col="geometry", **groupby_kws):
level = groupby_kws.pop("level", None)
if by is not None or level is not None:
df = df.groupby(**groupby_kws)
out = df[geom_col].apply(_cascaded_union) # noqa F821
out = df[geom_col].apply(_cascaded_union) # noqa: F821
else:
out = _cascaded_union(df[geom_col].tolist()) # noqa F821
out = _cascaded_union(df[geom_col].tolist()) # noqa: F821
return out


Expand Down
4 changes: 2 additions & 2 deletions libpysal/cg/ops/tabular.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ def dissolve(df, by="", **groupby_kws):
return union(df, by=by, **groupby_kws)


def clip(return_exterior=False): # noqa ARG001
def clip(return_exterior=False): # noqa: ARG001
# return modified entries of the df that are within an envelope
# provide an option to null out the geometries instead of not returning
raise NotImplementedError


def erase(return_interior=True): # noqa ARG001
def erase(return_interior=True): # noqa: ARG001
# return modified entries of the df that are outside of an envelope
# provide an option to null out the geometries instead of not returning
raise NotImplementedError
Expand Down
8 changes: 4 additions & 4 deletions libpysal/cg/ops/tests/test_shapely.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ def setup_method(self):

def compare(self, func_name, df, **kwargs):
geom_list = df.geometry.tolist()
shefunc = she.__dict__[func_name] # noqa F821
shtfunc = sht.__dict__[func_name] # noqa F821
shefunc = she.__dict__[func_name] # noqa: F821
shtfunc = sht.__dict__[func_name] # noqa: F821

try:
she_vals = (shefunc(geom, **kwargs) for geom in geom_list)
sht_vals = shtfunc(df, inplace=False, **kwargs)
sht_list = sht_vals[f"shape_{func_name}"].tolist()
for tabular, shapely in zip(sht_list, she_vals, strict=True):
if comp.is_shape(tabular) and comp.is_shape(shapely): # noqa F821
comp.equal(tabular, shapely) # noqa F821
if comp.is_shape(tabular) and comp.is_shape(shapely): # noqa: F821
comp.equal(tabular, shapely) # noqa: F821
else:
assert tabular == shapely
except NotImplementedError as e:
Expand Down
2 changes: 1 addition & 1 deletion libpysal/cg/ops/tests/test_tabular.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from ....common import requires as _requires
from ....examples import get_path
from ....io import geotable as pdio
from ... import ops as GIS # noqa N812
from ... import ops as GIS # noqa: N812
from ...shapes import Polygon


Expand Down
8 changes: 4 additions & 4 deletions libpysal/cg/rtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def union_all(kids):
return cur


def Rtree(): # noqa N802
def Rtree(): # noqa: N802
return RTree()


Expand Down Expand Up @@ -416,7 +416,7 @@ class RTree:
>>> rt.intersection([5, 5, 6, 6])
[]
""" # noqa E501
""" # noqa: E501

def __init__(self):
self.count = 0
Expand Down Expand Up @@ -713,15 +713,15 @@ def walk(self, predicate):
def query_rect(self, r):
"""Yield objects that intersect with the rectangle (``r``)."""

def p(o, x): # noqa ARG001
def p(o, x): # noqa: ARG001
return r.does_intersect(o.rect)

yield from self.walk(p)

def query_point(self, point):
"""Yield objects that intersect with the point (``point``)."""

def p(o, x): # noqa ARG001
def p(o, x): # noqa: ARG001
return o.rect.does_containpoint(point)

yield from self.walk(p)
Expand Down
8 changes: 4 additions & 4 deletions libpysal/cg/segmentLocator.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def add(self, segment, id):
self._kd2 = None
return True

def remove(self, segment): # noqa ARG002
def remove(self, segment): # noqa: ARG002
self._kd = None
self._kd2 = None
pass
Expand Down Expand Up @@ -313,7 +313,7 @@ def nearest(self, pt):
cols[idx],
) # (i,j)'s of the filled grid cells within radius.

for t in zip(rows, cols): # noqa B905
for t in zip(rows, cols): # noqa: B905
possibles.update(self.hash[t])

if DEBUG:
Expand Down Expand Up @@ -363,7 +363,7 @@ def combo_check(bins, segments, qpoints):
DEBUG = False


def brute_check(segments, qpoints): # noqa ARG001
def brute_check(segments, qpoints): # noqa: ARG001
t0 = time.time()
g2 = BruteSegmentLocator(segs)
t1 = time.time()
Expand Down Expand Up @@ -417,7 +417,7 @@ def binSizeTest():
qpts = random_points(q)
for col, bins in enumerate(binSizes):
print("N, Bins:", n, bins)
qps = test_grid(bins, segs, qpts) # noqa F821
qps = test_grid(bins, segs, qpts) # noqa: F821
results[row, col] = qps
return results

Expand Down
4 changes: 2 additions & 2 deletions libpysal/cg/sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def linear2arcdist(linear_dist, radius=RADIUS_EARTH_KM):
return arc_dist


def toXYZ(pt): # noqa N802
def toXYZ(pt): # noqa: N802
"""Convert a point's latitude and longitude to x,y,z.
Parameters
Expand All @@ -190,7 +190,7 @@ def toXYZ(pt): # noqa N802
return x, y, z


def toLngLat(xyz): # noqa N802
def toLngLat(xyz): # noqa: N802
"""Convert a point's x,y,z to latitude and longitude.
Parameters
Expand Down
4 changes: 2 additions & 2 deletions libpysal/cg/standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ def get_rectangle_rectangle_intersection(r0, r1, checkOverlap=True):
>>> ri = get_rectangle_rectangle_intersection(r0,r1)
>>> ri[:] == r1[:]
True
""" # noqa E501
""" # noqa: E501

intersection = None
common_bb = True
Expand Down Expand Up @@ -634,7 +634,7 @@ def get_polygon_point_dist(poly, pt):
part_prox = []
for vertices in poly._vertices:
vx_range = range(-1, len(vertices) - 1)
seg = lambda i: LineSegment(vertices[i], vertices[i + 1]) # noqa B023
seg = lambda i: LineSegment(vertices[i], vertices[i + 1]) # noqa: B023
_min_dist = min([get_segment_point_dist(seg(i), pt)[0] for i in vx_range])
part_prox.append(_min_dist)
dist = min(part_prox)
Expand Down
2 changes: 1 addition & 1 deletion libpysal/cg/tests/test_sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest

from ... import examples as pysal_examples
from ...io.fileio import FileIO as psopen # noqa N813
from ...io.fileio import FileIO as psopen # noqa: N813
from .. import sphere


Expand Down
2 changes: 1 addition & 1 deletion libpysal/cg/voronoi.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def voronoi_frames(points, radius=None, clip="extent"):
>>> regions_df.shape == points_df.shape
True
""" # noqa E501
""" # noqa: E501

regions, vertices = voronoi(points, radius=radius)
regions, vertices = as_dataframes(regions, vertices, points)
Expand Down
6 changes: 3 additions & 3 deletions libpysal/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import copy

import pandas # noqa F401
import pandas # noqa: F401

try:
from patsy import PatsyError
Expand All @@ -23,7 +23,7 @@

except ImportError:

def jit(function=None, **kwargs): # noqa ARG001
def jit(function=None, **kwargs): # noqa: ARG001
"""Mimic numba.jit() with synthetic wrapper."""

if function is not None:
Expand Down Expand Up @@ -128,7 +128,7 @@ def inner(function):
return function
else:

def passer(*args, **kwargs): # noqa ARG001
def passer(*args, **kwargs): # noqa: ARG001
if v:
missing = [arg for i, arg in enumerate(wanted) if not available[i]]
print(f"missing dependencies: {missing}")
Expand Down
2 changes: 1 addition & 1 deletion libpysal/examples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def fetch_all():
example = datasets[name]
try:
example.download()
except: # noqa E722
except: # noqa: E722
print(f"Example not downloaded: {name}")
example_manager.add_examples(datasets)

Expand Down
8 changes: 4 additions & 4 deletions libpysal/examples/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def type_of_script() -> str:
"""Helper function to determine run context."""

try:
ipy_str = str(type(get_ipython())) # noqa F821
ipy_str = str(type(get_ipython())) # noqa: F821
if "zmqshell" in ipy_str:
return "jupyter"
if "terminal" in ipy_str:
Expand Down Expand Up @@ -217,7 +217,7 @@ def load(self, file_name) -> io.FileIO:
class Examples:
"""Manager for pysal example datasets."""

def __init__(self, datasets={}): # noqa B006
def __init__(self, datasets={}): # noqa: B006
self.datasets = datasets

def add_examples(self, examples):
Expand Down Expand Up @@ -269,7 +269,7 @@ def download_remotes(self):
example = self.remotes[name]
try:
example.download()
except: # noqa E722
except: # noqa: E722
print(f"Example not downloaded: {name}.")

def get_installed_names(self) -> list:
Expand All @@ -281,7 +281,7 @@ def get_remote_url(self, name):
if name in self.datasets:
try:
return self.datasets[name].download_url
except: # noqa E722
except: # noqa: E722
print(f"{name} is a built-in dataset, no url.")
else:
print(f"{name} is not an available dataset.")
Expand Down
4 changes: 2 additions & 2 deletions libpysal/examples/remotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,8 +644,8 @@ def _remote_data():
url = "https://geodacenter.github.io/data-and-lab//"
try:
page = requests.get(url)
except: # noqa E722
warnings.warn("Remote data sets not available. Check connection.") # noqa B028
except: # noqa: E722
warnings.warn("Remote data sets not available. Check connection.") # noqa: B028
return {}
soup = BeautifulSoup(page.text, "html.parser")
samples = soup.find(class_="samples")
Expand Down
2 changes: 1 addition & 1 deletion libpysal/examples/tests/test_available.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_data_home(self):
def test_data_home_fallback(self, path_exists_mock, makedirs_mock):
data_home = user_data_dir("pysal", "pysal")

def makedirs_side_effect(path, exist_ok=False): # noqa ARG001
def makedirs_side_effect(path, exist_ok=False): # noqa: ARG001
if path == data_home:
raise OSError(errno.EROFS)

Expand Down
2 changes: 1 addition & 1 deletion libpysal/graph/_triangulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
)

try:
from numba import njit # noqa E401
from numba import njit # noqa: E401

HAS_NUMBA = True
except ModuleNotFoundError:
Expand Down
2 changes: 1 addition & 1 deletion libpysal/graph/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def _build_coincidence_lookup(geoms):
"""
Identify coincident points and create a look-up table for the coincident geometries.
"""
valid_coincident_geom_types = set(("Point",)) # noqa C405
valid_coincident_geom_types = set(("Point",)) # noqa: C405
if not set(geoms.geom_type) <= valid_coincident_geom_types:
raise ValueError(
"coindicence checks are only well-defined for "
Expand Down
4 changes: 2 additions & 2 deletions libpysal/graph/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def adjacency(self):
return self._adjacency.copy()

@classmethod
def from_W(cls, w): # noqa N802
def from_W(cls, w): # noqa: N802
"""Create an experimental Graph from libpysal.weights.W object
Parameters
Expand All @@ -179,7 +179,7 @@ def from_W(cls, w): # noqa N802
"""
return cls.from_weights_dict(dict(w))

def to_W(self): # noqa N802
def to_W(self): # noqa: N802
"""Convert Graph to a libpysal.weights.W object
Returns
Expand Down
4 changes: 2 additions & 2 deletions libpysal/graph/tests/test_set_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ def test___gt__(self):

def test___eq__(self):
assert self.distance2500 == self.distance2500.copy()
assert not self.distance2500 == self.distance2500_id # noqa SIM201
assert not self.distance2500 == self.distance2500_id # noqa: SIM201

def test___ne__(self):
assert not self.distance2500 != self.distance2500.copy() # noqa SIM202
assert not self.distance2500 != self.distance2500.copy() # noqa: SIM202
assert self.distance2500 != self.distance2500_id

def test___and__(self):
Expand Down
2 changes: 1 addition & 1 deletion libpysal/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
from .tables import *
from .util import *

open = fileio.FileIO # noqa A001
open = fileio.FileIO # noqa: A001
2 changes: 1 addition & 1 deletion libpysal/io/fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def check(cls):
print(f"Ext: '.{key}', Modes: {list(val.keys())!r}")

@classmethod
def open(cls, *args, **kwargs): # noqa A001
def open(cls, *args, **kwargs): # noqa: A001
"""Alias for ``FileIO()``."""

return cls(*args, **kwargs)
Expand Down
4 changes: 2 additions & 2 deletions libpysal/io/iohandlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@

try:
from . import db
except: # noqa E722
warnings.warn("SQLAlchemy not installed, database I/O disabled") # noqa B028
except: # noqa: E722
warnings.warn("SQLAlchemy not installed, database I/O disabled") # noqa: B028
2 changes: 1 addition & 1 deletion libpysal/io/iohandlers/arcgis_dbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _get_varName(self):

varName = property(fget=_get_varName, fset=_set_varName)

def read(self, n=-1): # noqa ARG002
def read(self, n=-1): # noqa: ARG002
self._complain_ifclosed(self.closed)
return self._read()

Expand Down
Loading

0 comments on commit 9e45960

Please sign in to comment.