Skip to content

Commit d09484f

Browse files
committed
robustness against empty data files, new version
1 parent 687ebd3 commit d09484f

4 files changed

Lines changed: 29 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [v0.5.6] - 2025-07-17
8+
9+
### Fixed
10+
* Now empty data files should cause no problem.
11+
712
## [v0.5.5] - 2025-05-23
813

914
### Fixed

looptrace_regionals_vis/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from numpydoc_decorator import doc # type: ignore[import-untyped]
1212

13-
__version__ = "0.5.5"
13+
__version__ = "0.5.6"
1414

1515
_PACKAGE_NAME = package = Path(__file__).parent.name
1616

looptrace_regionals_vis/reader.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import pandas as pd
1111
from gertils.types import NucleusNumber, TraceIdFrom0
1212
from numpydoc_decorator import doc # type: ignore[import-untyped]
13+
from pandas.errors import EmptyDataError
1314

1415
from .bounding_box import BoundingBox3D
1516
from .point import FloatLike, Point3D
@@ -119,12 +120,17 @@ def build_layers(folder) -> list[FullDataLayer]: # type: ignore[no-untyped-def]
119120
for file_type, file_path in file_by_kind.items():
120121
logging.debug("Processing data for file type %s: %s", file_type.name, file_path)
121122
if file_type == InputFileContentType.MergeContributors:
122-
rois_by_type = {
123-
MergeContributorRoi: [
124-
_parse_merge_contributor_record(row)
125-
for _, row in pd.read_csv(file_path).iterrows()
123+
parse_result: list[MergeContributorRoi]
124+
try:
125+
data = pd.read_csv(file_path)
126+
except EmptyDataError:
127+
logging.warning("Empty data file: %s", file_path)
128+
parse_result = []
129+
else:
130+
parse_result = [
131+
_parse_merge_contributor_record(row) for _, row in data.iterrows()
126132
]
127-
}
133+
rois_by_type = {MergeContributorRoi: parse_result}
128134
elif file_type == InputFileContentType.NucleiLabeled:
129135
rois_by_type = {}
130136
for r in _parse_non_contributor_non_proximal_rois(file_path):
@@ -300,7 +306,12 @@ def _parse_non_contributor_non_proximal_rois(
300306
path: Path,
301307
) -> list[NonNuclearRoi | SingletonRoi | MergedRoi]:
302308
rois: list[NonNuclearRoi | SingletonRoi | MergedRoi] = []
303-
for _, row in pd.read_csv(path).iterrows():
309+
try:
310+
data = pd.read_csv(path)
311+
except EmptyDataError:
312+
logging.warning("Empty data file: %s", path)
313+
return []
314+
for _, row in data.iterrows():
304315
roiId, time, channel, box, traceId, trace_partners, maybe_nuc_num, maybe_id_and_contribs = (
305316
_parse_nucleus_labeled_record(row)
306317
)
@@ -345,7 +356,11 @@ def _parse_non_contributor_non_proximal_rois(
345356
def _parse_proximity_rejects(
346357
path: Path,
347358
) -> list[tuple[RoiId, set[RoiId], Timepoint, Channel, BoundingBox3D]]:
348-
spot_data = pd.read_csv(path, index_col=None)
359+
try:
360+
spot_data = pd.read_csv(path, index_col=None)
361+
except EmptyDataError:
362+
logging.warning("Empty data file: %s", path)
363+
return []
349364
return _parse_proximity_rejects_table(spot_data)
350365

351366

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "looptrace-regionals-vis"
3-
version = "0.5.5"
3+
version = "0.5.6"
44
description = "This project facilitates viewing, in `napari`, regional spots from `looptrace`."
55
authors = ["Vince Reuter"]
66
license = "MIT"

0 commit comments

Comments
 (0)