Skip to content

Commit

Permalink
fix(back): Fix formatting for new stable version of black (pixano#64)
Browse files Browse the repository at this point in the history
* fix(back): Fix formatting for new stable version of black

* fix(ci): Specify black formatter version
  • Loading branch information
cpvannier authored Jan 29, 2024
1 parent b1071ce commit a8bdf40
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,20 @@ jobs:
with:
options: "--check --verbose --diff --color"
src: "./pixano"
version: "~= 24.0"

- name: Format backend tests with black
uses: psf/black@stable
with:
options: "--check --verbose --diff --color"
src: "./tests"
jupyter: true
version: "~= 24.0"

- name: Format Jupyter notebooks with black
uses: psf/black@stable
with:
options: "--check --verbose --diff --color"
src: "./notebooks"
jupyter: true
version: "~= 24.0"
16 changes: 10 additions & 6 deletions pixano/data/dataset/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ def __init__(
path=path,
info=DatasetInfo.from_json(info_file),
stats=DatasetStat.from_json(stats_file) if stats_file.is_file() else None,
thumbnail=Image(uri=thumb_file.absolute().as_uri()).url
if thumb_file.is_file()
else None,
thumbnail=(
Image(uri=thumb_file.absolute().as_uri()).url
if thumb_file.is_file()
else None
),
)

@property
Expand Down Expand Up @@ -288,9 +290,11 @@ def update_table(
for feat in new_feats:
# None is not supported for booleans yet (should be fixed in pylance 0.9.1)
feat_array = pa.array(
[False] * len(table)
if feat.dtype == "bool"
else [None] * len(table),
(
[False] * len(table)
if feat.dtype == "bool"
else [None] * len(table)
),
type=field_to_pyarrow(feat.dtype),
)
new_feats_table = new_feats_table.append_column(
Expand Down
6 changes: 3 additions & 3 deletions pixano/data/exporters/coco_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ def _export_object(
# Category
category = {
"id": None,
"name": obj.features["category"].value
if "category" in obj.features
else None,
"name": (
obj.features["category"].value if "category" in obj.features else None
),
}
if category["name"] is not None:
for cat in self.dataset.info.categories:
Expand Down
24 changes: 14 additions & 10 deletions pixano/data/importers/coco_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,20 @@ def import_rows(self) -> Iterator:
"original_id": str(ann["id"]),
"item_id": item_id,
"view_id": "image",
"bbox": BBox.from_xywh(ann["bbox"])
.normalize(im["height"], im["width"])
.to_dict()
if ann["bbox"]
else None,
"mask": CompressedRLE.encode(
ann["segmentation"], im["height"], im["width"]
).to_dict()
if ann["segmentation"]
else None,
"bbox": (
BBox.from_xywh(ann["bbox"])
.normalize(im["height"], im["width"])
.to_dict()
if ann["bbox"]
else None
),
"mask": (
CompressedRLE.encode(
ann["segmentation"], im["height"], im["width"]
).to_dict()
if ann["segmentation"]
else None
),
"category": str(categories[ann["category_id"]]),
}
for ann in im_anns
Expand Down
4 changes: 1 addition & 3 deletions pixano/data/item/item_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ def to_pyarrow(self, mask: ItemURLE = None) -> BBox:
return (
BBox.from_dict(self.model_dump())
if self.coords != [0.0, 0.0, 0.0, 0.0]
else BBox.from_rle(mask.to_pyarrow())
if mask
else None
else BBox.from_rle(mask.to_pyarrow()) if mask else None
)


Expand Down
8 changes: 4 additions & 4 deletions pixano/models/inference_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ def process_dataset(
save_batch.extend(
self.preannotate(process_batch, views, uri_prefix, threshold)
if process_type == "obj"
else self.precompute_embeddings(
process_batch, views, uri_prefix
else (
self.precompute_embeddings(process_batch, views, uri_prefix)
if process_type in ["segment_emb", "search_emb"]
else []
)
if process_type in ["segment_emb", "search_emb"]
else []
)
progress.update(batch_size)

Expand Down

0 comments on commit a8bdf40

Please sign in to comment.