Skip to content

fix: warn when dataset contains NaN values before bitinfo calculation - #345

Open
0x5t4l1n wants to merge 2 commits into
observingClouds:mainfrom
0x5t4l1n:fix/nan-preflight-warning
Open

0x5t4l1n wants to merge 2 commits into
observingClouds:mainfrom
0x5t4l1n:fix/nan-preflight-warning

Conversation

@0x5t4l1n

@0x5t4l1n 0x5t4l1n commented Aug 2, 2026

Copy link
Copy Markdown

Summary

Fixes #200 — NaN values in input arrays cause BitInformation to produce inaccurate results with no indication to the user.

Fix in xbitinfo/xbitinfo.py:

  • Add _check_for_nans(ds) that issues one UserWarning per affected variable with the NaN count
  • Called at the top of get_bitinformation() before any computation
  • Suppressible with warnings.filterwarnings("ignore", category=UserWarning, module="xbitinfo")

Test plan

  • ds = xr.Dataset({"a": xr.DataArray([1.0, float("nan"), 3.0])}); xb.get_bitinformation(ds) → UserWarning raised
  • Clean dataset → no warning

0x5t4l1n and others added 2 commits August 3, 2026 00:59
Resolves observingClouds#200. NaN values in input arrays cause BitInformation to
produce inaccurate or unexpected results with no indication to the user.
Add _check_for_nans() that issues a UserWarning per variable listing the
NaN count, called at the entry point of get_bitinformation() before any
computation begins. Users who intentionally pass NaN-masked data can
suppress with warnings.filterwarnings.
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.

Check for NaNs and raise warning

1 participant