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

Skip to content

Document, deprecate or remove everything exposed in the "numpy" namespace #12385

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

Closed
shoyer opened this issue Nov 14, 2018 · 35 comments
Closed

Document, deprecate or remove everything exposed in the "numpy" namespace #12385

shoyer opened this issue Nov 14, 2018 · 35 comments

Comments

@shoyer
Copy link
Member

shoyer commented Nov 14, 2018

These functions in particular (from #12382) are exported by NumPy, but not documented in the online docs:

    undocumented = {
        'Tester': 'numpy.testing._private.nosetester.NoseTester',
        '_add_newdoc_ufunc': 'numpy.core._multiarray_umath._add_newdoc_ufunc',
        'add_docstring': 'numpy.core._multiarray_umath.add_docstring',
        'add_newdoc': 'numpy.core.function_base.add_newdoc',
        'add_newdoc_ufunc': 'numpy.core._multiarray_umath._add_newdoc_ufunc',
        'byte_bounds': 'numpy.lib.utils.byte_bounds',
        'compare_chararrays': 'numpy.core._multiarray_umath.compare_chararrays',
        'deprecate': 'numpy.lib.utils.deprecate',
        'deprecate_with_doc': 'numpy.lib.utils.<lambda>',
        'disp': 'numpy.lib.function_base.disp',
        'fastCopyAndTranspose': 'numpy.core._multiarray_umath._fastCopyAndTranspose',
        'get_array_wrap': 'numpy.lib.shape_base.get_array_wrap',
        'get_include': 'numpy.lib.utils.get_include',
        'int_asbuffer': 'numpy.core._multiarray_umath.int_asbuffer',
        'mafromtxt': 'numpy.lib.npyio.mafromtxt',
        'maximum_sctype': 'numpy.core.numerictypes.maximum_sctype',
        'ndfromtxt': 'numpy.lib.npyio.ndfromtxt',
        'recfromcsv': 'numpy.lib.npyio.recfromcsv',
        'recfromtxt': 'numpy.lib.npyio.recfromtxt',
        'safe_eval': 'numpy.lib.utils.safe_eval',
        'set_string_function': 'numpy.core.arrayprint.set_string_function',
        'show_config': 'numpy.__config__.show',
        'who': 'numpy.lib.utils.who',
    }

We'll need to make a decision about each of these functions, and either document or deprecate them. (For the most part, my preference would be for deprecation!)

To remove an item from the checks added in #12382, set its __module__ attribute, e.g., using @set_module('numpy').

@charris
Copy link
Member

charris commented Nov 14, 2018

compare_chararrays now has a docstring, whether or not it shows up in the documentation I don't know.

@shoyer
Copy link
Member Author

shoyer commented Nov 14, 2018

@charris Yes, to be clear most of these have docstrings -- they just don't appear in the online documentation generated by Sphinx.

@eric-wieser
Copy link
Member

Related: #10106

@jicksy
Copy link

jicksy commented Mar 24, 2019

Hi,
I would like to work on this ticket.

@mattip
Copy link
Member

mattip commented Mar 24, 2019

@jicksy let us know if you need help getting started: what you tried and where you get stuck.

@rgommers
Copy link
Member

To make this ticket actionable it needs some decisions. Here is the easiest part, the functions that definitely need to be documented (i.e. review/improve docstring, and add to reference guide):

    'deprecate': 'numpy.lib.utils.deprecate',
    'deprecate_with_doc': 'numpy.lib.utils.<lambda>',
    'get_include': 'numpy.lib.utils.get_include',
    'show_config': 'numpy.__config__.show',
    'who': 'numpy.lib.utils.who',

@jicksy I would suggest to start with those.

@smellslikekeenspirit
Copy link

Hi, I'd like to work on this!

@rgommers
Copy link
Member

Some more proposed decisions:

Deprecate in numpy namespace because is available in np.testing or np.lib:

   'Tester': 'numpy.testing._private.nosetester.NoseTester',

Document and add to reference guide:

        'compare_chararrays': 'numpy.core._multiarray_umath.compare_chararrays',

Deprecate completely (trivial alias with one keyword):

        'ndfromtxt': 'numpy.lib.npyio.ndfromtxt',
        'mafromtxt': 'numpy.lib.npyio.mafromtxt',

Deprecate because it was never meant to be public:

        'int_asbuffer': 'numpy.core._multiarray_umath.int_asbuffer',
        'safe_eval': 'numpy.lib.utils.safe_eval'

@rgommers
Copy link
Member

@smellslikekeenspirit please go for it! I suggest to comment here what part you are working on, because there seem to be multiple people interested.

@normallytangent
Copy link

Hello! @rgommers I am starting with the first few functions that you mentioned. It is my very first time contributing to a complex project or even to documentation at this scale, so I am having a hard time locating the right document.
#10106 mentions that the new documentation should be added to numpy/add_newdocs.py but I couldn't find this directory.
What I found was numpy/core/_add_newdocs.py Am I on the right path?

@mattip
Copy link
Member

mattip commented Mar 29, 2019

This is different than #10106. Many of these already have docstrings, but they do not appear in the rendered documents. For instance, `compare_chararrays' has a docstring, but searching for it in the docs comes up empty. One choice would be to add it somewhere, perhaps in Miscellaneous routines, another would be to deprecate it. If you wish to pursue this, you should start with one of the items on the list and issue a PR with that fix. Then add a checklist to the PR with the other items you wish to handle so we can monitor progress. You may choose to leave the harder ones for another PR.

@rgommers
Copy link
Member

I'd think compare_chararrays goes right under chararray in http://www.numpy.org/devdocs/reference/routines.char.html#convenience-class. To get it there, add it to the listing in /doc/source/reference/routines.char.rst.

@normallytangent
Copy link

Ok, understood. I'll keep both of you posted here

@normallytangent
Copy link

@rgommers I did as you said. I have a couple more questions:

  1. As I understand it, listing compare_chararrays should automatically reference it to the Sphinx document. Is that what Sphinx does?
    For background: I couldn't check the results locally after I made the addition on my repo, so I used the inspect-element feature on the devdocs to understand what was happening. It seems an HTML row is added for every addition to the lists. That is not to be done manually, am I right?

  2. Should I issue a PR from my feature branch to the numpy/master?

@rgommers
Copy link
Member

As I understand it, listing compare_chararrays should automatically reference it to the Sphinx document. Is that what Sphinx does?

Yes, Sphinx translates rst documentation file into html (or pdf) content, and the Sphinx autosummary extension basically takes care of seeing that function name in the routine listing, extracting the docstring of that named function, then rendering it as html including the appropriate links.

Should I issue a PR from my feature branch to the numpy/master?

Indeed

I couldn't check the results locally

This first PR will be quite straightforward so it's probably first time right. However if you're going to try more involved changes, you really should try to get make html to work; waiting for the CI system each time to check something isn't workable.

@kritisingh1
Copy link
Member

@rgommers I am starting on removing the deprecated parts as suggested by @seberg as I see Chelwin has started on adding listing . As you wrote in one of the comments above, these four functions , ndfromtxt, mafromtxt, int_asbuffer, safe_eval, need to be deprecated. Could you give me some pointers on what content exactly needs to be removed, apart from their listing in doc/source/user/basics.io.genfromtxt.rst ? Also let me know if I am getting this wrong. Thanks a lot!

@mattip
Copy link
Member

mattip commented Mar 31, 2019

xref #9312 which began documenting show_config

@rgommers
Copy link
Member

@kritisingh1 your doc changes so far look fine. Deprecating functionality is a bit more involved than editing docs, you need to:

  • issue a DeprecationWarning when the function is called
  • ensure that that warning is silenced when running the tests for that function
  • edit the function docstring to note that it is deprecated (can possibly be done with np.deprecate or np.deprecate_with_doc, or manually as in the PR linked below).

This is a good example of deprecating a function: https://github.com/numpy/numpy/pull/12244/files

@kritisingh1
Copy link
Member

kritisingh1 commented Apr 6, 2019

@rgommers what are we planning to replace the functionalities which ndfromtxt and mafromtxt provide with? Or we are just deprecating the functionalities completely? Since you mentioned above that they are trivial alias with one keyword, there should be an alternative way to achieve the tasks performed by those functions.

@rgommers
Copy link
Member

rgommers commented Apr 6, 2019

@kritisingh1 you can look at the implementation of those functions for the answer. They are both calling genfromtxt with the usemask keyword. ndfromtxt is even setting usemask to False which is already the genfromtxt default. So it's identical to genfromtxt. mafromtxt is genfromtxt(..., usemask=False).

@kritisingh1
Copy link
Member

kritisingh1 commented Jul 7, 2019

These functions look like internal helper functions, and in my opinion, do not need to be documented/ exposed to public. This issue is a couple PRs far from being closed so a general agreement would be a great help.
'_add_newdoc_ufunc': 'numpy.core._multiarray_umath._add_newdoc_ufunc', 'add_docstring': 'numpy.core._multiarray_umath.add_docstring', 'add_newdoc': 'numpy.core.function_base.add_newdoc', 'add_newdoc_ufunc': 'numpy.core._multiarray_umath._add_newdoc_ufunc'

@mattip
Copy link
Member

mattip commented Jul 7, 2019

agreed, no need to document them

@mattip
Copy link
Member

mattip commented Jul 9, 2019

@kritisingh1 could you comment on whether we can close #13214, and add a checklist here of what if anything remains to be done?

@eric-wieser
Copy link
Member

eric-wieser commented Jul 9, 2019

agreed, no need to document them

add_newdoc is used extensively twice by scipy: https://github.com/scipy/scipy/search?q=add_newdoc&unscoped_q=add_newdoc

I think perhaps we should consider it public API.

@kritisingh1
Copy link
Member

kritisingh1 commented Jul 9, 2019

Yes we can close #13214
As for the checklist, the following functions need to be documented /deprecated : -

  • Tester
  • FastCopyAndTranspose
  • get_array_wrap
  • int_asbuffer
  • maximum_sctype
  • recfromtxt
  • recfromcsv
  • safe_eval
  • set_string_function
    And in a separate PR, we can discuss about what to do with show_config since that function triggered a lot of discussion on how do we want to go about it. xref DOC: show_config documentation #9312

@rgommers
Copy link
Member

rgommers commented Jul 9, 2019

agreed, no need to document them

add_newdoc is used extensively twice by scipy: https://github.com/scipy/scipy/search?q=add_newdoc&unscoped_q=add_newdoc

I think perhaps we should consider it public API.

Good catch, thanks. I just remembered SciPy had its own, but we use the NumPy one as well. So yes, public it is ....

It would be nice to improve the add_newdoc docstring a little if we're adding it to the refguide.

@eric-wieser
Copy link
Member

It would be nice to improve...

Done in gh-13946

@hmaarrfk
Copy link
Contributor

Would it be possible to remove Tester, it imports unittest and tempfile which contribute to 20% of the import time.

@eric-wieser
Copy link
Member

Are we sure that it's actually 20%? Remember the transitive import times might just move under a different module.

It seems to me that we could hide those imports within Tester itself, without answering the question of when to remove it

@hmaarrfk
Copy link
Contributor

Yeah. I've been benchmarking import times. Nothing else imports unit test

@hmaarrfk
Copy link
Contributor

I can try to see if we can lazy import those two, but looking at the comment, it seems innocent enough to remove all together

@rgommers
Copy link
Member

I can try to see if we can lazy import those two, but looking at the comment, it seems innocent enough to remove all together

Removing Tester does nothing I think unless you also remove importing numpy.testing. which implies removing numpy.test, numpy.linalg.test, etc. Which doesn't sound too appealing.

@hmaarrfk there are existing issues on import time and lazy importing, please continue there rather than mix in the discussion here.

@WarrenWeckesser
Copy link
Member

Back in #12385 (comment), @rgommers (responding to a suggestion from @eric-wieser) said that add_newdoc would remain public. Does that decision still stand? SciPy CI jobs running Python 3.12 and NumPy main dev branch are failing because SciPy uses from numpy.lib import add_newdoc.

@rgommers, sorry for the spam pings if that's a known problem with a fix in progress. I haven't followed all private/public decisions for 2.0 very closely.

@rgommers
Copy link
Member

Thanks for the pings @WarrenWeckesser. It's being fixed up right now, and looks like it'll be staying in the numpy.lib namespace. See gh-24507 for the full contents of the numpy.lib redesign.

@rgommers
Copy link
Member

I think we can close this issue. Most objects have been cleaned up now in the main namespace. Here is the status:

  • staying and have been documented: get_include and show_config
  • still available but to be cleaned up: compare_chararrays, get_array_wrap (these are tracked as part of ENH: Overhaul of NumPy main namespace [NEP 52] #24306)
  • removed from the main namespace: everything else

A few functions (e.g., byte_bounds) will be kept but in a namespace in/under numpy.lib; the attribute error message from trying to access it in the main namespace will tell the user where it moved to.

Thanks everyone!

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

No branches or pull requests