Skip to content

Commit fbdd0cb

Browse files
authored
Use Ruff for code formatting (#851)
Signed-off-by: Lukas Heumos <[email protected]>
1 parent 7c280b7 commit fbdd0cb

File tree

22 files changed

+45
-75
lines changed

22 files changed

+45
-75
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,10 @@ minimum_pre_commit_version: 2.16.0
88
ci:
99
skip: []
1010
repos:
11-
- repo: https://github.com/psf/black
12-
rev: 24.10.0
13-
hooks:
14-
- id: black
1511
- repo: https://github.com/rbubley/mirrors-prettier
1612
rev: v3.4.2
1713
hooks:
1814
- id: prettier
19-
- repo: https://github.com/asottile/blacken-docs
20-
rev: 1.19.1
21-
hooks:
22-
- id: blacken-docs
2315
- repo: https://github.com/pre-commit/mirrors-mypy
2416
rev: v1.14.1
2517
hooks:
@@ -31,3 +23,4 @@ repos:
3123
hooks:
3224
- id: ruff
3325
args: [--fix, --exit-non-zero-on-fix]
26+
- id: ruff-format

benchmarks/spatialdata_benchmark.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def time_map_blocks(self, _):
4444

4545

4646
class TimeQueries:
47-
4847
params = ([100, 1_000, 10_000], [True, False], [100, 1_000])
4948
param_names = ["length", "filter_table", "n_transcripts_per_cell"]
5049

benchmarks/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
- function run_benchmark is used to run the benchmarks.
99
1010
Performant dataset generation functions so the benchmarks run fast even for large artificial datasets.
11-
The object is to generate a dataset containing many cells. By copying the same cell values instead of
11+
The object is to generate a dataset containing many cells. By copying the same cell values instead of
1212
doing gaussian blur on the whole image, we can generate the same dataset in a fraction of the time.
1313
- function labeled_particles is used to generate labeled blobs.
1414
- function _generate_ball is used to generate a ball of given radius and dimension.

docs/extensions/typed_returns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def _process_return(lines):
1111
m = re.fullmatch(r"(?P<param>\w+)\s+:\s+(?P<type>[\w.]+)", line)
1212
if m:
1313
# Once this is in scanpydoc, we can use the fancy hover stuff
14-
yield f'-{m["param"]} (:class:`~{m["type"]}`)'
14+
yield f"-{m['param']} (:class:`~{m['type']}`)"
1515
else:
1616
yield line
1717

pyproject.toml

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -103,27 +103,6 @@ filterwarnings = [
103103
# "ignore:.*U.*mode is deprecated:DeprecationWarning",
104104
]
105105

106-
[tool.black]
107-
line-length = 120
108-
target-version = ['py310']
109-
include = '\.pyi?$'
110-
exclude = '''
111-
(
112-
/(
113-
\.eggs
114-
| \.git
115-
| \.hg
116-
| \.mypy_cache
117-
| \.tox
118-
| \.venv
119-
| _build
120-
| buck-out
121-
| build
122-
| dist
123-
)/
124-
)
125-
'''
126-
127106
[tool.jupytext]
128107
formats = "ipynb,md"
129108

@@ -148,6 +127,7 @@ exclude = [
148127
"docs/_build",
149128
"dist",
150129
"setup.py",
130+
151131
]
152132
line-length = 120
153133
target-version = "py310"

src/spatialdata/_core/operations/aggregate.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ def aggregate(
180180
ONES_KEY = None
181181
if value_key is None:
182182
ONES_KEY = "__ones_column_aggregate"
183-
assert (
184-
ONES_KEY not in values_.columns
185-
), f"Column {ONES_KEY} is reserved for internal use and cannot be already present in values_"
183+
assert ONES_KEY not in values_.columns, (
184+
f"Column {ONES_KEY} is reserved for internal use and cannot be already present in values_"
185+
)
186186
values_[ONES_KEY] = 1
187187
value_key = ONES_KEY
188188

@@ -384,10 +384,10 @@ def _aggregate_shapes(
384384
"agg_func='sum' instead."
385385
)
386386
assert not isinstance(values.iloc[0].geometry, Point), (
387-
"Fractions cannot be computed when values are points. " "Please use fractions=False."
387+
"Fractions cannot be computed when values are points. Please use fractions=False."
388388
)
389389
assert not (categorical and agg_func == "mean"), (
390-
"Incompatible choice: aggregating a categorical column with " "agg_func='mean'"
390+
"Incompatible choice: aggregating a categorical column with agg_func='mean'"
391391
)
392392

393393
# we need to add a column of ones to the values dataframe to be able to count the number of instances in each zone

src/spatialdata/_core/operations/rasterize.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -678,9 +678,9 @@ def rasterize_shapes_points(
678678
elif isinstance(agg_func, str):
679679
AGGREGATIONS = ["sum", "count", "count_cat", "first"]
680680

681-
assert np.isin(
682-
agg_func, AGGREGATIONS
683-
), f"Aggregation function must be one of {', '.join(AGGREGATIONS)}. Found {agg_func}"
681+
assert np.isin(agg_func, AGGREGATIONS), (
682+
f"Aggregation function must be one of {', '.join(AGGREGATIONS)}. Found {agg_func}"
683+
)
684684

685685
assert agg_func == "count" or value_key is not None, f"value_key cannot be done for agg_func={agg_func}"
686686

src/spatialdata/_core/operations/transform.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,9 @@ def _(
287287
if transformation is None and to_coordinate_system is not None:
288288
return data.transform_to_coordinate_system(target_coordinate_system=to_coordinate_system)
289289
raise RuntimeError(ERROR_MSG_AFTER_0_0_15)
290-
assert bool(transformation is None) != bool(
291-
to_coordinate_system is None
292-
), "When maintain_positioning is True, only one of transformation and to_coordinate_system can be None"
290+
assert bool(transformation is None) != bool(to_coordinate_system is None), (
291+
"When maintain_positioning is True, only one of transformation and to_coordinate_system can be None"
292+
)
293293
new_elements: dict[str, dict[str, Any]] = {}
294294
for element_type in ["images", "labels", "points", "shapes"]:
295295
d = getattr(data, element_type)

src/spatialdata/_core/operations/vectorize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def _(element: GeoDataFrame, **kwargs: Any) -> GeoDataFrame:
113113
return _make_circles(element, obs)
114114
if isinstance(element.geometry.iloc[0], Point):
115115
return element
116-
raise RuntimeError("Unsupported geometry type: " f"{type(element.geometry.iloc[0])}")
116+
raise RuntimeError(f"Unsupported geometry type: {type(element.geometry.iloc[0])}")
117117

118118

119119
@to_circles.register(DaskDataFrame)
@@ -281,7 +281,7 @@ def _(gdf: GeoDataFrame, buffer_resolution: int = 16) -> GeoDataFrame:
281281
return buffered_df
282282
assert isinstance(gdf.geometry.iloc[0], Polygon | MultiPolygon)
283283
return gdf
284-
raise RuntimeError("Unsupported geometry type: " f"{type(gdf.geometry.iloc[0])}")
284+
raise RuntimeError(f"Unsupported geometry type: {type(gdf.geometry.iloc[0])}")
285285

286286

287287
@to_polygons.register(DaskDataFrame)

src/spatialdata/_core/query/relational_query.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ def _filter_table_by_elements(
164164
"""
165165
assert set(elements_dict.keys()).issubset({"images", "labels", "shapes", "points"})
166166
assert len(elements_dict) > 0, "elements_dict must not be empty"
167-
assert any(
168-
len(elements) > 0 for elements in elements_dict.values()
169-
), "elements_dict must contain at least one dict which contains at least one element"
167+
assert any(len(elements) > 0 for elements in elements_dict.values()), (
168+
"elements_dict must contain at least one dict which contains at least one element"
169+
)
170170
if table is None:
171171
return None
172172
to_keep = np.zeros(len(table), dtype=bool)

0 commit comments

Comments
 (0)