Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/ndi/epoch/epochset.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,20 @@ def epochtable(
def _compute_hash(self, epochtable: list[dict[str, Any]]) -> str:
"""Compute hash of epoch table for cache validation."""

# Create a stable string representation
# Create a stable string representation. Objects with to_dict()
# (like ndi_epoch_epoch) already exclude circular back-references,
# so we prefer that. For anything else, fall back to repr()
# rather than blindly walking __dict__, which can hit cycles
# (e.g. epoch -> epochset_object -> epoch table -> epoch).
def make_hashable(obj):
if isinstance(obj, dict):
return tuple(sorted((k, make_hashable(v)) for k, v in obj.items()))
elif isinstance(obj, list):
elif isinstance(obj, (list, tuple)):
return tuple(make_hashable(x) for x in obj)
elif isinstance(obj, np.ndarray):
return tuple(obj.flatten().tolist())
elif hasattr(obj, "to_dict"):
return make_hashable(obj.to_dict())
elif hasattr(obj, "__dict__"):
return make_hashable(obj.__dict__)
else:
return obj

Expand Down
Loading