Content-Length: 561669 | pFad | https://github.com/numpy/numpy/pull/28899

5E DEP: Deprecate ma.round_ and add warning test by dineshcsdev · Pull Request #28899 · numpy/numpy · GitHub
Skip to content

DEP: Deprecate ma.round_ and add warning test #28899

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

dineshcsdev
Copy link

@dineshcsdev dineshcsdev commented May 4, 2025

Deprecate ma.round_ and add warning test

@jorenham jorenham changed the title Deprecate ma.round_ and add warning test DEP: Deprecate ma.round_ and add warning test May 4, 2025
Copy link
Member

@mattip mattip left a comment

Choose a reason for hiding this comment

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

You can run locally to fix the failing tests.

with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
ma.round_([1.234, 2.345])
assert any("deprecated" in str(warning.message) for warning in w), "No deprecation warning!"
Copy link
Member

Choose a reason for hiding this comment

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

Rather than adding here, add to numpy/_core/tests/test_deprecations.py

Copy link
Contributor

Choose a reason for hiding this comment

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

There may also be less boilierplate via i.e, with pytest.deprecated_call(match='deprecated'):

Copy link
Member

Choose a reason for hiding this comment

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

This should be deleted

@dineshcsdev
Copy link
Author

I’ve removed the separate test_round_warning.py file and moved the test into numpy/core/tests/test_deprecations.py as suggested.
The test now uses pytest.deprecated_call(match="deprecated") to reduce boilerplate.

@ngoldbaum
Copy link
Member

Please try to build numpy and run the tests locally before pushing to run CI. Using spin helps with this.

This also needs a release note.

@ngoldbaum ngoldbaum added the 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes label May 5, 2025
@dineshcsdev
Copy link
Author

Thanks for the feedback! 🙌
I’ll work on building NumPy locally and run the tests using spin before pushing again.
Also, I’ll add the missing release note in the correct format as per the NumPy release note guidelines.

Will update the PR shortly.

Copy link
Member

@mattip mattip left a comment

Choose a reason for hiding this comment

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

Please run the tests locally before pushing a git change.

Comment on lines 1 to 2
Deprecate `ma.round_` function
------------------------------
Copy link
Member

Choose a reason for hiding this comment

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

RST needs two quotes.

Suggested change
Deprecate `ma.round_` function
------------------------------
Deprecate ``ma.round_``
-----------------------

with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
ma.round_([1.234, 2.345])
assert any("deprecated" in str(warning.message) for warning in w), "No deprecation warning!"
Copy link
Member

Choose a reason for hiding this comment

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

This should be deleted

@@ -7,6 +7,9 @@
import pytest
import tempfile
import re
import numpy.ma as ma


Copy link
Member

Choose a reason for hiding this comment

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

Linting complains about too many blank lines here

Copy link
Member

Choose a reason for hiding this comment

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

The extra line is causing linting failures. Please fix.

@@ -8176,8 +8176,13 @@ def round_(a, decimals=0, out=None):
return out


round = round_
Copy link
Member

Choose a reason for hiding this comment

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

On line 8123 above you need to change the function name from round_ to round

Copy link
Member

Choose a reason for hiding this comment

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

You also need to examine and change the documentation to use round instead of round_. See the Examples section starting on line 8146.

@dineshcsdev
Copy link
Author

I've addressed all the feedback:

  1. Fixed the RST format in the release note with proper double backticks
  2. Fixed the function implementation in core.py to properly deprecate round_ and redirect to round
  3. Fixed the spacing issue in test_deprecations.py
  4. Built and tested locally with spin

Thank you for your guidance!

Copy link
Member

@jorenham jorenham left a comment

Choose a reason for hiding this comment

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

It would help to also announce the deprecation in the typing stubs:

numpy/numpy/ma/core.pyi

Lines 1294 to 1295 in de784cd

def round_(a, decimals=..., out=...): ...
round = round_

You can use the @deprecated decorator from typing_extensions for this (docs).
Be careful to only deprecate round_, and not also round

@dineshcsdev
Copy link
Author

@jorenham your issue changed to another pr due to some technical issue I'm sorry about that you can view here Dinesh-0813:fix-deprecate-ma-round #28917 sorry for the trouble

Copy link
Member

@mattip mattip left a comment

Choose a reason for hiding this comment

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

You should check the reasons CI is failing, and fix them. I pointed out a few, there may be more.

@@ -7,6 +7,9 @@
import pytest
import tempfile
import re
import numpy.ma as ma


Copy link
Member

Choose a reason for hiding this comment

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

The extra line is causing linting failures. Please fix.

@@ -8176,8 +8176,13 @@ def round_(a, decimals=0, out=None):
return out


round = round_
Copy link
Member

Choose a reason for hiding this comment

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

You also need to examine and change the documentation to use round instead of round_. See the Examples section starting on line 8146.

@dineshcsdev
Copy link
Author

This PR renames the internal function round_ to round in numpy.ma.core, aligning it with NumPy's naming conventions and improving clarity. Associated docstrings and usages have been updated accordingly.

@mattip
Copy link
Member

mattip commented May 9, 2025

Tests are still failing. Also please add the necessary changes to typing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
07 - Deprecation 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes component: numpy.ma masked arrays
Projects
Status: Pending authors' response
Development

Successfully merging this pull request may close these issues.

5 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/numpy/numpy/pull/28899

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy