Skip to content

ENH: Add typing for np.random and Generator #17103

@bashtage

Description

@bashtage

NumPy supplies partial typing support. Currently random's methods and Generator do not have typing information which results in errors in mypy.

Reproducing code example:

Use mypy on any project that uses np.random and you will see output like

linearmodels/tests/iv/results/simulated-test-data.py:16: error: Module 'numpy.random' has no attribute 'multivariate_normal'
linearmodels/tests/iv/results/simulated-test-data.py:16: error: Module 'numpy.random' has no attribute 'seed'
linearmodels/tests/iv/results/simulated-test-data.py:69: error: Module has no attribute "chisquare"
linearmodels/panel/utility.py:496: error: Name 'np.random.RandomState' is not defined
linearmodels/panel/utility.py:534: error: Module has no attribute "RandomState"; maybe "__RandomState_ctor"?

Numpy/Python version information:

1.19.1 3.7.7 (default, May 7 2020, 21:25:33)
[GCC 7.3.0]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions