Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Bugbear Ruff #154

Merged
merged 4 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ line-length = 100

[tool.ruff.lint]
select = [
# "B",
"B",
"E",
"F",
"FLY",
Expand Down Expand Up @@ -119,7 +119,6 @@ extend-unsafe-fixes = [
[tool.ruff.lint.per-file-ignores]
"spatialpandas/tests/**" = [
"NPY002", # Replace legacy `np.random.rand` call with Generator
# "B904", # Within an `except` clause, raise exceptions with from err or None
]

[tool.ruff.lint.isort]
Expand Down
2 changes: 1 addition & 1 deletion spatialpandas/dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ def write_metadata_file():
# Build spatial metadata for parquet dataset
partition_bounds = {}
for col, bounds in all_bounds.items():
partition_bounds[col] = pd.DataFrame(all_bounds[col]).to_dict()
partition_bounds[col] = pd.DataFrame(bounds).to_dict()

spatial_metadata = {'partition_bounds': partition_bounds}
b_spatial_metadata = json.dumps(spatial_metadata).encode('utf')
Expand Down
7 changes: 4 additions & 3 deletions spatialpandas/geometry/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,17 @@ def construct_from_string(cls, string):
raise AttributeError
except AttributeError:
raise TypeError(
f"'construct_from_string' expects a string, got {type(string)}")
f"'construct_from_string' expects a string, got {type(string)}"
) from None

msg = f"Cannot construct a '{cls.__name__}' from '{{}}'"
if string.startswith(cls._geometry_name.lower()):
# Extract subtype
try:
subtype_string = cls._parse_subtype(string)
return cls(subtype_string)
except Exception:
raise TypeError(msg.format(string))
except Exception as e:
raise TypeError(msg.format(string)) from e
else:
raise TypeError(msg.format(string))

Expand Down
6 changes: 3 additions & 3 deletions spatialpandas/geometry/baselist.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def _validate_nested_arrow_type(nesting_levels, pyarrow_type):
return pa.null()

pyarrow_element_type = pyarrow_type
for i in range(nesting_levels):
for _ in range(nesting_levels):
if not isinstance(pyarrow_element_type, pa.ListType):
raise ValueError(
f"Expected input data to have {nesting_levels} nested layer(s)"
Expand Down Expand Up @@ -192,7 +192,7 @@ def _arrow_type_from_numpy_element_dtype(cls, dtype):
arrow_dtype = pa.from_numpy_dtype(dtype)

# Wrap dtype with appropriate number of nesting levels
for i in range(cls._nesting_levels):
for _ in range(cls._nesting_levels):
arrow_dtype = pa.list_(arrow_dtype)

return arrow_dtype
Expand All @@ -202,7 +202,7 @@ def _numpy_element_dtype_from_arrow_type(self, pyarrow_type):
return pa.null()

pyarrow_element_type = pyarrow_type
for i in range(self._nesting_levels):
for _ in range(self._nesting_levels):
pyarrow_element_type = pyarrow_element_type.value_type

return pyarrow_element_type.to_pandas_dtype()
Expand Down
4 changes: 2 additions & 2 deletions spatialpandas/io/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def validate_coerce_filesystem(
else:
try:
return fsspec.filesystem(filesystem, **fsspec_opts)
except ValueError:
except ValueError as e:
raise ValueError(
f"Received invalid filesystem value with type: {type(filesystem)}"
)
) from e


def _maybe_prepend_protocol(
Expand Down
12 changes: 6 additions & 6 deletions spatialpandas/tests/geometry/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
def st_point_array(draw, min_size=0, max_size=30, geoseries=False):
n = draw(st.integers(min_size, max_size))
points = []
for i in range(n):
for _ in range(n):
x_mid = draw(st.floats(-50, 50))
y_mid = draw(st.floats(-50, 50))
point = (np.random.rand(2) - 0.5) * 5
Expand All @@ -51,7 +51,7 @@ def st_point_array(draw, min_size=0, max_size=30, geoseries=False):
def st_multipoint_array(draw, min_size=0, max_size=30, geoseries=False):
n = draw(st.integers(min_size, max_size))
lines = []
for i in range(n):
for _ in range(n):
num_points = draw(st.integers(1, 10))
x_mid = draw(st.floats(-50, 50))
y_mid = draw(st.floats(-50, 50))
Expand All @@ -70,7 +70,7 @@ def st_multipoint_array(draw, min_size=0, max_size=30, geoseries=False):
def st_line_array(draw, min_size=0, max_size=30, geoseries=False):
n = draw(st.integers(min_size, max_size))
lines = []
for i in range(n):
for _ in range(n):
line_len = draw(st.integers(2, 10))
x_mid = draw(st.floats(-50, 50))
y_mid = draw(st.floats(-50, 50))
Expand Down Expand Up @@ -105,7 +105,7 @@ def st_ring_array(draw, min_size=3, max_size=30, geoseries=False):
assert min_size >= 3
n = draw(st.integers(min_size, max_size))
rings = []
for i in range(n):
for _ in range(n):
rings.append(sg.LinearRing(get_unique_points(n)))

result = from_shapely(rings)
Expand All @@ -118,10 +118,10 @@ def st_ring_array(draw, min_size=3, max_size=30, geoseries=False):
def st_multiline_array(draw, min_size=0, max_size=5, geoseries=False):
n = draw(st.integers(min_size, max_size))
multilines = []
for i in range(n):
for _ in range(n):
m = draw(st.integers(1, 5))
lines = []
for j in range(m):
for _ in range(m):
line_len = draw(st.integers(2, 3))
x_mid = draw(st.floats(-50, 50))
y_mid = draw(st.floats(-50, 50))
Expand Down
2 changes: 1 addition & 1 deletion spatialpandas/tests/test_geodataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_active_geometry(use_dask):
# Select columns not including active geometry
selected_gdf = gdf[['a', 'points']]
with pytest.raises(ValueError):
selected_gdf.geometry
selected_gdf.geometry # noqa: B018

assert selected_gdf.set_geometry('points').geometry.name == 'points'

Expand Down
2 changes: 1 addition & 1 deletion spatialpandas/tools/sjoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def _sjoin_dask_pandas(

# Build list of delayed sjoin results
joined_dfs = []
for df, (i, bounds) in zip(dfs, partition_bounds.iterrows()):
for df, (_idx, bounds) in zip(dfs, partition_bounds.iterrows()):
right_inds = right_sindex.intersects(bounds.values)
if how == "left" or len(right_inds) > 0:
joined_dfs.append(
Expand Down