|
10 | 10 | import pandas as pd |
11 | 11 | from gertils.types import NucleusNumber, TraceIdFrom0 |
12 | 12 | from numpydoc_decorator import doc # type: ignore[import-untyped] |
| 13 | +from pandas.errors import EmptyDataError |
13 | 14 |
|
14 | 15 | from .bounding_box import BoundingBox3D |
15 | 16 | from .point import FloatLike, Point3D |
@@ -119,12 +120,17 @@ def build_layers(folder) -> list[FullDataLayer]: # type: ignore[no-untyped-def] |
119 | 120 | for file_type, file_path in file_by_kind.items(): |
120 | 121 | logging.debug("Processing data for file type %s: %s", file_type.name, file_path) |
121 | 122 | 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() |
126 | 132 | ] |
127 | | - } |
| 133 | + rois_by_type = {MergeContributorRoi: parse_result} |
128 | 134 | elif file_type == InputFileContentType.NucleiLabeled: |
129 | 135 | rois_by_type = {} |
130 | 136 | for r in _parse_non_contributor_non_proximal_rois(file_path): |
@@ -300,7 +306,12 @@ def _parse_non_contributor_non_proximal_rois( |
300 | 306 | path: Path, |
301 | 307 | ) -> list[NonNuclearRoi | SingletonRoi | MergedRoi]: |
302 | 308 | 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(): |
304 | 315 | roiId, time, channel, box, traceId, trace_partners, maybe_nuc_num, maybe_id_and_contribs = ( |
305 | 316 | _parse_nucleus_labeled_record(row) |
306 | 317 | ) |
@@ -345,7 +356,11 @@ def _parse_non_contributor_non_proximal_rois( |
345 | 356 | def _parse_proximity_rejects( |
346 | 357 | path: Path, |
347 | 358 | ) -> 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 [] |
349 | 364 | return _parse_proximity_rejects_table(spot_data) |
350 | 365 |
|
351 | 366 |
|
|
0 commit comments