diff --git a/pyproject.toml b/pyproject.toml index e4385f1..98a8a51 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -80,7 +80,7 @@ line-length = 100 [tool.ruff.lint] select = [ - # "B", + "B", "E", "F", "FLY", @@ -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] diff --git a/spatialpandas/dask.py b/spatialpandas/dask.py index 94d6c95..cef8381 100644 --- a/spatialpandas/dask.py +++ b/spatialpandas/dask.py @@ -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') diff --git a/spatialpandas/geometry/base.py b/spatialpandas/geometry/base.py index dd1a897..bb4426f 100644 --- a/spatialpandas/geometry/base.py +++ b/spatialpandas/geometry/base.py @@ -72,7 +72,8 @@ 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()): @@ -80,8 +81,8 @@ def construct_from_string(cls, string): 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)) diff --git a/spatialpandas/geometry/baselist.py b/spatialpandas/geometry/baselist.py index ffe6fc1..006d1ec 100644 --- a/spatialpandas/geometry/baselist.py +++ b/spatialpandas/geometry/baselist.py @@ -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)" @@ -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 @@ -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() diff --git a/spatialpandas/io/utils.py b/spatialpandas/io/utils.py index 780bdc3..562867e 100644 --- a/spatialpandas/io/utils.py +++ b/spatialpandas/io/utils.py @@ -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( diff --git a/spatialpandas/tests/geometry/strategies.py b/spatialpandas/tests/geometry/strategies.py index d72afc1..2fe9424 100644 --- a/spatialpandas/tests/geometry/strategies.py +++ b/spatialpandas/tests/geometry/strategies.py @@ -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 @@ -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)) @@ -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)) @@ -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) @@ -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)) diff --git a/spatialpandas/tests/test_geodataframe.py b/spatialpandas/tests/test_geodataframe.py index 1b5a6c6..a867e67 100644 --- a/spatialpandas/tests/test_geodataframe.py +++ b/spatialpandas/tests/test_geodataframe.py @@ -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' diff --git a/spatialpandas/tools/sjoin.py b/spatialpandas/tools/sjoin.py index a0a00a6..e90aaa1 100644 --- a/spatialpandas/tools/sjoin.py +++ b/spatialpandas/tools/sjoin.py @@ -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(