Thanks to visit codestin.com
Credit goes to github.com

Skip to content

DOC: Document/ Deprecate functions exposed in "numpy" namespace #13222

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

Merged
merged 4 commits into from
Jun 10, 2019

Conversation

kritisingh1
Copy link
Member

@kritisingh1 kritisingh1 commented Mar 30, 2019

Related to #12385
The checklist for future work on this PR is as follows:
Deprecate -

  • 'mafromtxt`
  • 'ndfromtxt'

@rgommers Please review and let me know the required changes. Thanks a lot!

@mattip
Copy link
Member

mattip commented Mar 30, 2019

Please remove from your checklist items that already appear in #13214.

@mattip
Copy link
Member

mattip commented Mar 31, 2019

xref #9312 which began documenting show_config but still needs work.

@kritisingh1
Copy link
Member Author

I have added the warning messages for the function ndfromtxt and mafromtxt and also edited the docstrings. I am not sure where equivalent functions for int_asbuffer exists and would be grateful for pointers on it. @mattip

@seberg
Copy link
Member

seberg commented Apr 3, 2019

@kritisingh1 int_asbuffer is defined in multiarray on the C side. Sometimes a nice way to find things can be to use git grep "int_asbuffer", etc. The definition is in numpy/core/src/multiarray/multiarraymodule.c.

@kritisingh1
Copy link
Member Author

kritisingh1 commented Apr 3, 2019

@seberg yeah I was using git grep "int_asbuffer" but the function name was asbuffer so it didn't turn up in the results. I will take care of this from next time.

@mattip
Copy link
Member

mattip commented Apr 3, 2019

the interesting part will be determining what its docstring should be so we can put a deprecation notice in it. The docstring should be added to numpy/core/_add_newdocs.py, like

add_newdoc('numpy.core.multiarray', 'int_asbuffer', '''
<your text here>
.. deprecated:: 1.17
     Deprecated, use <your text here> instead
 ''')

Play with the function a bit, read the C code, and ask here or on the mailing list if you have a hard time coming up with some text

@@ -2235,13 +2237,18 @@ def ndfromtxt(fname, **kwargs):

"""
kwargs['usemask'] = False
warnings.warn(
"np.ndfromtxt is deprecated",
DeprecationWarning, stacklevel=2)
Copy link
Member

Choose a reason for hiding this comment

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

Needs a comment above the warning with the date, version, gh-issue format

Copy link
Member

Choose a reason for hiding this comment

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

Should also recommend a replacement, perhaps `ndfromtxt` is a deprecated alias of `genfromtxt`, prefer the latter

@mattip
Copy link
Member

mattip commented Apr 3, 2019

Please update the checklist at the top of the PR with the additional items, and mark off the ones that are modified in the PR

@kritisingh1
Copy link
Member Author

kritisingh1 commented Apr 5, 2019

@mattip I'm figuring out what text to add to the numpy/core/_add_newdocs.py . Meanwhile, I would be grateful if you could help me in fixing the failing tests. By the logs, the tests which are calling safe_eval, ndfromtxt and mafromtxt and are encountering warnings.warn(..) in the respective functions are failing which should not happen because they are just warnings. I'm not sure why this is happening. Thanks!

@mattip
Copy link
Member

mattip commented Apr 5, 2019

Look at the with warnings.* constructs in other tests, they are used to filter known warnings. Testing turns unexpected warnings into errors.

@mattip
Copy link
Member

mattip commented Apr 5, 2019

You should be running at least the basic tests locally, so you can avoid too much CI churn python runtests.py

@kritisingh1
Copy link
Member Author

@mattip the tests are failing despite adding the with warnings.* constructor for every mention of the deprecated functions. Is there anything I am missing?
Also, I looked at other functions which were deprecated in npyio.py and could see that the alternative to those functions were used in the tests. For example. pickle.loads in place of loads. So, as @rgommers suggested, I can instead modify the tests which use ndfromtxt and mafromtxt to use genfromtxt with the required flags as parameters. Please let me know what should be the better way to go ahead. Thanks!

@mattip
Copy link
Member

mattip commented Apr 9, 2019

You should add a test to numpy/core/tests/test_deprecated.py (or numpy/ma/tests/test_deprecations.py or numpy/linalg/tests/test_deprecations.py), for each deprecation. Then replace the deprecated function with its alternative inside numpy itself, so any function that used to call the deprecated function now should not be emitting warnings.

tests are failing despite adding the with warnings.* construct

It is hard to tell without seeing your changes. Note test_deprecations uses self.assert_deprecated

@seberg seberg self-requested a review May 28, 2019 16:41
@@ -1136,7 +1139,6 @@ def safe_eval(source):
"""
# Local import to speed up numpy's import time.
import ast

Copy link
Member

Choose a reason for hiding this comment

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

I think you can put this deprecation back, but have to replace all use-cases with the ast.literal_eval(source) call that this does. Maybe the DeprecationWarning should mention to use ast.literal_eval instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

@seberg , can I try deprecating self_eval in a different pull request altogether, if that is alright?

Copy link
Member

Choose a reason for hiding this comment

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

Yes of course, but should probably remove the documentation change as well for now then.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@@ -2225,6 +2225,9 @@ def ndfromtxt(fname, **kwargs):
"""
Load ASCII data stored in a file and return it as a single array.

.. deprecated:: 1.17
np.ndfromtxt is deprecated
Copy link
Member

@eric-wieser eric-wieser Jun 7, 2019

Choose a reason for hiding this comment

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

Again, mention the replacement here, possibly with a few more words than in the DeprecationWarning.

`ndfromtxt` is a deprecated alias of `genfromtxt` which overwrites the ``usemask`` argument
with `False` even when explicitly called as ``ndfromtxt(..., usemask=True)``. Use `genfromtxt` instead.

@kritisingh1
Copy link
Member Author

@mattip I will open separate PRs for addressing the issue #12385 as and when I complete the work involved for documenting/deprecating different functions. Meanwhile, please let me know if there is anything else that needs to be done for deprecating the functions in the above checklist.

@mattip mattip merged commit 6472813 into numpy:master Jun 10, 2019
@mattip
Copy link
Member

mattip commented Jun 10, 2019

Thanks @kritisingh1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants