Skip to content

Commit acf3395

Browse files
ErdiTkMarcoGorelli
andauthored
Enabled ruff TCH on some files (#51827)
* Enabled ruff TCH on pandas/core/apply.py, pandas/core/base.py, pandas/core/algorithms.py, pandas/core/sorting.py and pandas/core/ops/*. Only for the last two items there were changes needed. * black and isort fixed after running SKIP=flake8-rst pre-commit run --all-files --------- Co-authored-by: Marco Edward Gorelli <[email protected]>
1 parent a53cf8d commit acf3395

File tree

5 files changed

+34
-24
lines changed

5 files changed

+34
-24
lines changed

pandas/core/ops/array_ops.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
import datetime
88
from functools import partial
99
import operator
10-
from typing import Any
10+
from typing import (
11+
TYPE_CHECKING,
12+
Any,
13+
)
1114

1215
import numpy as np
1316

@@ -19,10 +22,6 @@
1922
ops as libops,
2023
)
2124
from pandas._libs.tslibs import BaseOffset
22-
from pandas._typing import (
23-
ArrayLike,
24-
Shape,
25-
)
2625

2726
from pandas.core.dtypes.cast import (
2827
construct_1d_object_array_from_listlike,
@@ -54,6 +53,12 @@
5453
from pandas.core.ops.dispatch import should_extension_dispatch
5554
from pandas.core.ops.invalid import invalid_comparison
5655

56+
if TYPE_CHECKING:
57+
from pandas._typing import (
58+
ArrayLike,
59+
Shape,
60+
)
61+
5762
# -----------------------------------------------------------------------------
5863
# Masking NA values and fallbacks for operations numpy does not support
5964

pandas/core/ops/common.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,23 @@
55

66
from functools import wraps
77
import sys
8-
from typing import Callable
8+
from typing import (
9+
TYPE_CHECKING,
10+
Callable,
11+
)
912

1013
from pandas._libs.lib import item_from_zerodim
1114
from pandas._libs.missing import is_matching_na
12-
from pandas._typing import F
1315

1416
from pandas.core.dtypes.generic import (
1517
ABCDataFrame,
1618
ABCIndex,
1719
ABCSeries,
1820
)
1921

22+
if TYPE_CHECKING:
23+
from pandas._typing import F
24+
2025

2126
def unpack_zerodim_and_defer(name: str) -> Callable[[F], F]:
2227
"""

pandas/core/ops/dispatch.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
"""
44
from __future__ import annotations
55

6-
from typing import Any
7-
8-
from pandas._typing import ArrayLike
6+
from typing import (
7+
TYPE_CHECKING,
8+
Any,
9+
)
910

1011
from pandas.core.dtypes.generic import ABCExtensionArray
1112

13+
if TYPE_CHECKING:
14+
from pandas._typing import ArrayLike
15+
1216

1317
def should_extension_dispatch(left: ArrayLike, right: Any) -> bool:
1418
"""

pandas/core/sorting.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,6 @@
2020
lib,
2121
)
2222
from pandas._libs.hashtable import unique_label_indices
23-
from pandas._typing import (
24-
AxisInt,
25-
IndexKeyFunc,
26-
Level,
27-
NaPosition,
28-
Shape,
29-
SortKind,
30-
npt,
31-
)
3223

3324
from pandas.core.dtypes.common import (
3425
ensure_int64,
@@ -44,6 +35,16 @@
4435
from pandas.core.construction import extract_array
4536

4637
if TYPE_CHECKING:
38+
from pandas._typing import (
39+
AxisInt,
40+
IndexKeyFunc,
41+
Level,
42+
NaPosition,
43+
Shape,
44+
SortKind,
45+
npt,
46+
)
47+
4748
from pandas import MultiIndex
4849
from pandas.core.arrays import ExtensionArray
4950
from pandas.core.indexes.base import Index

pyproject.toml

-5
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,6 @@ exclude = [
295295
# TCH to be enabled gradually
296296
"pandas/core/arrays/*" = ["TCH"]
297297
"pandas/core/nanops.py" = ["TCH"]
298-
"pandas/core/apply.py" = ["TCH"]
299-
"pandas/core/base.py" = ["TCH"]
300-
"pandas/core/algorithms.py" = ["TCH"]
301-
"pandas/core/ops/*" = ["TCH"]
302-
"pandas/core/sorting.py" = ["TCH"]
303298
"pandas/util/*" = ["TCH"]
304299
"pandas/_libs/*" = ["TCH"]
305300
# Keep this one enabled

0 commit comments

Comments
 (0)