Skip to content

fix: clear errors instead of crashes in analyses, stats and utils - #315

Merged
Ramdam17 merged 5 commits into
masterfrom
fix/small-fixes-analyses-stats-utils
Oct 4, 2026
Merged

Ramdam17 merged 5 commits into
masterfrom
fix/small-fixes-analyses-stats-utils

Conversation

@Ramdam17

@Ramdam17 Ramdam17 commented Oct 4, 2026 •

Copy link
Copy Markdown
Collaborator

What this does

Eight small defects found by the October audit, all of the same kind: a call that crashed obscurely or reported the wrong cause now says what is wrong. No call that worked before returns a different value.

hypyp/analyses.py

  • compute_sync rewrote every ValueError as Metric type "..." not supported, so optimization='bogus' was reported as "plv not supported". Only an unknown metric name gets that message now; any other error keeps its own (pair_connectivity cannot forward optimization/priority, and compute_sync masks all compute errors as "metric not supported" #306).
  • pair_connectivity called squeeze() on the multitaper signal. With a frequency list and a single epoch, a single channel per participant, or a single frequency such as [10, 11], a dimension disappeared and the next line raised IndexError. The squeeze() is removed; it did nothing when no dimension had length one.

hypyp/utils.py

  • normalizing raised UnboundLocalError for a type other than 'Zscore' or 'Logratio'; it raises a ValueError naming the two valid types.
  • generate_virtual_epoch failed inside the solver for an odd number of channels; it raises a ValueError, and its docstring example, which used three oscillators, uses four.
  • epochs_from_tasks failed with min() iterable argument is empty when the onset event of a task was absent from the recording; the ValueError names the task and the event.
  • create_epochs warns when the two participants give different numbers of epochs, or different numbers of recordings. It returns what it returned before.

hypyp/stats.py

  • statscluster raised UnboundLocalError for an unknown test; it raises a ValueError listing the valid names.
  • metaconn_matrix gains plot=True. The default draws as before; plot=False only computes.

Measured

  • 16 new tests, written first; none needs a download. The test of pair_connectivity on a dimension of length one compares the result with a PLV written from its definition.
  • Whole suite on macOS arm64, Python 3.12: 325 passed, 42 skipped, 0 failed.
  • 112 arrays produced by the touched functions on ordinary inputs (the nine metrics through pair_connectivity with a list and a dictionary of frequencies, compute_nmPLV, normalizing, the cluster wrappers with tail 0 and 1, metaconn_matrix, create_epochs, epochs_from_tasks, generate_virtual_epoch with a fixed seed) are bit-identical between master and this branch, shapes and dtypes included.

Withdrawn after review

Two repairs were in the first version and were taken out, because each made a failing call return numbers that are not established as correct.

statscluster(test='f multipleway') raises a TypeError on master and still does.

🤖 Generated with Claude Code

Ramdam17 and others added 3 commits October 4, 2026 09:18
…rors

compute_sync reports only an unknown metric as unsupported and lets any
other ValueError through. pair_connectivity and compute_nmPLV no longer
squeeze the multitaper signal, which broke a single epoch, channel or
frequency. statscluster raises a ValueError for an unknown test, runs the
two t-tests with tail=-1 and refuses tail=-1 for F tests, as does
statscondCluster. metaconn_matrix gains a plot argument that defaults to
True.

Outputs for inputs that worked before are bit-identical to master.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
normalizing raises a ValueError for an unknown type, generate_virtual_epoch
for an odd channel count, and epochs_from_tasks for an onset event absent
from the recording. create_epochs warns when the two participants give
different numbers of epochs and still returns both lists.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.

Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.

Ramdam17 and others added 2 commits October 4, 2026 10:08
compute_nmPLV goes back to what master does: its values are the subject of
#310, so making it run on a single epoch or channel would only produce new
wrong numbers. The lower tail of the cluster tests is left for the work on
cluster statistics: the call already succeeded for alpha >= 0.5, and the
paired test permutes without keeping the pairs. statscluster keeps only the
clear error for an unknown test.

create_epochs also warns when the two lists of recordings differ in length,
and no longer recommends equalising the counts, which does not make epochs
correspond in time. The singleton-dimension test of pair_connectivity
compares against a PLV written from its definition, and the normalizing
test checks the Zscore and Logratio values.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@Ramdam17
Ramdam17 merged commit 60ba3d8 into master Oct 4, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant