Skip to content

Avg returns NaN when 1 or more ping attempts fail - added a fix - #12

Open
reganface wants to merge 1 commit into
apaszke:masterfrom
reganface:master
Open

Avg returns NaN when 1 or more ping attempts fail - added a fix#12
reganface wants to merge 1 commit into
apaszke:masterfrom
reganface:master

Conversation

@reganface

Copy link
Copy Markdown

When 1 or more ping attempts fail, avg in the return object will be NaN, though min and max are returned correctly. As a backwards compatible way of addressing this, I've added two more properties in the return object:

{
    ...
    dropped: 1,
    success_avg: 23.6245
}

dropped will show how many of the attempts errored out. success_avg will return the average of all successful pings, ignoring the errors. If all pings are successful, success_avg and avg will be equal.

Since this is an old project that gets quite a bit of use, I decided to add new properties instead of changing the existing one to avoid breaking changes. It could easily be changed to fix the existing functionality, though.

The version number was updated to 0.1.2 and README.md was updated to show the two new properties in the sample return object.

When some number of ping attemps fail, avg will return Nan.
In those cases, success_avg will return the average ping of all
successful pings.

README has been updated and version bumped to 0.1.2
@gaby

gaby commented Nov 8, 2025

Copy link
Copy Markdown

@apaszke Thoughts on merging this?

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.

2 participants