You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+6-7Lines changed: 6 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ convention of providing stubs in a separate package, as specified in [PEP 561](h
17
17
pandas. In general, these stubs are narrower than what is possibly allowed by pandas,
18
18
but follow a convention of suggesting best recommended practices for using pandas.
19
19
20
-
The stubs are likely incomplete in terms of covering the published API of pandas.
20
+
The stubs are likely incomplete in terms of covering the published API of pandas. NOTE: The current 2.0.x releases of pandas-stubs do not support all of the new features of pandas 2.0. See this [tracker](https://github.com/pandas-dev/pandas-stubs/issues/624) to understand the current compatibility with version 2.0.
21
21
22
22
The stubs are tested with [mypy](http://mypy-lang.org/) and [pyright](https://github.com/microsoft/pyright#readme) and are currently shipped with the Visual Studio Code extension
@@ -137,20 +137,19 @@ Documentation is a work-in-progress.
137
137
138
138
## Background
139
139
140
-
These stubs are the result of a strategic effort lead by the core pandas team to integrate [Microsoft type stub repository](https://github.com/microsoft/python-type-stubs)
141
-
together with the [VirtusLabs pandas_stubs repository](https://github.com/VirtusLab/pandas-stubs).
140
+
These stubs are the result of a strategic effort led by the core pandas team to integrate [Microsoft type stub repository](https://github.com/microsoft/python-type-stubs) with the [VirtusLabs pandas_stubs repository](https://github.com/VirtusLab/pandas-stubs).
142
141
143
-
These stubs were initially forked from the Microsoft project <https://github.com/microsoft/python-type-stubs> as of [this commit](https://github.com/microsoft/python-type-stubs/tree/6b800063bde687cd1846122431e2a729a9de625a).
142
+
These stubs were initially forked from the Microsoft project at <https://github.com/microsoft/python-type-stubs> as of [this commit](https://github.com/microsoft/python-type-stubs/tree/6b800063bde687cd1846122431e2a729a9de625a).
144
143
145
-
We are indebted to Microsoft and that project for the initial set of public type stubs. We are also grateful for the original pandas-stubs project at <https://github.com/VirtusLab/pandas-stubs> that created the framework for testing the stubs.
144
+
We are indebted to Microsoft and that project for providing the initial set of public type stubs. We are also grateful for the original pandas-stubs project at <https://github.com/VirtusLab/pandas-stubs>, which created the framework for testing the stubs.
146
145
147
146
## Differences between type declarations in pandas and pandas-stubs
148
147
149
148
The <https://github.com/pandas-dev/pandas/> project has type declarations for some parts of pandas, both for the internal and public API's. Those type declarations are used to make sure that the pandas code is _internally_ consistent.
150
149
151
-
The <https://github.com/pandas-dev/pandas-stubs/> project provides type declarations for the pandas _public_ API. The philsophy of these stubs can be found at <https://github.com/pandas-dev/pandas-stubs/blob/main/docs/philosophy.md/> While it would be ideal if the `pyi` files in this project would be part of the `pandas` distribution, this would require consistency between the internal type declarations and the public declarations, and the scope of a project to create that consistency is quite large. That is a long term goal. Finally, another goal is to do more frequent releases of the pandas-stubs than is done for pandas, in order to make the stubs more useful.
150
+
The <https://github.com/pandas-dev/pandas-stubs/> project provides type declarations for the pandas _public_ API. The philosophy of these stubs can be found at <https://github.com/pandas-dev/pandas-stubs/blob/main/docs/philosophy.md/>. While it would be ideal if the `pyi` files in this project would be part of the `pandas` distribution, this would require consistency between the internal type declarations and the public declarations, and the scope of a project to create that consistency is quite large. That is a long term goal. Finally, another goal is to do more frequent releases of the pandas-stubs than is done for pandas, in order to make the stubs more useful.
152
151
153
-
If issues are found with the public stubs, pull requests to correct those issues are welcome. In addition, pull requests on the pandas repository to fix the same issue are welcome there as well. However, since the goals of typing in the two projects are different (internal consistency vs. public usage), it may be a challenge to create consistent type declarations across both projects. See <https://pandas.pydata.org/docs/development/contributing_codebase.html#type-hints/> for a discussion of typing standards used within the pandas code.
152
+
If issues are found with the public stubs, pull requests to correct those issues are welcome. In addition, pull requests on the pandas repository to fix the same issue are welcome there as well. However, since the goals of typing in the two projects are different (internal consistency vs. public usage), it may be a challenge to create consistent type declarations across both projects. See <https://pandas.pydata.org/docs/development/contributing_codebase.html#type-hints> for a discussion of typing standards used within the pandas code.
Copy file name to clipboardExpand all lines: docs/philosophy.md
+38-16Lines changed: 38 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
1
# pandas-stubs Type Checking Philosophy
2
2
3
3
The goal of the pandas-stubs project is to provide type stubs for the public API
4
-
that represent the recommended ways of using pandas. This is opposed to the
4
+
that represent the recommended ways of using pandas. This is opposed to the
5
5
philosophy within the pandas source, as described [here](https://pandas.pydata.org/docs/development/contributing_codebase.html?highlight=typing#type-hints), which
6
6
is to assist with the development of the pandas source code to ensure type safety within
7
7
that source.
8
8
9
-
Due to the methodology used by Microsoft to develop the original stubs, there are internal
9
+
Due to the methodology used by Microsoft to develop the original stubs, there are internal
10
10
classes, methods and functions that are annotated within the pandas-stubs project
11
11
that are incorrect with respect to the pandas source, but that have no effect on type
12
12
checking user code that calls the public API.
@@ -27,12 +27,12 @@ s = pd.Series([1, 2, 3])
27
27
lt = s <3
28
28
```
29
29
30
-
In the pandas source, `lt` is a `Series` with a `dtype` of `bool`. In the pandas-stubs,
31
-
the type of `lt` is `Series[bool]`. This allows further type checking to occur in other
30
+
In the pandas source, `lt` is a `Series` with a `dtype` of `bool`. In the pandas-stubs,
31
+
the type of `lt` is `Series[bool]`. This allows further type checking to occur in other
32
32
pandas methods. Note that in the above example, `s` is typed as `Series[Any]` because
33
33
its type cannot be statically inferred.
34
34
35
-
This also allows type checking for operations on series that contain date/time data. Consider
35
+
This also allows type checking for operations on series that contain date/time data. Consider
36
36
the following example that creates two series of datetimes with corresponding arithmetic.
37
37
38
38
```python
@@ -74,22 +74,22 @@ interval of `Timestamp`s.
74
74
A set of (most likely incomplete) tests for testing the type stubs is in the pandas-stubs
75
75
repository in the `tests` directory. The tests are used with `mypy` and `pyright` to
76
76
validate correct typing, and also with `pytest` to validate that the provided code
77
-
actually executes. The recent decision for Python 3.11 to include `assert_type()`,
77
+
actually executes. The recent decision for Python 3.11 to include `assert_type()`,
78
78
which is supported by `typing_extensions` version 4.2 and beyond makes it easier
79
-
to test to validate the return types of functions and methods. Future work
79
+
to test to validate the return types of functions and methods. Future work
80
80
is intended to expand the use of `assert_type()` in the test code.
81
81
82
82
## Narrow vs. Wide Arguments
83
83
84
-
A consideration in creating stubs is too make the set of type annotations for
84
+
A consideration in creating stubs is to make the set of type annotations for
85
85
function arguments "just right", i.e.,
86
86
not too narrow and not too wide. A type annotation to an argument to a function or
87
87
method is too narrow if it disallows valid arguments. A type annotation to
88
88
an argument to a function or method is too wide if
89
89
it allows invalid arguments. Testing for type annotations that are too narrow is rather
90
-
straightforward. It is easy to create an example for which the type checker indicates
90
+
straightforward. It is easy to create an example for which the type checker indicates
91
91
the argument is incorrect, and add it to the set of tests in the pandas-stubs
92
-
repository after fixing the appropriate stub. However, testing for when type annotations
92
+
repository after fixing the appropriate stub. However, testing for when type annotations
93
93
are too wide is a bit more complicated.
94
94
In this case, the test will fail when using `pytest`, but it is also desirable to
95
95
have type checkers report errors for code that is expected to fail type checking.
@@ -100,14 +100,36 @@ Here is an example that illustrates this concept, from `tests/test_interval.py`:
Copy file name to clipboardExpand all lines: docs/tests.md
+6-2Lines changed: 6 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,11 @@ Here are the most important options. Fore more details, please use `poe --help`.
11
11
- Run only pytest: `poe pytest`
12
12
- Run only pre-commit: `poe style`
13
13
- Run tests against the installed stubs (this will install and uninstall the stubs): `poe test_dist`
14
-
- Optional: run pytest against pandas nightly (this might fail): `poe pytest --nightly`
15
-
- Optional: Run stubtest to compare the installed pandas-stubs against pandas (this will fail): `poe stubtest`. If you have created an allowlist to ignore certain errors: `poe stubtest path_to_the_allow_list`
16
14
17
15
These tests originally came from https://github.com/VirtusLab/pandas-stubs.
16
+
17
+
The following tests are **optional**. Some of them are run by the CI but it is okay if they fail.
18
+
19
+
- Run pytest against pandas nightly: `poe pytest --nightly`
20
+
- Use mypy nightly to validate the annotations: `poe mypy --mypy_nightly`
21
+
- Run stubtest to compare the installed pandas-stubs against pandas (this will fail): `poe stubtest`. If you have created an allowlist to ignore certain errors: `poe stubtest path_to_the_allow_list`
0 commit comments