Skip to content

Find a run's project file, not just its folder, when loading by run number (#931) - #1089

Draft
fanchercm wants to merge 11 commits into
nextfrom
fix/931-missing-run-file
Draft

fanchercm wants to merge 11 commits into
nextfrom
fix/931-missing-run-file

Conversation

@fanchercm

@fanchercm fanchercm commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

On hold (draft): waiting for the NXstress phase 2 PR #1027 to merge first.
#1026 (phase 1) has merged, and this branch already includes it.

  • Conflicts resolved: the combine-runs window and three GUI test files.
  • One test change: NXstress hookup: phase 1 #1026's test stand-in for load_combine_projects now returns 1, as the real method does.
  • Deferred defect DD-11 records the declined texture fix; NXstress hookup: phase 1 #1026 already fixed the peak-fitting half.

The review fixes are pushed: texture run-number parsing, combine runs (parsing, ranges, export and Browse cancel) and lookup errors in all four windows. After #1027 merges, this branch will be rebased, re-tested and re-reviewed before it is marked ready.

Summary

Loading by run number crashed with a 'NoneType' object has no attribute … error when a run was in the database but its project file had never been reduced, or couldn't be found.

Root cause: get_input_project_file(run) returned shared/manualreduce or shared/autoreduce as soon as the folder existed, without checking that HB2B_<run>.h5 was in it. The load then failed, and both windows carried on into the empty workspace:

  • peak fitting: load_and_plot → get_subruns_limit;
  • texture fitting: load_project_plot → model.sub_runs.

Changes (each approved individually)

  • A. The run lookup checks for the file. get_input_project_file returns a folder only if it holds HB2B_<run>.h5.
    • "manual" preferred: manualreduce, then autoreduce. "auto": autoreduce only.
    • Otherwise it raises RuntimeError, naming the file and the folders searched ("has the run been reduced yet?"). The peak-fitting and texture windows already show that in a pop-up.
  • D. Combine runs by run number works.
    • It used to pass the lookup's folders on as project files, so it never worked. It now uses <folder>/HB2B_<run>.h5.
    • loadRunNumbers shows lookup errors in a pop-up. Without that, A would have made a missing run an unhandled error in the slot.

Effect: no computed value changes. When the preferred folder holds the run's file, the lookup returns the same folder as before. A run only in autoreduce now loads from there with "manual" preferred. A run that was never reduced gets a clear message instead of a crash.

Not included

Both windows still continue after a load that fails for another reason, e.g. a file picked in the file dialog that isn't a project file. Making them stop was proposed but not approved; it's recorded in docs/ground_truths.md. For run numbers, A stops a missing file before any load is attempted.

Tests

  • tests/unit/pyrs/utilities/test_input_project_file.py: a synthetic shared/{manualreduce,autoreduce} tree, covering the preferred folder, the fallback to autoreduce, and missing files.
  • tests/unit/pyrs/interface/combine_runs/test_combine_runs_crtl.py: run numbers become project-file paths, and a missing run raises.
  • tests/ui/test_merge_projectfiles.py::test_load_missing_run_number_reports: a missing run shows a pop-up.
  • The tests for the lookup change and for combine runs fail without the fix.
  • The existing combine-runs GUI test passes, as do ruff, mypy (pixi run mypy pyrs scripts tests) and the pre-commit hooks.
  • The archive-based test_get_input_project_file (skipped without /HFIR) now also requires HB2B_1060.h5 to be in IPTS-22731's manualreduce.

Closes #931

🤖 Generated with Claude Code

