Skip to content

Commit 4af5756

Browse files
authored
STYLE: Enable ruff TCH on pandas/core/indexers and more (#51779)
enable ruff TCH
1 parent b391397 commit 4af5756

24 files changed

+153
-113
lines changed

pandas/core/groupby/generic.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,6 @@
3232
lib,
3333
reduction as libreduction,
3434
)
35-
from pandas._typing import (
36-
ArrayLike,
37-
Axis,
38-
AxisInt,
39-
CorrelationMethod,
40-
FillnaOptions,
41-
IndexLabel,
42-
Manager,
43-
Manager2D,
44-
SingleManager,
45-
TakeIndexer,
46-
)
4735
from pandas.errors import SpecificationError
4836
from pandas.util._decorators import (
4937
Appender,
@@ -96,6 +84,19 @@
9684
from pandas.plotting import boxplot_frame_groupby
9785

9886
if TYPE_CHECKING:
87+
from pandas._typing import (
88+
ArrayLike,
89+
Axis,
90+
AxisInt,
91+
CorrelationMethod,
92+
FillnaOptions,
93+
IndexLabel,
94+
Manager,
95+
Manager2D,
96+
SingleManager,
97+
TakeIndexer,
98+
)
99+
99100
from pandas import Categorical
100101
from pandas.core.generic import NDFrame
101102

pandas/core/groupby/grouper.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@
1717
from pandas._config import using_copy_on_write
1818

1919
from pandas._libs import lib
20-
from pandas._typing import (
21-
ArrayLike,
22-
Axis,
23-
NDFrameT,
24-
npt,
25-
)
2620
from pandas.errors import InvalidIndexError
2721
from pandas.util._decorators import cache_readonly
2822
from pandas.util._exceptions import find_stack_level
@@ -52,6 +46,13 @@
5246
from pandas.io.formats.printing import pprint_thing
5347

5448
if TYPE_CHECKING:
49+
from pandas._typing import (
50+
ArrayLike,
51+
Axis,
52+
NDFrameT,
53+
npt,
54+
)
55+
5556
from pandas.core.generic import NDFrame
5657

5758

pandas/core/groupby/indexing.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import numpy as np
1111

12-
from pandas._typing import PositionalIndexer
1312
from pandas.util._decorators import (
1413
cache_readonly,
1514
doc,
@@ -21,6 +20,8 @@
2120
)
2221

2322
if TYPE_CHECKING:
23+
from pandas._typing import PositionalIndexer
24+
2425
from pandas import (
2526
DataFrame,
2627
Series,

pandas/core/groupby/numba_.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111

1212
import numpy as np
1313

14-
from pandas._typing import Scalar
1514
from pandas.compat._optional import import_optional_dependency
1615

1716
from pandas.core.util.numba_ import (
1817
NumbaUtilError,
1918
jit_user_function,
2019
)
2120

21+
if TYPE_CHECKING:
22+
from pandas._typing import Scalar
23+
2224

2325
def validate_udf(func: Callable) -> None:
2426
"""

pandas/core/indexers/utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
import numpy as np
1212

13-
from pandas._typing import AnyArrayLike
14-
1513
from pandas.core.dtypes.common import (
1614
is_array_like,
1715
is_bool_dtype,
@@ -26,6 +24,8 @@
2624
)
2725

2826
if TYPE_CHECKING:
27+
from pandas._typing import AnyArrayLike
28+
2929
from pandas.core.frame import DataFrame
3030
from pandas.core.indexes.base import Index
3131

pandas/core/indexes/api.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
from __future__ import annotations
22

33
import textwrap
4-
from typing import cast
4+
from typing import (
5+
TYPE_CHECKING,
6+
cast,
7+
)
58

69
import numpy as np
710

811
from pandas._libs import (
912
NaT,
1013
lib,
1114
)
12-
from pandas._typing import Axis
1315
from pandas.errors import InvalidIndexError
1416

1517
from pandas.core.dtypes.cast import find_common_type
@@ -30,6 +32,8 @@
3032
from pandas.core.indexes.range import RangeIndex
3133
from pandas.core.indexes.timedeltas import TimedeltaIndex
3234

35+
if TYPE_CHECKING:
36+
from pandas._typing import Axis
3337
_sort_msg = textwrap.dedent(
3438
"""\
3539
Sorting because non-concatenation axis is not aligned. A future version

pandas/core/indexes/category.py

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

33
from typing import (
4+
TYPE_CHECKING,
45
Any,
56
Hashable,
67
)
78

89
import numpy as np
910

1011
from pandas._libs import index as libindex
11-
from pandas._typing import (
12-
Dtype,
13-
DtypeObj,
14-
npt,
15-
)
1612
from pandas.util._decorators import (
1713
cache_readonly,
1814
doc,
@@ -45,6 +41,12 @@
4541

4642
from pandas.io.formats.printing import pprint_thing
4743

44+
if TYPE_CHECKING:
45+
from pandas._typing import (
46+
Dtype,
47+
DtypeObj,
48+
npt,
49+
)
4850
_index_doc_kwargs: dict[str, str] = dict(ibase._index_doc_kwargs)
4951
_index_doc_kwargs.update({"target_klass": "CategoricalIndex"})
5052

pandas/core/indexes/datetimelike.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
ABC,
88
abstractmethod,
99
)
10-
from datetime import datetime
1110
from typing import (
1211
TYPE_CHECKING,
1312
Any,
@@ -32,10 +31,6 @@
3231
parsing,
3332
to_offset,
3433
)
35-
from pandas._typing import (
36-
Axis,
37-
npt,
38-
)
3934
from pandas.compat.numpy import function as nv
4035
from pandas.errors import NullFrequencyError
4136
from pandas.util._decorators import (
@@ -70,6 +65,13 @@
7065
from pandas.core.tools.timedeltas import to_timedelta
7166

7267
if TYPE_CHECKING:
68+
from datetime import datetime
69+
70+
from pandas._typing import (
71+
Axis,
72+
npt,
73+
)
74+
7375
from pandas import CategoricalIndex
7476

7577
_index_doc_kwargs = dict(ibase._index_doc_kwargs)

pandas/core/indexes/datetimes.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,6 @@
2525
to_offset,
2626
)
2727
from pandas._libs.tslibs.offsets import prefix_mapping
28-
from pandas._typing import (
29-
Dtype,
30-
DtypeObj,
31-
Frequency,
32-
IntervalClosedType,
33-
TimeAmbiguous,
34-
TimeNonexistent,
35-
npt,
36-
)
3728
from pandas.util._decorators import (
3829
cache_readonly,
3930
doc,
@@ -60,6 +51,16 @@
6051
from pandas.core.tools.times import to_time
6152

6253
if TYPE_CHECKING:
54+
from pandas._typing import (
55+
Dtype,
56+
DtypeObj,
57+
Frequency,
58+
IntervalClosedType,
59+
TimeAmbiguous,
60+
TimeNonexistent,
61+
npt,
62+
)
63+
6364
from pandas.core.api import (
6465
DataFrame,
6566
PeriodIndex,

pandas/core/indexes/extension.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111

1212
import numpy as np
1313

14-
from pandas._typing import (
15-
ArrayLike,
16-
npt,
17-
)
1814
from pandas.util._decorators import (
1915
cache_readonly,
2016
doc,
@@ -25,6 +21,11 @@
2521
from pandas.core.indexes.base import Index
2622

2723
if TYPE_CHECKING:
24+
from pandas._typing import (
25+
ArrayLike,
26+
npt,
27+
)
28+
2829
from pandas.core.arrays import IntervalArray
2930
from pandas.core.arrays._mixins import NDArrayBackedExtensionArray
3031

pandas/core/indexes/interval.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
)
88
import textwrap
99
from typing import (
10+
TYPE_CHECKING,
1011
Any,
1112
Hashable,
1213
Literal,
@@ -26,12 +27,6 @@
2627
Timestamp,
2728
to_offset,
2829
)
29-
from pandas._typing import (
30-
Dtype,
31-
DtypeObj,
32-
IntervalClosedType,
33-
npt,
34-
)
3530
from pandas.errors import InvalidIndexError
3631
from pandas.util._decorators import (
3732
Appender,
@@ -92,6 +87,13 @@
9287
timedelta_range,
9388
)
9489

90+
if TYPE_CHECKING:
91+
from pandas._typing import (
92+
Dtype,
93+
DtypeObj,
94+
IntervalClosedType,
95+
npt,
96+
)
9597
_index_doc_kwargs = dict(ibase._index_doc_kwargs)
9698

9799
_index_doc_kwargs.update(

pandas/core/indexes/period.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
datetime,
55
timedelta,
66
)
7-
from typing import Hashable
7+
from typing import (
8+
TYPE_CHECKING,
9+
Hashable,
10+
)
811

912
import numpy as np
1013

@@ -16,11 +19,6 @@
1619
Resolution,
1720
Tick,
1821
)
19-
from pandas._typing import (
20-
Dtype,
21-
DtypeObj,
22-
npt,
23-
)
2422
from pandas.util._decorators import (
2523
cache_readonly,
2624
doc,
@@ -46,6 +44,12 @@
4644
)
4745
from pandas.core.indexes.extension import inherit_names
4846

47+
if TYPE_CHECKING:
48+
from pandas._typing import (
49+
Dtype,
50+
DtypeObj,
51+
npt,
52+
)
4953
_index_doc_kwargs = dict(ibase._index_doc_kwargs)
5054
_index_doc_kwargs.update({"target_klass": "PeriodIndex or list of Periods"})
5155
_shared_doc_kwargs = {

pandas/core/indexes/range.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import operator
55
from sys import getsizeof
66
from typing import (
7+
TYPE_CHECKING,
78
Any,
89
Callable,
910
Hashable,
@@ -20,10 +21,6 @@
2021
)
2122
from pandas._libs.algos import unique_deltas
2223
from pandas._libs.lib import no_default
23-
from pandas._typing import (
24-
Dtype,
25-
npt,
26-
)
2724
from pandas.compat.numpy import function as nv
2825
from pandas.util._decorators import (
2926
cache_readonly,
@@ -51,6 +48,11 @@
5148
)
5249
from pandas.core.ops.common import unpack_zerodim_and_defer
5350

51+
if TYPE_CHECKING:
52+
from pandas._typing import (
53+
Dtype,
54+
npt,
55+
)
5456
_empty_range = range(0)
5557

5658

pandas/core/indexes/timedeltas.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
""" implement the TimedeltaIndex """
22
from __future__ import annotations
33

4+
from typing import TYPE_CHECKING
5+
46
from pandas._libs import (
57
index as libindex,
68
lib,
@@ -10,7 +12,6 @@
1012
Timedelta,
1113
to_offset,
1214
)
13-
from pandas._typing import DtypeObj
1415

1516
from pandas.core.dtypes.common import (
1617
is_dtype_equal,
@@ -28,6 +29,9 @@
2829
from pandas.core.indexes.datetimelike import DatetimeTimedeltaMixin
2930
from pandas.core.indexes.extension import inherit_names
3031

32+
if TYPE_CHECKING:
33+
from pandas._typing import DtypeObj
34+
3135

3236
@inherit_names(
3337
["__neg__", "__pos__", "__abs__", "total_seconds", "round", "floor", "ceil"]

0 commit comments

Comments
 (0)