Skip to content

Commit

Permalink
use nme check_for_errors_in_dkt_values for improve error data when fa…
Browse files Browse the repository at this point in the history
…il to import data
  • Loading branch information
Czaki committed Apr 11, 2022
1 parent f3f0782 commit eedfb10
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions package/PartSegCore/_old_json_hooks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import nme
import numpy as np
from napari.utils import Colormap

Expand Down Expand Up @@ -90,6 +91,10 @@ def part_hook(dkt):
dkt["measurement_profile"] = dkt["statistic_profile"]
del dkt["statistic_profile"]
except Exception as e: # pylint: disable=W0703
problematic_fields = nme.check_for_errors_in_dkt_values(dkt2)
if problematic_fields:
dkt2["__error__"] = f"Error in fields: {', '.join(problematic_fields)}"
return dkt2
dkt = dkt2
dkt["__error__"] = str(e)

Expand Down Expand Up @@ -149,6 +154,10 @@ def profile_hook(dkt):
dkt["colors"].append(dkt["colors"][-1])
return Colormap(**dkt)
except Exception as e: # pylint: disable=W0703
problematic_fields = nme.check_for_errors_in_dkt_values(dkt2)
if problematic_fields:
dkt2["__error__"] = f"Error in fields: {', '.join(problematic_fields)}"
return dkt2
dkt = dkt2
dkt["__error__"] = str(e)

Expand Down
4 changes: 4 additions & 0 deletions package/PartSegCore/json_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def partseg_object_hook(dkt: dict):
return nme.nme_object_hook(dkt)

if "__ReadOnly__" in dkt or "__Serializable__" in dkt or "__Enum__" in dkt:
problematic_fields = nme.check_for_errors_in_dkt_values(dkt)
if problematic_fields:
dkt["__error__"] = f"Error in fields: {', '.join(problematic_fields)}"
return dkt
is_enum = "__Enum__" in dkt
for el in ("__Enum__", "__Serializable__", "__ReadOnly__"):
dkt.pop(el, None)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ install_requires =
magicgui>=0.3.3
mahotas>=1.4.9
napari>=0.4.8
nme>=0.1.3
nme>=0.1.4
numpy>=1.18.0
oiffile>=2020.1.18
openpyxl>=2.4.9
Expand Down

0 comments on commit eedfb10

Please sign in to comment.