Skip to content

Fix nfev_fit int64 dtype lock crashing batch-saved ngmix output (#795)#802

Open
cailmdaley wants to merge 1 commit into
developfrom
fix/795-nfev-batch-dtype
Open

Fix nfev_fit int64 dtype lock crashing batch-saved ngmix output (#795)#802
cailmdaley wants to merge 1 commit into
developfrom
fix/795-nfev-batch-dtype

Conversation

@cailmdaley

Copy link
Copy Markdown
Contributor

Summary

  • compile_results filled the nfev_fit column with np.nan on failed fits — the only int-like output column with a float fallback.
  • With SAVE_BATCH enabled, save_results locks column dtypes from batch 1 (fresh save_as_fits write) and appends every later batch into a structured array typed to those locked dtypes. If batch 1 happens to have zero failed fits, nfev_fit locks to int64 (FITS 'K'); the first later batch containing a failed fit then feeds a NaN into that int64 column, raising ValueError: cannot convert float NaN to integer at append time — crashing tiles mid-run, exactly at a batch boundary as reported.
  • Fix: use ngmix's own -1 failed/absent-nfev sentinel (already documented in the adjacent comment) instead of np.nan. nfev_fit is now int64 with -1 meaning failed/absent, dtype-stable across every batch.

Test plan

  • New regression test test_save_results_batches_survive_a_later_failed_fit drives the real save_results over a two-batch sequence (batch 1 all-success, batch 2 with a failed fit type) — fails on develop with the exact reported crash at ngmix.py:612, passes with the fix.
  • tests/module/test_ngmix.py — 18 passed (in-container).
  • pytest -m "not slow" tests/science — 11 passed, no regressions.
  • Checked every nfev reference in the codebase — no consumer reads or NaN-masks the output column.

Fixes #795

— Claude Fable on behalf of Cail

🤖 Generated with Claude Code

https://claude.ai/code/session_01J9qEVRCWEekT5ACNB3rjkq

compile_results filled nfev_fit with np.nan on failed fits, the only
int-like column with a float fallback. With SAVE_BATCH enabled,
save_results locks column dtypes from batch 1; if that batch has no
failures the column locks to int64, and the first later batch with a
failure feeds NaN into it, raising "cannot convert float NaN to
integer" on append. Use ngmix's own -1 failed/absent-nfev sentinel
instead of NaN, keeping the column int64 across every batch.

Fixes #795
@cailmdaley cailmdaley mentioned this pull request Jul 10, 2026
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.

[BUG] ngmix crash

1 participant