Skip to content

Implement nanmedian function in keras.ops#22585

Open
shashaka wants to merge 6 commits intokeras-team:masterfrom
shashaka:nanmedian
Open

Implement nanmedian function in keras.ops#22585
shashaka wants to merge 6 commits intokeras-team:masterfrom
shashaka:nanmedian

Conversation

@shashaka
Copy link
Copy Markdown
Collaborator

Adds keras.ops.nanmedian, which computes the median of the input tensor along a specified axis while ignoring NaN values.
Supported across NumPy, TensorFlow, PyTorch, and JAX backends. Not supported on OpenVINO.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the nanmedian operation across multiple Keras backends (JAX, TensorFlow, PyTorch, and NumPy) and adds the corresponding public API and tests. Feedback focuses on ensuring consistent behavior for edge cases, specifically handling empty axis reductions in the NumPy backend to prevent ValueError and removing a redundant check in the PyTorch implementation. A test assertion also needs to be updated to correctly verify the identity behavior for empty axes.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 28, 2026

Codecov Report

❌ Patch coverage is 88.88889% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.85%. Comparing base (28a83c5) to head (f9d77b7).

Files with missing lines Patch % Lines
keras/src/backend/jax/numpy.py 33.33% 2 Missing ⚠️
keras/api/_tf_keras/keras/ops/__init__.py 0.00% 1 Missing ⚠️
keras/api/_tf_keras/keras/ops/numpy/__init__.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #22585      +/-   ##
==========================================
- Coverage   83.28%   79.85%   -3.44%     
==========================================
  Files         596      596              
  Lines       68089    68125      +36     
  Branches    10607    10610       +3     
==========================================
- Hits        56711    54401    -2310     
- Misses       8634    11020    +2386     
+ Partials     2744     2704      -40     
Flag Coverage Δ
keras 79.68% <88.88%> (-3.41%) ⬇️
keras-jax 24.78% <30.55%> (-34.89%) ⬇️
keras-numpy 55.35% <63.88%> (+<0.01%) ⬆️
keras-openvino 53.33% <50.00%> (-0.01%) ⬇️
keras-tensorflow 61.04% <69.44%> (+<0.01%) ⬆️
keras-torch 59.86% <69.44%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@keerthanakadiri keerthanakadiri added the stat:awaiting keras-eng Awaiting response from Keras engineer label Mar 30, 2026
Copy link
Copy Markdown
Collaborator

@hertschuh hertschuh left a comment

Choose a reason for hiding this comment

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

Thanks for adding this!

Can you also rebase?

@hertschuh hertschuh added stat:awaiting response from contributor and removed stat:awaiting keras-eng Awaiting response from Keras engineer labels Mar 31, 2026
Copy link
Copy Markdown
Collaborator

@hertschuh hertschuh left a comment

Choose a reason for hiding this comment

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

Thanks!

@google-ml-butler google-ml-butler bot added the ready to pull Ready to be merged into the codebase label Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review ready to pull Ready to be merged into the codebase size:M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants