Skip to content

Commit ba7aa5f

Browse files
committed
Copy from microsoft/python-type-stubs
1 parent e8edbf8 commit ba7aa5f

File tree

145 files changed

+12780
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+12780
-0
lines changed

pyproject.toml

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
[tool.black]
2+
line_length = 88
3+
target_version = ["py39"]
4+
5+
[tool.isort]
6+
profile = "black"
7+
combine_as_imports = true
8+
line_length = 88
9+
extra_standard_library = [
10+
"typing_extensions",
11+
"_typeshed",
12+
# Extra modules not recognized by isort
13+
"_compression",
14+
"_csv",
15+
"_curses",
16+
"_markupbase",
17+
"_random",
18+
"_weakrefset",
19+
"genericpath",
20+
"opcode",
21+
"pyexpat",
22+
# Python 2 modules
23+
"__builtin__",
24+
"cookielib",
25+
"cStringIO",
26+
"httplib",
27+
"mimetools",
28+
"rfc822",
29+
"thread",
30+
"urllib2",
31+
"urlparse",
32+
"BaseHTTPServer",
33+
"Queue",
34+
"SimpleHTTPServer",
35+
"SocketServer",
36+
"StringIO",
37+
"UserDict",
38+
"UserList",
39+
"UserString",
40+
]
41+
42+
[tool.mypy]
43+
# Import discovery
44+
mypy_path = "typings"
45+
namespace_packages = false
46+
explicit_package_bases = false
47+
ignore_missing_imports = true
48+
follow_imports = "normal"
49+
follow_imports_for_stubs = false
50+
no_site_packages = false
51+
no_silence_site_packages = false
52+
# Platform configuration
53+
python_version = "3.8"
54+
# Disallow dynamic typing
55+
disallow_any_unimported = false # TODO
56+
disallow_any_expr = false # TODO
57+
disallow_any_decorated = false # TODO
58+
disallow_any_explicit = false # TODO
59+
disallow_any_generics = false # TODO
60+
disallow_subclassing_any = false # TODO
61+
# Untyped definitions and calls
62+
disallow_untyped_calls = false # TODO
63+
disallow_untyped_defs = false # TODO
64+
disallow_incomplete_defs = false # TODO
65+
check_untyped_defs = true
66+
disallow_untyped_decorators = true
67+
# None and Optional handling
68+
no_implicit_optional = true
69+
strict_optional = true
70+
# Configuring warnings
71+
warn_redundant_casts = true
72+
warn_unused_ignores = false # Change from pandas
73+
warn_no_return = true
74+
warn_return_any = false # TODO
75+
warn_unreachable = false # GH#27396
76+
# Suppressing errors
77+
show_none_errors = true
78+
ignore_errors = false
79+
# Miscellaneous strictness flags
80+
allow_untyped_globals = false
81+
allow_redefinition = false
82+
local_partial_types = false
83+
implicit_reexport = true
84+
strict_equality = true
85+
# Configuring error messages
86+
show_error_context = false
87+
show_column_numbers = false
88+
show_error_codes = true

pyrighttestconfig.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"typeCheckingMode": "basic",
3+
"include": [ "tests" ],
4+
"reportMissingModuleSource": false,
5+
"reportUnusedVariable": false,
6+
"useLibraryCodeForTypes": true,
7+
"reportUnknownArgumentType": true
8+
}

tests/__init__.py

Whitespace-only changes.

tests/pandas/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
These tests originally came from https://github.com/VirtusLab/pandas-stubs.
2+
3+

tests/pandas/__init__.py

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
from typing import Union, Optional, Type, TYPE_CHECKING
2+
import numpy as np
3+
import numpy.typing as npt
4+
5+
import pandas as pd
6+
7+
from pandas._typing import Dtype
8+
9+
10+
# The purpose of these checkers is twofold:
11+
# 1) The type checker will see that the right result was returned
12+
# 2) When using pytest, we can check that the result in the pyi file
13+
# corresponds to what pandas returns
14+
15+
16+
def check_dataframe_result(result: pd.DataFrame):
17+
assert isinstance(result, pd.DataFrame)
18+
19+
20+
def check_series_result(result: pd.Series, dtype: Optional[Dtype] = None):
21+
"""
22+
Check that the result is a Series, and that the dtype is the specified dtype
23+
24+
Since pandas doesn't support typing of a Series, we can check the type
25+
in pytest instead.
26+
27+
Parameters
28+
----------
29+
result : pd.Series
30+
result to check
31+
dtype : Optional[Dtype], optional
32+
expected dtype, by default None, which means don't check the dtype
33+
"""
34+
assert isinstance(result, pd.Series)
35+
if dtype is not None:
36+
assert result.dtype == dtype
37+
38+
39+
def check_index_result(result: pd.Index, dtype: Optional[Dtype] = None):
40+
"""
41+
Check that the result is a Index, and that the dtype is the specified dtype
42+
43+
Since pandas doesn't support typing of a Index, we can check the type
44+
in pytest instead.
45+
46+
Parameters
47+
----------
48+
result : pd.Index
49+
result to check
50+
dtype : Optional[Dtype], optional
51+
expected dtype, by default None, which means don't check the dtype
52+
"""
53+
assert isinstance(result, pd.Index)
54+
if dtype is not None:
55+
assert result.dtype == dtype
56+
57+
58+
def check_multiindex_result(result: pd.MultiIndex):
59+
"""
60+
Check that the result is a MultiIndex
61+
62+
Parameters
63+
----------
64+
result : pd.MultiIndex
65+
A multiindex
66+
"""
67+
68+
assert isinstance(result, pd.MultiIndex)
69+
70+
71+
def check_datetimeindex_result(result: pd.DatetimeIndex):
72+
"""
73+
Check that the result is a DatetimeIndex
74+
75+
Parameters
76+
----------
77+
result : pd.DatetimeIndex
78+
result to check
79+
"""
80+
assert isinstance(result, pd.DatetimeIndex)
81+
82+
83+
def check_numpy_result(result: np.ndarray, dtype: Optional[Union[Type[np.int64], Type[np.bool_], Type[np.str_]]] = None):
84+
assert isinstance(result, np.ndarray)
85+
if dtype is not None:
86+
assert result.dtype == dtype
87+
88+
89+
def check_timedelta_result(result: pd.Timedelta):
90+
assert isinstance(result, pd.Timedelta)
91+
92+
93+
def check_timestamp_result(result: pd.Timestamp):
94+
assert isinstance(result, pd.Timestamp)
95+
96+
97+
def check_interval_result(
98+
result: pd.Interval, dtype: Optional[Union[Type[pd.Timestamp], Type[pd.Timedelta], Type[int], Type[float]]]
99+
):
100+
assert isinstance(result, pd.Interval)
101+
if dtype is not None:
102+
assert isinstance(result.left, dtype)
103+
104+
105+
def check_int_result(result: int):
106+
assert isinstance(result, int)
107+
108+
109+
def check_float_result(result: float):
110+
assert isinstance(result, float)
111+
112+
113+
def check_bool_result(result: bool):
114+
assert isinstance(result, bool)

0 commit comments

Comments
 (0)