# Mypy type stubs for NumPy, pandas, and Matplotlib
[![Join the chat at https://gitter.im/data-science-types/community](https://badges.gitter.im/data-science-types/community.svg)](https://gitter.im/data-science-types/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
This is a [PEP-561][pep-561]-compliant stub-only package
which provides type information for [matplotlib][matplotlib], [numpy][numpy] and [pandas][pandas].
The [mypy][mypy] type checker (or pytype or PyCharm) can [recognize][mypy-docs] the types in these packages by installing this package.
### NOTE: This is a work in progress
Many functions are already typed, but a *lot* is still missing (NumPy and pandas are *huge* libraries).
Chances are, you will see a message from Mypy claiming that a function does not exist when it does exist.
If you encounter missing functions, we would be delighted for you to send a PR.
If you are unsure of how to type a function, we can discuss it.
## Installing
You can get this package from PyPI:
```bash
pip install data-science-types
```
To get the most up-to-date version, install it directly from GitHub:
```bash
pip install git+https://github.com/predictive-analytics-lab/data-science-types
```
Or clone the repository somewhere and do `pip install -e .`.
## Examples
These are the kinds of things that can be checked:
### Array creation
```python
import numpy as np
arr1: np.ndarray[np.int64] = np.array([3, 7, 39, -3]) # OK
arr2: np.ndarray[np.int32] = np.array([3, 7, 39, -3]) # Type error
arr3: np.ndarray[np.int32] = np.array([3, 7, 39, -3], dtype=np.int32) # OK
arr4: np.ndarray[float] = np.array([3, 7, 39, -3], dtype=float) # Type error: the type of ndarray can not be just "float"
arr5: np.ndarray[np.float64] = np.array([3, 7, 39, -3], dtype=float) # OK
```
### Operations
```python
import numpy as np
arr1: np.ndarray[np.int64] = np.array([3, 7, 39, -3])
arr2: np.ndarray[np.int64] = np.array([4, 12, 9, -1])
result1: np.ndarray[np.int64] = np.divide(arr1, arr2) # Type error
result2: np.ndarray[np.float64] = np.divide(arr1, arr2) # OK
compare: np.ndarray[np.bool_] = (arr1 == arr2)
```
### Reductions
```python
import numpy as np
arr: np.ndarray[np.float64] = np.array([[1.3, 0.7], [-43.0, 5.6]])
sum1: int = np.sum(arr) # Type error
sum2: np.float64 = np.sum(arr) # OK
sum3: float = np.sum(arr) # Also OK: np.float64 is a subclass of float
sum4: np.ndarray[np.float64] = np.sum(arr, axis=0) # OK
# the same works with np.max, np.min and np.prod
```
## Philosophy
The goal is not to recreate the APIs exactly.
The main goal is to have *useful* checks on our code.
Often the actual APIs in the libraries is more permissive than the type signatures in our stubs;
but this is (usually) a feature and not a bug.
## Contributing
We always welcome contributions.
All pull requests are subject to CI checks.
We check for compliance with Mypy and that the file formatting conforms to our Black specification.
You can install these dev dependencies via
```bash
pip install -e '.[dev]'
```
This will also install NumPy, pandas, and Matplotlib to be able to run the tests.
### Running CI locally (recommended)
We include a script for running the CI checks that are triggered when a PR is opened.
To test these out locally, you need to install the type stubs in your environment.
Typically, you would do this with
```bash
pip install -e .
```
Then use the `check_all.sh` script to run all tests:
```bash
./check_all.sh
```
Below we describe how to run the various checks individually,
but `check_all.sh` should be easier to use.
### Checking compliance with Mypy
The settings for Mypy are specified in the `mypy.ini` file in the repository.
Just running
```bash
mypy tests
```
from the base directory should take these settings into account.
We enforce 0 Mypy errors.
### Formatting with black
We use [Black][black] to format the stub files.
First, install `black` and then run
```bash
black .
```
from the base directory.
### Pytest
```bash
python -m pytest -vv tests/
```
### Flake8
```bash
flake8 *-stubs
```
## License
[Apache 2.0](LICENSE)
[pep-561]: https://www.python.org/dev/peps/pep-0561/
[matplotlib]: https://matplotlib.org
[numpy]: https://numpy.org
[pandas]: https://pandas.pydata.org
[mypy]: http://www.mypy-lang.org/
[mypy-docs]: https://mypy.readthedocs.io/en/latest/installed_packages.html
[black]: https://github.com/psf/black
Raw data
{
"_id": null,
"home_page": "https://github.com/predictive-analytics-lab/data-science-types",
"name": "data-science-types",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "",
"author": "PAL",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/ae/5f/6c4888c17fa53c551df740d93806c68f1d5eed6b6167747087415e50dccb/data-science-types-0.2.23.tar.gz",
"platform": "",
"description": "# Mypy type stubs for NumPy, pandas, and Matplotlib\n\n[![Join the chat at https://gitter.im/data-science-types/community](https://badges.gitter.im/data-science-types/community.svg)](https://gitter.im/data-science-types/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)\n\nThis is a [PEP-561][pep-561]-compliant stub-only package\nwhich provides type information for [matplotlib][matplotlib], [numpy][numpy] and [pandas][pandas].\nThe [mypy][mypy] type checker (or pytype or PyCharm) can [recognize][mypy-docs] the types in these packages by installing this package.\n\n### NOTE: This is a work in progress\n\nMany functions are already typed, but a *lot* is still missing (NumPy and pandas are *huge* libraries).\nChances are, you will see a message from Mypy claiming that a function does not exist when it does exist.\nIf you encounter missing functions, we would be delighted for you to send a PR.\nIf you are unsure of how to type a function, we can discuss it.\n\n## Installing\n\nYou can get this package from PyPI:\n\n```bash\npip install data-science-types\n```\n\nTo get the most up-to-date version, install it directly from GitHub:\n\n```bash\npip install git+https://github.com/predictive-analytics-lab/data-science-types\n```\n\nOr clone the repository somewhere and do `pip install -e .`.\n\n## Examples\n\nThese are the kinds of things that can be checked:\n\n### Array creation\n\n```python\nimport numpy as np\n\narr1: np.ndarray[np.int64] = np.array([3, 7, 39, -3]) # OK\narr2: np.ndarray[np.int32] = np.array([3, 7, 39, -3]) # Type error\narr3: np.ndarray[np.int32] = np.array([3, 7, 39, -3], dtype=np.int32) # OK\narr4: np.ndarray[float] = np.array([3, 7, 39, -3], dtype=float) # Type error: the type of ndarray can not be just \"float\"\narr5: np.ndarray[np.float64] = np.array([3, 7, 39, -3], dtype=float) # OK\n```\n\n### Operations\n\n```python\nimport numpy as np\n\narr1: np.ndarray[np.int64] = np.array([3, 7, 39, -3])\narr2: np.ndarray[np.int64] = np.array([4, 12, 9, -1])\n\nresult1: np.ndarray[np.int64] = np.divide(arr1, arr2) # Type error\nresult2: np.ndarray[np.float64] = np.divide(arr1, arr2) # OK\n\ncompare: np.ndarray[np.bool_] = (arr1 == arr2)\n```\n\n### Reductions\n\n```python\nimport numpy as np\n\narr: np.ndarray[np.float64] = np.array([[1.3, 0.7], [-43.0, 5.6]])\n\nsum1: int = np.sum(arr) # Type error\nsum2: np.float64 = np.sum(arr) # OK\nsum3: float = np.sum(arr) # Also OK: np.float64 is a subclass of float\nsum4: np.ndarray[np.float64] = np.sum(arr, axis=0) # OK\n\n# the same works with np.max, np.min and np.prod\n```\n\n## Philosophy\n\nThe goal is not to recreate the APIs exactly.\nThe main goal is to have *useful* checks on our code.\nOften the actual APIs in the libraries is more permissive than the type signatures in our stubs;\nbut this is (usually) a feature and not a bug.\n\n## Contributing\n\nWe always welcome contributions.\nAll pull requests are subject to CI checks.\nWe check for compliance with Mypy and that the file formatting conforms to our Black specification.\n\nYou can install these dev dependencies via\n\n```bash\npip install -e '.[dev]'\n```\n\nThis will also install NumPy, pandas, and Matplotlib to be able to run the tests.\n\n### Running CI locally (recommended)\n\nWe include a script for running the CI checks that are triggered when a PR is opened.\nTo test these out locally, you need to install the type stubs in your environment.\nTypically, you would do this with\n\n```bash\npip install -e .\n```\n\nThen use the `check_all.sh` script to run all tests:\n\n```bash\n./check_all.sh\n```\n\nBelow we describe how to run the various checks individually,\nbut `check_all.sh` should be easier to use.\n\n### Checking compliance with Mypy\n\nThe settings for Mypy are specified in the `mypy.ini` file in the repository.\nJust running\n\n```bash\nmypy tests\n```\n\nfrom the base directory should take these settings into account.\nWe enforce 0 Mypy errors.\n\n### Formatting with black\n\nWe use [Black][black] to format the stub files.\nFirst, install `black` and then run\n\n```bash\nblack .\n```\nfrom the base directory.\n\n### Pytest\n\n```bash\npython -m pytest -vv tests/\n```\n\n### Flake8\n\n```bash\nflake8 *-stubs\n```\n\n## License\n\n[Apache 2.0](LICENSE)\n\n\n[pep-561]: https://www.python.org/dev/peps/pep-0561/\n[matplotlib]: https://matplotlib.org\n[numpy]: https://numpy.org\n[pandas]: https://pandas.pydata.org\n[mypy]: http://www.mypy-lang.org/\n[mypy-docs]: https://mypy.readthedocs.io/en/latest/installed_packages.html\n[black]: https://github.com/psf/black\n\n\n",
"bugtrack_url": null,
"license": "Apache License 2.0",
"summary": "Type stubs for Python machine learning libraries",
"version": "0.2.23",
"project_urls": {
"Bug Tracker": "https://github.com/predictive-analytics-lab/data-science-types/issues/",
"Homepage": "https://github.com/predictive-analytics-lab/data-science-types",
"Source Code": "https://github.com/predictive-analytics-lab/data-science-types"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9f663f48f40f1aaa0508732706271db4285c25977ee0e00d6c3582e2a6ec2f01",
"md5": "df35aa8171cfc8374c8f227a57e1de5a",
"sha256": "bca319abc0e53a0316f9fcb887937e942477cb9e5fc63c8581e0b0438903b977"
},
"downloads": -1,
"filename": "data_science_types-0.2.23-py3-none-any.whl",
"has_sig": false,
"md5_digest": "df35aa8171cfc8374c8f227a57e1de5a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 42682,
"upload_time": "2021-02-16T16:45:03",
"upload_time_iso_8601": "2021-02-16T16:45:03.733539Z",
"url": "https://files.pythonhosted.org/packages/9f/66/3f48f40f1aaa0508732706271db4285c25977ee0e00d6c3582e2a6ec2f01/data_science_types-0.2.23-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ae5f6c4888c17fa53c551df740d93806c68f1d5eed6b6167747087415e50dccb",
"md5": "c899a88e472d21eb7ccdaa382fe0bc65",
"sha256": "8096b9a35a8a187bf9a122b4707c97de841d810744690ee2a4ac30c6462e0d16"
},
"downloads": -1,
"filename": "data-science-types-0.2.23.tar.gz",
"has_sig": false,
"md5_digest": "c899a88e472d21eb7ccdaa382fe0bc65",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 35914,
"upload_time": "2021-02-16T16:45:05",
"upload_time_iso_8601": "2021-02-16T16:45:05.066054Z",
"url": "https://files.pythonhosted.org/packages/ae/5f/6c4888c17fa53c551df740d93806c68f1d5eed6b6167747087415e50dccb/data-science-types-0.2.23.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2021-02-16 16:45:05",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "predictive-analytics-lab",
"github_project": "data-science-types",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "data-science-types"
}