Skip to content

Commit d385465

Browse files
authored
STYLE start enabling TCH (#51687)
* start enabling TCH * fixup * fixup --------- Co-authored-by: MarcoGorelli <>
1 parent b056c63 commit d385465

File tree

18 files changed

+119
-42
lines changed

18 files changed

+119
-42
lines changed

pandas/_config/config.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,8 @@
6666
)
6767
import warnings
6868

69-
from pandas._typing import (
70-
F,
71-
T,
72-
)
69+
from pandas._typing import F # noqa: TCH001
70+
from pandas._typing import T # noqa: TCH001
7371
from pandas.util._exceptions import find_stack_level
7472

7573

pandas/_testing/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@
2525
set_locale,
2626
)
2727

28-
from pandas._typing import (
29-
Dtype,
30-
Frequency,
31-
NpDtype,
32-
)
3328
from pandas.compat import pa_version_under7p0
3429

3530
from pandas.core.dtypes.common import (
@@ -118,6 +113,12 @@
118113
from pandas.core.construction import extract_array
119114

120115
if TYPE_CHECKING:
116+
from pandas._typing import (
117+
Dtype,
118+
Frequency,
119+
NpDtype,
120+
)
121+
121122
from pandas import (
122123
PeriodIndex,
123124
TimedeltaIndex,

pandas/_testing/_io.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
)
1414
import zipfile
1515

16-
from pandas._typing import (
17-
FilePath,
18-
ReadPickleBuffer,
19-
)
2016
from pandas.compat import get_lzma_file
2117
from pandas.compat._optional import import_optional_dependency
2218

@@ -27,6 +23,11 @@
2723
from pandas.io.common import urlopen
2824

2925
if TYPE_CHECKING:
26+
from pandas._typing import (
27+
FilePath,
28+
ReadPickleBuffer,
29+
)
30+
3031
from pandas import (
3132
DataFrame,
3233
Series,

pandas/_testing/_random.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
from __future__ import annotations
2+
13
import string
4+
from typing import TYPE_CHECKING
25

36
import numpy as np
47

5-
from pandas._typing import NpDtype
6-
8+
if TYPE_CHECKING:
9+
from pandas._typing import NpDtype
710
RANDS_CHARS = np.array(list(string.ascii_letters + string.digits), dtype=(np.str_, 1))
811

912

pandas/_testing/compat.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
"""
22
Helpers for sharing tests between DataFrame/Series
33
"""
4-
from pandas._typing import DtypeObj
4+
from __future__ import annotations
5+
6+
from typing import TYPE_CHECKING
57

68
from pandas import DataFrame
79

10+
if TYPE_CHECKING:
11+
from pandas._typing import DtypeObj
12+
813

914
def get_dtype(obj) -> DtypeObj:
1015
if isinstance(obj, DataFrame):

pandas/_testing/contexts.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,26 @@
66
import tempfile
77
from typing import (
88
IO,
9+
TYPE_CHECKING,
910
Any,
1011
Generator,
1112
)
1213
import uuid
1314

14-
from pandas._typing import (
15-
BaseBuffer,
16-
CompressionOptions,
17-
FilePath,
18-
)
1915
from pandas.compat import PYPY
2016
from pandas.errors import ChainedAssignmentError
2117

2218
from pandas import set_option
2319

2420
from pandas.io.common import get_handle
2521

22+
if TYPE_CHECKING:
23+
from pandas._typing import (
24+
BaseBuffer,
25+
CompressionOptions,
26+
FilePath,
27+
)
28+
2629

2730
@contextmanager
2831
def decompress_file(

pandas/compat/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
import os
1313
import platform
1414
import sys
15+
from typing import TYPE_CHECKING
1516

16-
from pandas._typing import F
1717
from pandas.compat._constants import (
1818
IS64,
1919
PY39,
@@ -33,6 +33,9 @@
3333
pa_version_under11p0,
3434
)
3535

36+
if TYPE_CHECKING:
37+
from pandas._typing import F
38+
3639

3740
def set_function_name(f: F, name: str, cls) -> F:
3841
"""

pandas/compat/_optional.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
import importlib
44
import sys
5-
import types
5+
from typing import TYPE_CHECKING
66
import warnings
77

88
from pandas.util._exceptions import find_stack_level
99

1010
from pandas.util.version import Version
1111

12+
if TYPE_CHECKING:
13+
import types
14+
1215
# Update install.rst & setup.cfg when updating versions!
1316

1417
VERSIONS = {

pandas/compat/numpy/function.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from __future__ import annotations
1919

2020
from typing import (
21+
TYPE_CHECKING,
2122
Any,
2223
TypeVar,
2324
cast,
@@ -30,18 +31,20 @@
3031
is_bool,
3132
is_integer,
3233
)
33-
from pandas._typing import (
34-
Axis,
35-
AxisInt,
36-
)
3734
from pandas.errors import UnsupportedFunctionCall
3835
from pandas.util._validators import (
3936
validate_args,
4037
validate_args_and_kwargs,
4138
validate_kwargs,
4239
)
4340

44-
AxisNoneT = TypeVar("AxisNoneT", Axis, None)
41+
if TYPE_CHECKING:
42+
from pandas._typing import (
43+
Axis,
44+
AxisInt,
45+
)
46+
47+
AxisNoneT = TypeVar("AxisNoneT", Axis, None)
4548

4649

4750
class CompatValidator:

pandas/core/_numba/executor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
Callable,
77
)
88

9+
if TYPE_CHECKING:
10+
from pandas._typing import Scalar
11+
912
import numpy as np
1013

11-
from pandas._typing import Scalar
1214
from pandas.compat._optional import import_optional_dependency
1315

1416

0 commit comments

Comments
 (0)