…umber (#931)

get_input_project_file returned shared/manualreduce or autoreduce as soon
as the folder existed, even without HB2B_<run>.h5; the load then failed
and the windows went on into a NoneType crash. It now returns the folder
that holds the run's file (manual, then auto; auto only), or raises a
RuntimeError naming the file and folders, which the windows show.

Combine runs by run number passed those folders on as project files and
never worked: it now uses <folder>/HB2B_<run>.h5, and loadRunNumbers
shows lookup errors in a pop-up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
Pre-merge checks: Passed 1 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Title check Pending This assessment has not completed. The check will be retried on the next pre-merge check run.
Passed Passed checks: 1 passed

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…rors

- Texture window: parse the run number once, so " 1060" or "01060"
  loads HB2B_1060.h5, the file the lookup checked.
- Combine runs: Python ints (np.int16 overflowed above 32767); a range
  a:b includes b, and a range with more than two ends is refused; a run
  that cannot be found raises instead of being silently dropped
  (FileNotFoundError is now shown); fewer than two runs says so (and
  clears the choice) instead of exporting a previous combination or
  crashing; a new combine forgets the previous one; cancelling Browse or
  the save dialog does nothing.
- NeXus lookup: finddata's CalledProcessError and an empty FileFinder
  result become RuntimeError; the peak-fitting, texture, combine-runs and
  manual-reduction windows show it in a pop-up.
- Tests: the real lookup over a synthetic shared/ tree; combine by run
  number end to end on real data; the #931 crash path in peak fitting;
  padded run numbers in texture; manual reduction's unknown run; the
  archive test checks the file.

Defects recorded, not fixed:
- Peak-fitting load_and_plot and texture load_project_plot continue
  after a project file fails to load (e.g. a non-project file picked in
  the file dialog) into a NoneType error; proposed and declined (#931).
  To be added to docs/deferred_defects.md once #1026 brings that file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fanchercm
fanchercm marked this pull request as draft November 10, 2026 18:16
fanchercm and others added 7 commits November 10, 2026 14:18
# Conflicts:
#	tests/ui/test_peak_fitting.py
#	tests/ui/test_texture_fitting.py
…file

Conflicts resolved:
- combine_runs_viewer.py: keep #1026's saveFileDialogNXstress and its
  `-> None` on loadRunNumbers, with #931's error handling in it.
- tests/ui (merge_projectfiles, peak_fitting, texture_fitting): keep both
  sides' new tests.

#1026's test_load_project_files_auto_prompt_calls_both_save_dialogs_in_order
stubbed load_combine_projects to return None; with #931's check that a
combine happened (fewer than two runs -> error dialog) the stub now
returns 1, as the real method does, instead of hanging on a modal dialog.

Defects recorded, not fixed:
- DD-11: the peak-fitting and texture windows carry on after a project
  file fails to load, into a NoneType error (proposed and declined, #931).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ing half

Since #1026, PeakFittingViewer.load_and_plot returns after a failed load
and records current_hidra_file_name only on success, which is the fix B
that #931 proposed. DD-11 and the #931 ground-truths section now say so.

Defects recorded, not fixed:
- DD-11: the texture-fitting window carries on after a project file fails
  to load (proposed and declined, #931).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… lookup notes

Tests (no production change):
- test_combine_by_run_number cleared the shared window's combination
  first; it passed even with loading switched off. It now resets the
  model, asserts the exact run files and messages, and uses two ranges.
- test_single_run_does_not_offer_export stubs both export dialogs and
  gives the model a workspace with geometry, so a regression fails
  instead of hanging on a modal dialog.
- New: bad run entries show one error (GUI); a failed combine clears
  the previous combination (unit).
- NeXus lookup tests go through the public get_nexus_file.
- Manual reduction test checks the lookup's message reaches the user.
- Window state (typed text, chosen files, file name) is restored after
  each test; runs are linked or stubbed instead of copied.

Docs: DD-11 describes the texture window's mixed state accurately; the
NeXus lookup note says an empty result falls back to finddata. The
manual-reduction comment no longer cites a nonexistent defect number.

Defects recorded, not fixed:
- DD-11: the texture-fitting window carries on after a project file
  fails to load (proposed and declined, #931).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…der; unreadable files reported

Each approved separately, from the second review of #1089:
- gui_helper.parse_integers: a range includes its end, as in combine
  runs and manual reduction ("1327:1330" was 3 runs in peak fitting,
  4 elsewhere). Affects the peak-fitting run and sub-run boxes;
  selection only, no computed value changes.
- Combine runs: runs keep the order typed (it numbers the combined
  file's sub-runs), a repeated run is combined once, and empty entries
  (a trailing comma) are skipped.
- Combine runs' load_project_files also reports OSError (missing or
  non-HDF5 file) and KeyError (not a project file) instead of letting
  them escape the Qt slot.
- Peak fitting's load_run_number parses the run box inside its try, so
  text such as "abc" is reported.
- Type hints on get_input_project_file and the combine-runs parsers.
- Tests for each, each failing without its change; parse_integers'
  test now asserts its results.

Defects recorded, not fixed:
- DD-11: the texture-fitting window carries on after a project file
  fails to load (proposed and declined, #931).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…oxes; record DD-12 to DD-14

The 2D-plot sub-run box selects 0-based array positions (never the
first), so "1:5" now plots sub-runs 2-6 for a file numbered 1..N (it was
2-5), not sub-run 5 as the ground truths said; the plot-sub-runs box
mixes positions (one entry) and numbers (several). Kept for all three
boxes (owner's decision with the corrected effect).

Defects recorded, not fixed:
- DD-12: peak fitting's sub-run boxes disagree on positions vs numbers;
  the 2D box can never plot the first sub-run.
- DD-13: a missing sub-run in plot_diff_data raises IndexError, which
  escapes the Qt slot.
- DD-14: CombineRunsModel.combine_project_files leaks a project-file
  handle when reading its record fails, and keeps a partial workspace
  after a failed append (latent).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fanchercm and others added 2 commits November 13, 2026 16:49
Conflicts with #1027 (in next) resolved:
- texture_fitting_viewer: next's load_project_plot(path) is called with #931's validated run_number
- test_merge_projectfiles: the stand-in combine returns 1 (#931's count) on next's three-sub-run workspace;
  minimal_HidraWorkspace now requires sub_runs
- test_peak_fitting: both new tests kept
- test_texture_fitting: the load_project_plot stand-in records the path it is given (new signature)
- docs: both sides kept; this branch's DD-11..14 unchanged

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	docs/deferred_defects.md
#	docs/ground_truths.md
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.

Errors when pyRS loads data and a NoneType is returned

1 participant