Skip to content
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

Get some kind of typing for scipy.special #11749

Open
3 of 7 tasks
person142 opened this issue Mar 30, 2020 · 8 comments
Open
3 of 7 tasks

Get some kind of typing for scipy.special #11749

person142 opened this issue Mar 30, 2020 · 8 comments
Labels
good first issue Good topic for first contributor pull requests, with a relatively straightforward solution scipy.special static typing Items related to static typing task A straightforward change, verification or fix.

Comments

@person142
Copy link
Member

person142 commented Mar 30, 2020

This is a tracking issue for getting some kind of typing (likely very rough) for everything in scipy.special. Things that this entails:

  • Type cython_special as Any, since it has no public Python API.
  • Type the ufuncs in _ufuncs as best we can
  • Generate stubs for specfun.
    • The interesting thing here will be generating stubs from the .pyf file; I have a local branch with an initial effort
    • Some compromises will need to be made as the "functions" in the modules f2py generates aren't actually functions; e.g. type(sc.specfun.jdzo) is <class 'fortran'>. Since these functions aren't exposed publicly in any way (instead they are just used in _basic.py mostly) we should likely just ignore that distinction.
  • Add type stubs for a few more miscellaneous extension modules (_comb etc.)
  • Add types for orthogonal.py
  • Add types to _basic.py
    • The blocker here will likely be getting something for ArrayLike in the NumPy stubs EDIT: this is included in NumPy 1.20
  • Add ignores for the places we import matplotlib/pytest/sympy

My hope is that the process of trying to type special will reveal the big things that need to be solved. Once we have solved them we might be ready to open up a big issue for "adding types to stuff" that will then be beginner friendly.

@rgommers
Copy link
Member

rgommers commented Dec 31, 2020

With NumPy 1.20.0 I think the things we need (like numpy.typing.ArrayLike) are in place, and we can think about moving type annotations inline.

There's two recent PRs that looked at type annotations, gh-10844 for stats.qmc (tried inline in Python code, failed on Sphinx warnings so far) and gh-13313 for Qhull (inline in Cython code).

The idea of using inline annotations in combination with numpy.typing by using delayed evaluation of annotations via from __future__ import annotations (see #10844 (comment)) looks like the right thing to do.

The current issue is that Sphinx is generating warnings about inline annotations, see #10844 (comment). sphinx.ext.autodoc has a few options to deal with that, like autodoc_typehints = 'none' (Sphinx docs) - but that's not working - probably because of lack of support in numpydoc. Related issues:

@rgommers rgommers added the sprint Mentored-Sprint. Please do not work on this unless you're participating to a sprint label May 14, 2021
@rgommers
Copy link
Member

Type annotations for other submodules are also welcome now - there's a lot to do. Easiest to keep it in stub files for now, gh-13833 is close to finalizing moving them inline.

@vladutmd
Copy link
Contributor

I'm going to start by changing the necessary annotations to ArrayLike in orthogonal.pyi then do basic.pyi

@BvB93
Copy link
Contributor

BvB93 commented Jun 10, 2021

Recently there was an update to the np.ufunc stubs (see numpy.typing._ufunc) that might be useful as a potential guideline.

Most notably, it introduced a number of type-check-only ufunc subclasses, one for each combination of ufunc.nin and ufunc.nout. In this manner at least some type safety can be guaranteed for each nin/nout combination.

@lucascolley lucascolley added the task A straightforward change, verification or fix. label Nov 21, 2023
@lucascolley lucascolley added good first issue Good topic for first contributor pull requests, with a relatively straightforward solution and removed sprint Mentored-Sprint. Please do not work on this unless you're participating to a sprint labels Dec 11, 2023
@JPena-code
Copy link

Hi. I'm new at contributing to open source and I'm really eager to it, so after reading some of the related issues and PRs (mainly #13833). I would like to try add the typing for the _basic.py module if no one if currently working on it.
Before I start working on it, i wonder if is more suitable to make those typings inline or an stub file?

@lucascolley
Copy link
Member

Hi @JPena-code , others my have different thoughts, but I think it makes sense to start with stubs - then you can always move them inline as a follow-up later.

Feel free to ping me if you'd like any help with submitting a PR by the way!

@rgommers
Copy link
Member

Almost all existing annotations are in stub files:

$ ls scipy/*/*.pyi
scipy/linalg/_cythonized_array_utils.pyi	scipy/spatial/_qhull.pyi			scipy/special/_test_internal.pyi
scipy/linalg/_decomp_lu_cython.pyi		scipy/spatial/_voronoi.pyi			scipy/special/cython_special.pyi
scipy/linalg/_matfuncs_expm.pyi			scipy/spatial/distance.pyi			scipy/stats/_qmc_cy.pyi
scipy/spatial/_ckdtree.pyi			scipy/special/_orthogonal.pyi			scipy/stats/_sobol.pyi

so adding more there seems like the right default for now.

@JPena-code
Copy link

Great, thanks for the help @lucascolley, I will try to add the typing in a stub file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good topic for first contributor pull requests, with a relatively straightforward solution scipy.special static typing Items related to static typing task A straightforward change, verification or fix.
Projects
None yet
Development

No branches or pull requests

6 participants