Skip to content

ENH: add nanmean - #910

Merged
lucascolley merged 4 commits into
data-apis:mainfrom
ushnah:nanmean
Aug 25, 2026
Merged

ENH: add nanmean#910
lucascolley merged 4 commits into
data-apis:mainfrom
ushnah:nanmean

Conversation

@ushnah

@ushnah ushnah commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Towards #789

  • add support for nanmean

@lucascolley
lucascolley self-requested a review August 12, 2026 14:04
@lucascolley lucascolley added enhancement New feature or request new function labels Aug 12, 2026
@lucascolley lucascolley changed the title ENH: add nanmean ENH: add nanmean Aug 12, 2026
@lucascolley lucascolley added this to the 0.11.2 milestone Aug 12, 2026
@lucascolley

Copy link
Copy Markdown
Member

cc @OmarManzoor

@lucascolley
lucascolley removed their request for review August 12, 2026 18:08
@lucascolley lucascolley linked an issue Aug 12, 2026 that may be closed by this pull request
4 tasks

@qbarthelemy qbarthelemy left a comment

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.

Branch must be rebased, because code has been moved to src\array_api_extra\_agnostic\_statistical.py

Comment thread src/array_api_extra/_lib/_funcs.py Outdated
Comment thread src/array_api_extra/_lib/_funcs.py Outdated
Comment thread src/array_api_extra/_lib/_funcs.py Outdated
@ushnah
ushnah force-pushed the nanmean branch 3 times, most recently from 4eaf451 to 1ba49d5 Compare August 23, 2026 22:46
Comment thread tests/main/test_statistical.py Outdated
applying changes for mean

Co-authored-by: Omar Salman <omar.salman@arbisoft.com>

@OmarManzoor OmarManzoor left a comment

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.

LGTM. Thank you @ushnah

@OmarManzoor

Copy link
Copy Markdown
Contributor

CC: @lucascolley I think this looks fine to merge

@lucascolley
lucascolley self-requested a review August 25, 2026 12:25

@lucascolley lucascolley 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 all! One question

Comment on lines +170 to +181
safe_count = xp.astype(
xp.where(count == 0, xp.ones_like(count), count),
sum_.dtype,
copy=False,
)
result = sum_ / safe_count
if xp.any(count == 0):
result = xp.where(
count == 0,
xp.full_like(result, xp.nan),
result,
)

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 is one of these xp.where calls gated behind xp.any(count == 0), but the other isn't?

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.

Valid point! Maybe we can just remove this extra condition, the where clause is checking for 0s anyways

@lucascolley

Copy link
Copy Markdown
Member

In case you are interested in contributing another PR @ushnah, checking off the last item in gh-100 would be a good contribution. That would involve following the instructions at https://data-apis.org/array-api-extra/contributing.html#delegation for

def angle(z: Array, /, *, deg: bool = False, xp: ArrayNamespace | None = None) -> Array:

@lucascolley
lucascolley merged commit 52fe44d into data-apis:main Aug 25, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request new function

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ENH: add support for nanmin, nanmax, nanmean and nansum

5 participants