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
* typo fix: 'too' -> 'to'
* standardise spaces after '.' within paragraph
All other ends of sentences (period/full stop, '.') are followed by two
spaces - these are followed by one. Making these match.
Note this has no impact on rendering, Markdown only creates a single
rendered space after a '.' in either case.
* remove trailing whitespace in paragraph
All other lines in this paragraph have no trailing whitespace, remove
this single trailing whitespace to match.
Note that this has no impact on the rendering of the Markdown.
* standardise spaces after '.' for whole philsophy doc
As with previous commit, but for the whole document.
Found using the regex "\. ([^ ])" and replacing with ". $1".
All other ends of sentences (period/full stop, '.') are followed by two
spaces - these are followed by one. Making these match.
Note this has no impact on rendering, Markdown only creates a single
rendered space after a '.' in either case.
* remove trailing whitespace for whole philosophy doc
As with previous commit, but for the whole document.
Found using the regex "\s$".
All other lines have no trailing whitespace, remove these single
trailing whitespaces to match.
Note that this has no impact on the rendering of the Markdown.
Copy file name to clipboardExpand all lines: docs/philosophy.md
+13-13Lines changed: 13 additions & 13 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.
@@ -108,9 +108,9 @@ Here is an example that illustrates this concept, from `tests/test_interval.py`:
108
108
In this particular example, the stubs consider that `i1` will have the type
109
109
`pd.Interval[pd.Timestamp]`. It is incorrect code to add a `Timestamp` to a
110
110
time-based interval. Without the `if TYPE_CHECKING_INVALID_USAGE` construct, the
111
-
code would fail at runtime. Further, type checkers should report an error for this
112
-
incorrect code. By placing the `# type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]`
113
-
on the line, type checkers are told to ignore the type error. To ensure that the
111
+
code would fail at runtime. Further, type checkers should report an error for this
112
+
incorrect code. By placing the `# type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]`
113
+
on the line, type checkers are told to ignore the type error. To ensure that the
114
114
pandas-stubs annotations are not too wide (allow adding a `Timestamp` to a
115
115
time-based interval), mypy and pyright are configured to report unused ignore
0 commit comments