Skip to content

fix(statistics): accept finite NumPy scalar measurements - #651

Closed
harshitethic wants to merge 2 commits into
Hebbian-Robotics:mainfrom
harshitethic:fix/weighted-value-numpy-scalars-647
Closed

harshitethic wants to merge 2 commits into
Hebbian-Robotics:mainfrom
harshitethic:fix/weighted-value-numpy-scalars-647

Conversation

@harshitethic

Copy link
Copy Markdown
Contributor

Summary

  • normalize NumPy scalar values with .item() before numeric validation
  • keep rejecting Python and NumPy booleans as measurements/weights
  • add regression coverage for np.float32, np.int64, and np.bool_

Fixes #647.

@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Statistics module accepts NumPy scalar types.

The PR should not merge until the isolated utility import test works again.

Findings

  1. P1 Isolated utility import fails ▶
  2. P2 Finite longdouble values fail ▶
Summary

WeightedValue now accepts finite NumPy number scalars as measurements and weights while still rejecting booleans.

  • Converts NumPy scalars before numeric validation.
  • Adds examples for accepted numeric scalars and rejected NumPy booleans.

Reviews (1) · Last reviewed commit: "test(statistics): cover NumPy scalar mea..."

Comment thread src/hflow/statistics.py
from dataclasses import dataclass
from itertools import pairwise

import numpy as np

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Isolated utility import fails

The existing utility test runs Python without site-packages and imports hflow.statistics. This new numpy import raises ModuleNotFoundError, so the test fails before its checks run. Keep that import working without site-packages, or change the test and the documented standard-library-only promise together.

Comment thread src/hflow/statistics.py
Comment on lines +13 to 15
if isinstance(value, np.generic):
value = value.item()
if isinstance(value, bool) or not isinstance(value, (int, float)):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Finite longdouble values fail

np.longdouble(1).item() does not become a Python int or float. The next check therefore makes WeightedValue(np.longdouble(1), 1) raise ValueError, even though the measurement is finite. Callers using that NumPy scalar type still cannot use these summaries; accept finite real NumPy scalars without relying on .item() to return a built-in number.

@kstonekuan

Copy link
Copy Markdown
Contributor

Thanks for this. #647 was assigned to chiruu12, and their fix in #649 has now merged, so I'm closing this one. Issues with an assignee are taken; everything else is fair game. If you want another, exercising HFlow against a real corpus such as Egocentric-10K on Hugging Face and reporting what breaks or is slow is high-value work right now.

@kstonekuan kstonekuan closed this Oct 1, 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]: WeightedValue refuses finite NumPy scalars as "not a finite number"

2 participants