Skip to content

fix: Numpy sum error#104

Merged
cbueth merged 2 commits intoBikeNetKit:mainfrom
juanfonsecaLS1:fix-errors-on-newer-versions
Mar 11, 2026
Merged

fix: Numpy sum error#104
cbueth merged 2 commits intoBikeNetKit:mainfrom
juanfonsecaLS1:fix-errors-on-newer-versions

Conversation

@juanfonsecaLS1
Copy link
Copy Markdown
Collaborator

@juanfonsecaLS1 juanfonsecaLS1 commented Mar 9, 2026

This updates the code to fix #102

Closes #102.

@juanfonsecaLS1
Copy link
Copy Markdown
Collaborator Author

this also superseeds #103

@juanfonsecaLS1 juanfonsecaLS1 marked this pull request as ready for review March 9, 2026 11:55
return 0

return 1 - npsum(
return 1 - sum(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This now uses the python integrated sum? If we are not using numpy's sum, then the import from numpy import sum as npsum should be removed, as it is not used anywhere else in this file. I'm confused why this is erroring here, while using sum by numpy sin other places of this package still works.
I'd say if the CI works there is no need to dig into the details.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I went for the simpler way as suggested in the error line I was getting. I did not remove the import as the npsum is still used in calculate_global_efficiency

def calculate_global_efficiency(distance_matrix, measure1, measure2):
    r"""Calculate the global efficiency for the given network measures.

    The global efficiency is the ratio between the sums of the inverses of the
    distances of the two network measures.

    If any of the distances is 0 or infinite, it is ignored in the calculation.

    Parameters
    ----------
    distance_matrix : dict
        The distance matrix for the network measures, as returned by instance attribute
        :attr:`superblockify.metrics.metric.Metric.distance_matrix`
    measure1 : str
        The first network measure
    measure2 : str
        The second network measure

    Returns
    -------
    float
        The global efficiency of the network measures

    Notes
    -----
    .. math::

         E_{\text{glob},S/E}=\frac{\sum_{i \neq j}\frac{1}{d_S(i, j)}}
         {\sum_{i \neq j} \frac{1}{d_E(i, j)}}
    """

    dist1, dist2 = _network_measures_filtered_flattened(
        distance_matrix, measure1, measure2
    )

    # Calculate the global efficiency as the ratio between the sums of the inverses
    return npsum(1 / dist1) / npsum(1 / dist2)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good point, I did not see it there. Let's see what the second CI run now says.

@cbueth cbueth changed the title updated code with bug fix: Numpy sum error Mar 11, 2026
@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.55%. Comparing base (037151f) to head (adb63f7).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #104   +/-   ##
=======================================
  Coverage   98.54%   98.55%           
=======================================
  Files          31       31           
  Lines        1861     1863    +2     
  Branches      333      333           
=======================================
+ Hits         1834     1836    +2     
  Misses          4        4           
  Partials       23       23           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cbueth cbueth merged commit 9fd0a18 into BikeNetKit:main Mar 11, 2026
28 checks passed
@cbueth
Copy link
Copy Markdown
Collaborator

cbueth commented Mar 11, 2026

Thank you for the PR and easy fix. The CI passes.

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.

np.sum(generator) in calculate_coverage fails with NumPy ≥ 2.0

3 participants