Skip to content

Commit edf1ba1

Browse files
authored
STYLE: Enable ruff TCH on some files (pandas-dev#51812)
* STYLE: enable ruff TCH * Fix circular import
1 parent 178e504 commit edf1ba1

Some content is hidden

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

53 files changed

+388
-285
lines changed

pandas/core/reshape/concat.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
1919

2020
from pandas._config import using_copy_on_write
2121

22-
from pandas._typing import (
23-
Axis,
24-
AxisInt,
25-
HashableT,
26-
)
2722
from pandas.util._decorators import cache_readonly
2823

2924
from pandas.core.dtypes.concat import concat_compat
@@ -51,6 +46,12 @@
5146
from pandas.core.internals import concatenate_managers
5247

5348
if TYPE_CHECKING:
49+
from pandas._typing import (
50+
Axis,
51+
AxisInt,
52+
HashableT,
53+
)
54+
5455
from pandas import (
5556
DataFrame,
5657
Series,

pandas/core/reshape/encoding.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
from collections import defaultdict
44
import itertools
55
from typing import (
6+
TYPE_CHECKING,
67
Hashable,
78
Iterable,
89
)
910

1011
import numpy as np
1112

1213
from pandas._libs.sparse import IntIndex
13-
from pandas._typing import NpDtype
1414

1515
from pandas.core.dtypes.common import (
1616
is_integer_dtype,
@@ -28,6 +28,9 @@
2828
)
2929
from pandas.core.series import Series
3030

31+
if TYPE_CHECKING:
32+
from pandas._typing import NpDtype
33+
3134

3235
def get_dummies(
3336
data,

pandas/core/reshape/pivot.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111
import numpy as np
1212

1313
from pandas._libs import lib
14-
from pandas._typing import (
15-
AggFuncType,
16-
AggFuncTypeBase,
17-
AggFuncTypeDict,
18-
IndexLabel,
19-
)
2014
from pandas.util._decorators import (
2115
Appender,
2216
Substitution,
@@ -48,6 +42,13 @@
4842
from pandas.core.series import Series
4943

5044
if TYPE_CHECKING:
45+
from pandas._typing import (
46+
AggFuncType,
47+
AggFuncTypeBase,
48+
AggFuncTypeDict,
49+
IndexLabel,
50+
)
51+
5152
from pandas import DataFrame
5253

5354

pandas/core/reshape/reshape.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import numpy as np
1111

1212
import pandas._libs.reshape as libreshape
13-
from pandas._typing import npt
1413
from pandas.errors import PerformanceWarning
1514
from pandas.util._decorators import cache_readonly
1615
from pandas.util._exceptions import find_stack_level
@@ -44,6 +43,8 @@
4443
)
4544

4645
if TYPE_CHECKING:
46+
from pandas._typing import npt
47+
4748
from pandas.core.arrays import ExtensionArray
4849
from pandas.core.indexes.frozen import FrozenList
4950

pandas/core/reshape/tile.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from __future__ import annotations
55

66
from typing import (
7+
TYPE_CHECKING,
78
Any,
89
Callable,
910
Literal,
@@ -16,7 +17,6 @@
1617
Timestamp,
1718
)
1819
from pandas._libs.lib import infer_dtype
19-
from pandas._typing import IntervalLeftRight
2020

2121
from pandas.core.dtypes.common import (
2222
DT64NS_DTYPE,
@@ -46,6 +46,9 @@
4646
from pandas.core import nanops
4747
import pandas.core.algorithms as algos
4848

49+
if TYPE_CHECKING:
50+
from pandas._typing import IntervalLeftRight
51+
4952

5053
def cut(
5154
x,

pandas/core/reshape/util.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
from __future__ import annotations
22

3-
import numpy as np
3+
from typing import TYPE_CHECKING
44

5-
from pandas._typing import NumpyIndexT
5+
import numpy as np
66

77
from pandas.core.dtypes.common import is_list_like
88

9+
if TYPE_CHECKING:
10+
from pandas._typing import NumpyIndexT
11+
912

1013
def cartesian_product(X) -> list[np.ndarray]:
1114
"""

pandas/core/strings/base.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import abc
4-
import re
54
from typing import (
65
TYPE_CHECKING,
76
Callable,
@@ -10,9 +9,11 @@
109

1110
import numpy as np
1211

13-
from pandas._typing import Scalar
14-
1512
if TYPE_CHECKING:
13+
import re
14+
15+
from pandas._typing import Scalar
16+
1617
from pandas import Series
1718

1819

pandas/core/strings/object_array.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@
1616
from pandas._libs import lib
1717
import pandas._libs.missing as libmissing
1818
import pandas._libs.ops as libops
19-
from pandas._typing import (
20-
NpDtype,
21-
Scalar,
22-
)
2319

2420
from pandas.core.dtypes.common import is_scalar
2521
from pandas.core.dtypes.missing import isna
2622

2723
from pandas.core.strings.base import BaseStringArrayMethods
2824

2925
if TYPE_CHECKING:
26+
from pandas._typing import (
27+
NpDtype,
28+
Scalar,
29+
)
30+
3031
from pandas import Series
3132

3233

pandas/core/tools/numeric.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from __future__ import annotations
22

3-
from typing import Literal
3+
from typing import (
4+
TYPE_CHECKING,
5+
Literal,
6+
)
47

58
import numpy as np
69

@@ -10,10 +13,6 @@
1013
)
1114

1215
from pandas._libs import lib
13-
from pandas._typing import (
14-
DateTimeErrorChoices,
15-
npt,
16-
)
1716

1817
from pandas.core.dtypes.cast import maybe_downcast_numeric
1918
from pandas.core.dtypes.common import (
@@ -36,6 +35,12 @@
3635
import pandas as pd
3736
from pandas.core.arrays import BaseMaskedArray
3837

38+
if TYPE_CHECKING:
39+
from pandas._typing import (
40+
DateTimeErrorChoices,
41+
npt,
42+
)
43+
3944

4045
def to_numeric(
4146
arg,

pandas/core/tools/timedeltas.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44
from __future__ import annotations
55

6-
from datetime import timedelta
76
from typing import (
87
TYPE_CHECKING,
98
overload,
@@ -30,6 +29,8 @@
3029
from pandas.core.arrays.timedeltas import sequence_to_td64ns
3130

3231
if TYPE_CHECKING:
32+
from datetime import timedelta
33+
3334
from pandas._libs.tslibs.timedeltas import UnitChoices
3435
from pandas._typing import (
3536
ArrayLike,

pandas/core/tools/times.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@
44
datetime,
55
time,
66
)
7+
from typing import TYPE_CHECKING
78

89
import numpy as np
910

1011
from pandas._libs.lib import is_list_like
11-
from pandas._typing import DateTimeErrorChoices
1212

1313
from pandas.core.dtypes.generic import (
1414
ABCIndex,
1515
ABCSeries,
1616
)
1717
from pandas.core.dtypes.missing import notna
1818

19+
if TYPE_CHECKING:
20+
from pandas._typing import DateTimeErrorChoices
21+
1922

2023
def to_time(
2124
arg,

pandas/core/window/ewm.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@
99

1010
from pandas._libs.tslibs import Timedelta
1111
import pandas._libs.window.aggregations as window_aggregations
12-
from pandas._typing import (
13-
Axis,
14-
TimedeltaConvertibleTypes,
15-
)
16-
17-
if TYPE_CHECKING:
18-
from pandas import DataFrame, Series
19-
from pandas.core.generic import NDFrame
20-
2112
from pandas.util._decorators import doc
2213

2314
from pandas.core.dtypes.common import (
@@ -60,6 +51,18 @@
6051
BaseWindowGroupby,
6152
)
6253

54+
if TYPE_CHECKING:
55+
from pandas._typing import (
56+
Axis,
57+
TimedeltaConvertibleTypes,
58+
)
59+
60+
from pandas import (
61+
DataFrame,
62+
Series,
63+
)
64+
from pandas.core.generic import NDFrame
65+
6366

6467
def get_center_of_mass(
6568
comass: float | None,

pandas/core/window/expanding.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,6 @@
77
Callable,
88
)
99

10-
from pandas._typing import (
11-
Axis,
12-
QuantileInterpolation,
13-
WindowingRankType,
14-
)
15-
16-
if TYPE_CHECKING:
17-
from pandas import DataFrame, Series
18-
from pandas.core.generic import NDFrame
19-
2010
from pandas.util._decorators import doc
2111

2212
from pandas.core.indexers.objects import (
@@ -40,6 +30,19 @@
4030
RollingAndExpandingMixin,
4131
)
4232

33+
if TYPE_CHECKING:
34+
from pandas._typing import (
35+
Axis,
36+
QuantileInterpolation,
37+
WindowingRankType,
38+
)
39+
40+
from pandas import (
41+
DataFrame,
42+
Series,
43+
)
44+
from pandas.core.generic import NDFrame
45+
4346

4447
class Expanding(RollingAndExpandingMixin):
4548
"""

pandas/core/window/numba_.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99

1010
import numpy as np
1111

12-
from pandas._typing import Scalar
1312
from pandas.compat._optional import import_optional_dependency
1413

1514
from pandas.core.util.numba_ import jit_user_function
1615

16+
if TYPE_CHECKING:
17+
from pandas._typing import Scalar
18+
1719

1820
@functools.lru_cache(maxsize=None)
1921
def generate_numba_apply_func(

pandas/core/window/rolling.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@
2626
to_offset,
2727
)
2828
import pandas._libs.window.aggregations as window_aggregations
29-
from pandas._typing import (
30-
ArrayLike,
31-
Axis,
32-
NDFrameT,
33-
QuantileInterpolation,
34-
WindowingRankType,
35-
)
3629
from pandas.compat._optional import import_optional_dependency
3730
from pandas.errors import DataError
3831
from pandas.util._decorators import doc
@@ -99,6 +92,14 @@
9992
)
10093

10194
if TYPE_CHECKING:
95+
from pandas._typing import (
96+
ArrayLike,
97+
Axis,
98+
NDFrameT,
99+
QuantileInterpolation,
100+
WindowingRankType,
101+
)
102+
102103
from pandas import (
103104
DataFrame,
104105
Series,

pandas/io/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# ruff: noqa: TCH004
12
from typing import TYPE_CHECKING
23

34
if TYPE_CHECKING:
@@ -8,5 +9,5 @@
89
stata,
910
)
1011

11-
# and mark only those modules as public
12+
# mark only those modules as public
1213
__all__ = ["formats", "json", "stata"]

0 commit comments

Comments
 (0)