Skip to content

test_1d_compare_with_numpy fails with numpy 2.2 #92

@olebole

Description

@olebole

In Debian, we are transitioning to numpy 2.2, and observe the following test failure:

__________________________ test_1d_compare_with_numpy __________________________

    @given(
>       size=st.integers(0, 50),
        nx=st.integers(1, 10),
        xmin=st.floats(-1e10, 1e10),
        xmax=st.floats(-1e10, 1e10),
        weights=st.booleans(),
        dtype=st.sampled_from([">f4", "<f4", ">f8", "<f8"]),
    )

fast_histogram/tests/test_histogram.py:17: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
fast_histogram/tests/test_histogram.py:47: in test_1d_compare_with_numpy
    reference = np.histogram(x, bins=nx, weights=w, range=(xmin, xmax))[0]
/usr/lib/python3/dist-packages/numpy/lib/_histograms_impl.py:796: in histogram
    bin_edges, uniform_bins = _get_bin_edges(a, bins, range, weights)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

a = array([], dtype='>f8'), bins = 2, range = (-5e-324, 0.0), weights = None

    def _get_bin_edges(a, bins, range, weights):
[…]
        if n_equal_bins is not None:
            # gh-10322 means that type resolution rules are dependent on array
            # shapes. To avoid this causing problems, we pick a type now and stick
            # with it throughout.
            bin_type = np.result_type(first_edge, last_edge, a)
            if np.issubdtype(bin_type, np.integer):
                bin_type = np.result_type(bin_type, float)
    
            # bin edges must be computed
            bin_edges = np.linspace(
                first_edge, last_edge, n_equal_bins + 1,
                endpoint=True, dtype=bin_type)
            if np.any(bin_edges[:-1] >= bin_edges[1:]):
>               raise ValueError(
                    f'Too many bins for data range. Cannot create {n_equal_bins} '
                    f'finite-sized bins.')
E               ValueError: Too many bins for data range. Cannot create 2 finite-sized bins.
E               Falsifying example: test_1d_compare_with_numpy(
E                   # The test sometimes passed when commented parts were varied together.
E                   size=0,  # or any other generated value
E                   nx=2,
E                   xmin=-5e-324,
E                   xmax=0.0,
E                   weights=False,  # or any other generated value
E                   dtype='>f8',  # or any other generated value
E               )
E               Explanation:
E                   These lines were always and only run by failing examples:
E                       /usr/lib/python3/dist-packages/numpy/_core/function_base.py:155

/usr/lib/python3/dist-packages/numpy/lib/_histograms_impl.py:453: ValueError

This was reported as Debian#1094732. This looks to me like a problem with the test code and not with the operational code, so I will disable the test for the moment in the Debian build.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions