Skip to content

fix tablereport error in histogram when data range is very narrow#2189

Merged
rcap107 merged 11 commits into
skrub-data:mainfrom
jeromedockes:fix-tablereport-narrow-range
Jul 2, 2026
Merged

fix tablereport error in histogram when data range is very narrow#2189
rcap107 merged 11 commits into
skrub-data:mainfrom
jeromedockes:fix-tablereport-narrow-range

Conversation

@jeromedockes

@jeromedockes jeromedockes commented Jun 25, 2026

Copy link
Copy Markdown
Member

we can get an error in matplotlib / numpy histogram if the column is not constant but the data range does not contain enough representable floating numbers for the default number of bins

for example it would fail on a column like this

    low = np.float32(10.0)
    high = np.nextafter(low, 11.0)
    data = pd.Series([low, high])

@jeromedockes jeromedockes added bug Something isn't working TableReport anything related to the TableReport labels Jun 25, 2026
@jeromedockes jeromedockes added this to the Release 0.10 milestone Jun 25, 2026

@rcap107 rcap107 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @jeromedockes

The code looks mostly good to me, but I'd like a few more comments explaining what is happening before we merge this

return None
vmin, vmax = values.min(), values.max()
delta = max(np.spacing(vmin), np.spacing(vmax))
if vmax - vmin > 12 * delta:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why 12 here and 6 below?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

if the range is already wider than 12, we don't need to adjust it. otherwise we add 6 on each side so it is at least 12-wide afterwards.

probably 5 + 5 = 10 would be enough because there are 10 bins, but we don't care and have a little safety margin to make sure we don't crash

return low, high


def _get_safe_hist_range(values):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

could you explain this function in a bit more detail? it's not clear what is happening in the code and what is being returned

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yep i added comments LMK if it is clearer now

_, hist = _plotting.histogram(data)
assert (hist["n_low_outliers"], hist["n_high_outliers"]) == (0, 0)

low = np.float32(10.0)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can you add a comment here explaining what this line is for?

@rcap107 rcap107 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the comments @jeromedockes, the PR looks good to me

@rcap107 rcap107 merged commit 3039ae4 into skrub-data:main Jul 2, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working TableReport anything related to the TableReport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants