Skip to content

Commit 9effe4c

Browse files
Used less technical terms and less details. User guide
1 parent ccb601e commit 9effe4c

File tree

2 files changed

+119
-14
lines changed

2 files changed

+119
-14
lines changed

doc/source/ecosystem.rst

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -577,18 +577,75 @@ Library Accessor Classes Description
577577
.. _woodwork: https://github.com/alteryx/woodwork
578578

579579

580-
Type stubs
580+
Development tools
581581
----------------------------
582582

583583
`pandas-stubs <https://github.com/VirtusLab/pandas-stubs>`__
584584
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
585585

586-
pandas by itself doesn't expose any type information to the user.
587-
This means that in pandas-dependent projects the type checkers like mypy won't perform like expected
588-
and will treat all pandas objects as they were of type ``Any``.
586+
pandas doesn't expose any type information to the user by itself.
587+
Install pandas-stubs to enable basic type coverage of pandas API.
588+
589589
Learn more by reading through these issues `14468 <https://github.com/pandas-dev/pandas/issues/14468>`_,
590590
`26766 <https://github.com/pandas-dev/pandas/issues/26766>`_, `28142 <https://github.com/pandas-dev/pandas/issues/28142>`_.
591591

592-
pandas-stubs are meant to alleviate this issue by providing basic type coverage of pandas API.
593-
After installing it using ``pip`` or ``conda``, the ``.pyi`` files will be
594-
placed alongside the pandas ``.py`` files and be available for the type checker.
592+
Installation
593+
^^^^^^^^^^^^
594+
595+
Using pip:
596+
597+
.. code:: bash
598+
599+
pip install pandas-stubs
600+
601+
Using conda:
602+
603+
.. code:: bash
604+
605+
conda install -c conda-forge pandas-stubs
606+
607+
Alternatively the manual options are:
608+
609+
* cloning the repository along with the files, or
610+
* including it as a submodule to your project repository,
611+
612+
and then configuring a type checker with the correct paths.
613+
614+
Usage
615+
^^^^^
616+
617+
Let’s take this piece of code as an example in file round.py
618+
619+
.. code:: python
620+
621+
import pandas as pd
622+
623+
decimals = pd.DataFrame({'TSLA': 3, 'AMZN': 2})
624+
prices = pd.DataFrame(data={'date': ['2021-08-13', '2021-08-07', '2021-08-21'],
625+
'TSLA': [720.13, 716.22, 731.22], 'AMZN': [3316.50, 3200.50, 3100.23]})
626+
sorted_prices = prices.round(decimals=decimals)
627+
628+
629+
mypy won't see any issues with that but after installing pandas-stubs and running it again
630+
631+
.. code:: bash
632+
633+
mypy round.py
634+
635+
636+
we get the following error message
637+
638+
.. code:: bash
639+
640+
round.py:6: error: Argument "decimals" to "round" of "DataFrame" has incompatible type "DataFrame";
641+
expected "Union[int, Dict[Union[int, str], int], Series]"
642+
643+
644+
And after confirming with the `docs <https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.round.html>`_
645+
we can fix the code
646+
647+
.. code:: python
648+
649+
decimals = pd.Series({'TSLA': 3, 'AMZN': 2})
650+
651+

web/pandas/community/ecosystem.md

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -389,16 +389,64 @@ authors to coordinate on the namespace.
389389
| [composeml](https://github.com/alteryx/compose) | `slice` | `DataFrame` |
390390
| [woodwork](https://github.com/alteryx/woodwork) | `slice` | `Series`, `DataFrame` |
391391

392-
## Type stubs
392+
## Development tools
393393

394394
### [pandas-stubs](https://github.com/VirtusLab/pandas-stubs)
395395

396-
pandas by itself doesn't expose any type information to the user.
397-
This means that in pandas-dependent projects the type checkers like mypy won't perform like expected
398-
and will treat all pandas objects as they were of type `Any`.
396+
pandas doesn't expose any type information to the user by itself.
397+
Install pandas-stubs to enable basic type coverage of pandas API.
398+
399399
Learn more by reading through these issues [14468](https://github.com/pandas-dev/pandas/issues/14468),
400400
[26766](https://github.com/pandas-dev/pandas/issues/26766), [28142](https://github.com/pandas-dev/pandas/issues/28142).
401401

402-
pandas-stubs are meant to alleviate this issue by providing basic type coverage of pandas API.
403-
After installing it using `pip` or `conda`, the `.pyi` files will be
404-
placed alongside the pandas `.py` files and be available for the type checker.
402+
#### Installation
403+
404+
Using pip:
405+
```
406+
pip install pandas-stubs
407+
```
408+
409+
Using conda:
410+
411+
```
412+
conda install -c conda-forge pandas-stubs
413+
```
414+
415+
Alternatively the manual install options are:
416+
417+
* cloning the repository along with the files, or
418+
* including it as a submodule to your project repository,
419+
420+
and then configuring a type checker with the correct paths.
421+
422+
#### Usage
423+
424+
Let’s take this piece of code as an example in file round.py
425+
426+
```
427+
import pandas as pd
428+
429+
decimals = pd.DataFrame({'TSLA': 3, 'AMZN': 2})
430+
prices = pd.DataFrame(data={'date': ['2021-08-13', '2021-08-07', '2021-08-21'],
431+
'TSLA': [720.13, 716.22, 731.22], 'AMZN': [3316.50, 3200.50, 3100.23]})
432+
sorted_prices = prices.round(decimals=decimals)
433+
```
434+
435+
mypy won't see any issues with that but after installing pandas-stubs and running it again
436+
437+
```
438+
mypy round.py
439+
```
440+
441+
we get the following error message
442+
443+
```
444+
round.py:6: error: Argument "decimals" to "round" of "DataFrame" has incompatible type "DataFrame"; expected "Union[int, Dict[Union[int, str], int], Series]"
445+
```
446+
447+
And after confirming with the [docs](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.round.html)
448+
we can fix the code
449+
450+
```
451+
decimals = pd.Series({'TSLA': 3, 'AMZN': 2})
452+
```

0 commit comments

Comments
 (0)