Skip to content

Commit e36b586

Browse files
committed
Enable ruff TCH
1 parent c71645f commit e36b586

35 files changed

+233
-135
lines changed

pandas/_libs/algos.pyi

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
from typing import Any
1+
from typing import (
2+
Any,
3+
TYPE_CHECKING,
4+
)
5+
if TYPE_CHECKING:
6+
import numpy as np
27

3-
import numpy as np
4-
5-
from pandas._typing import npt
8+
from pandas._typing import npt
69

710
class Infinity:
811
"""

pandas/_libs/arrays.pyi

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
from typing import Sequence
1+
from typing import (
2+
Sequence,
3+
TYPE_CHECKING,
4+
)
25

3-
import numpy as np
6+
if TYPE_CHECKING:
7+
import numpy as np
48

5-
from pandas._typing import (
6-
DtypeObj,
7-
Shape,
8-
)
9+
from pandas._typing import (
10+
DtypeObj,
11+
Shape,
12+
)
913

1014
class NDArrayBacked:
1115
_dtype: DtypeObj

pandas/_libs/groupby.pyi

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
from typing import Literal
1+
from typing import (
2+
Literal,
3+
TYPE_CHECKING,
4+
)
25

3-
import numpy as np
6+
if TYPE_CHECKING:
7+
import numpy as np
48

5-
from pandas._typing import npt
9+
from pandas._typing import npt
610

711
def group_median_float64(
812
out: np.ndarray, # ndarray[float64_t, ndim=2]

pandas/_libs/hashing.pyi

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import numpy as np
1+
from typing import TYPE_CHECKING
22

3-
from pandas._typing import npt
3+
if TYPE_CHECKING:
4+
import numpy as np
5+
6+
from pandas._typing import npt
47

58
def hash_object_array(
69
arr: npt.NDArray[np.object_],

pandas/_libs/hashtable.pyi

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ from typing import (
22
Any,
33
Hashable,
44
Literal,
5+
TYPE_CHECKING,
56
)
67

7-
import numpy as np
8+
if TYPE_CHECKING:
9+
import numpy as np
810

9-
from pandas._typing import npt
11+
from pandas._typing import npt
1012

1113
def unique_label_indices(
1214
labels: np.ndarray, # const int64_t[:]

pandas/_libs/index.pyi

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import numpy as np
1+
from typing import TYPE_CHECKING
22

3-
from pandas._typing import npt
3+
if TYPE_CHECKING:
4+
import numpy as np
45

5-
from pandas import MultiIndex
6-
from pandas.core.arrays import ExtensionArray
6+
from pandas._typing import npt
7+
from pandas import MultiIndex
8+
from pandas.core.arrays import ExtensionArray
79

810
class IndexEngine:
911
over_size_threshold: bool

pandas/_libs/internals.pyi

+13-10
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@ from typing import (
33
Sequence,
44
final,
55
overload,
6+
TYPE_CHECKING,
67
)
7-
import weakref
88

9-
import numpy as np
9+
if TYPE_CHECKING:
10+
import weakref
1011

11-
from pandas._typing import (
12-
ArrayLike,
13-
T,
14-
npt,
15-
)
12+
import numpy as np
13+
14+
from pandas._typing import (
15+
ArrayLike,
16+
T,
17+
npt,
18+
)
1619

17-
from pandas import Index
18-
from pandas.core.arrays._mixins import NDArrayBackedExtensionArray
19-
from pandas.core.internals.blocks import Block as B
20+
from pandas import Index
21+
from pandas.core.arrays._mixins import NDArrayBackedExtensionArray
22+
from pandas.core.internals.blocks import Block as B
2023

2124
def slice_len(slc: slice, objlen: int = ...) -> int: ...
2225
def get_blkno_indexers(

pandas/_libs/interval.pyi

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ from typing import (
33
Generic,
44
TypeVar,
55
overload,
6+
TYPE_CHECKING,
67
)
78

8-
import numpy as np
9-
import numpy.typing as npt
9+
if TYPE_CHECKING:
10+
import numpy as np
11+
import numpy.typing as npt
1012

1113
from pandas._typing import (
1214
IntervalClosedType,

pandas/_libs/join.pyi

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import numpy as np
1+
from typing import TYPE_CHECKING
22

3-
from pandas._typing import npt
3+
if TYPE_CHECKING:
4+
import numpy as np
5+
6+
from pandas._typing import npt
47

58
def inner_join(
69
left: np.ndarray, # const intp_t[:]

pandas/_libs/lib.pyi

+7-5
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ from typing import (
99
Hashable,
1010
Literal,
1111
overload,
12+
TYPE_CHECKING,
1213
)
1314

1415
import numpy as np
1516

16-
from pandas._typing import (
17-
ArrayLike,
18-
DtypeObj,
19-
npt,
20-
)
17+
if TYPE_CHECKING:
18+
from pandas._typing import (
19+
ArrayLike,
20+
DtypeObj,
21+
npt,
22+
)
2123

2224
# placeholder until we can specify np.ndarray[object, ndim=2]
2325
ndarray_obj_2d = np.ndarray

pandas/_libs/missing.pyi

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import numpy as np
2-
from numpy import typing as npt
1+
from typing import TYPE_CHECKING
2+
3+
if TYPE_CHECKING:
4+
import numpy as np
5+
6+
from numpy import typing as npt
37

48
class NAType:
59
def __new__(cls, *args, **kwargs): ...

pandas/_libs/ops.pyi

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ from typing import (
44
Iterable,
55
Literal,
66
overload,
7+
TYPE_CHECKING,
78
)
89

9-
import numpy as np
10+
if TYPE_CHECKING:
11+
import numpy as np
1012

11-
from pandas._typing import npt
13+
from pandas._typing import npt
1214

1315
_BinOp = Callable[[Any, Any], Any]
1416
_BoolOp = Callable[[Any, Any], bool]

pandas/_libs/ops_dispatch.pyi

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import numpy as np
1+
from typing import TYPE_CHECKING
2+
3+
if TYPE_CHECKING:
4+
import numpy as np
25

36
def maybe_dispatch_ufunc_to_dunder_op(
47
self, ufunc: np.ufunc, method: str, *inputs, **kwargs

pandas/_libs/parsers.pyi

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
from typing import (
22
Hashable,
33
Literal,
4+
TYPE_CHECKING,
45
)
56

6-
import numpy as np
7+
if TYPE_CHECKING:
8+
import numpy as np
79

8-
from pandas._typing import (
9-
ArrayLike,
10-
Dtype,
11-
npt,
12-
)
10+
from pandas._typing import (
11+
ArrayLike,
12+
Dtype,
13+
npt,
14+
)
1315

1416
STR_NA_VALUES: set[str]
1517

pandas/_libs/properties.pyi

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
from typing import (
22
Sequence,
33
overload,
4+
TYPE_CHECKING
45
)
56

6-
from pandas._typing import (
7-
AnyArrayLike,
8-
DataFrame,
9-
Index,
10-
Series,
11-
)
7+
if TYPE_CHECKING:
8+
from pandas._typing import (
9+
AnyArrayLike,
10+
DataFrame,
11+
Index,
12+
Series,
13+
)
1214

1315
# note: this is a lie to make type checkers happy (they special
1416
# case property). cache_readonly uses attribute names similar to

pandas/_libs/reduction.pyi

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
from typing import Any
1+
from typing import (
2+
Any,
3+
TYPE_CHECKING,
4+
)
25

3-
from pandas._typing import DtypeObj
6+
if TYPE_CHECKING:
7+
from pandas._typing import DtypeObj
48

59
def check_result_array(obj: object, dtype: DtypeObj) -> None: ...
610
def extract_result(res: object) -> Any: ...

pandas/_libs/reshape.pyi

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import numpy as np
1+
from typing import TYPE_CHECKING
22

3-
from pandas._typing import npt
3+
if TYPE_CHECKING:
4+
import numpy as np
5+
6+
from pandas._typing import npt
47

58
def unstack(
69
values: np.ndarray, # reshape_t[:, :]

pandas/_libs/sparse.pyi

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from typing import (
22
Sequence,
33
TypeVar,
4+
TYPE_CHECKING,
45
)
56

6-
import numpy as np
7+
if TYPE_CHECKING:
8+
import numpy as np
79

8-
from pandas._typing import npt
10+
from pandas._typing import npt
911

1012
_SparseIndexT = TypeVar("_SparseIndexT", bound=SparseIndex)
1113

pandas/_libs/tslib.pyi

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
from datetime import tzinfo
1+
from typing import TYPE_CHECKING
22

3-
import numpy as np
3+
if TYPE_CHECKING:
4+
from datetime import tzinfo
45

5-
from pandas._typing import npt
6+
import numpy as np
7+
8+
from pandas._typing import npt
69

710
def format_array_from_datetime(
811
values: npt.NDArray[np.int64],

pandas/_libs/tslibs/conversion.pyi

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
from datetime import (
2-
datetime,
3-
tzinfo,
4-
)
1+
from typing import TYPE_CHECKING
52

6-
import numpy as np
3+
if TYPE_CHECKING:
4+
from datetime import (
5+
datetime,
6+
tzinfo,
7+
)
8+
9+
import numpy as np
710

811
DT64NS_DTYPE: np.dtype
912
TD64NS_DTYPE: np.dtype

pandas/_libs/tslibs/fields.pyi

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import numpy as np
1+
from typing import TYPE_CHECKING
22

3-
from pandas._typing import npt
3+
if TYPE_CHECKING:
4+
import numpy as np
5+
6+
from pandas._typing import npt
47

58
def build_field_sarray(
69
dtindex: npt.NDArray[np.int64], # const int64_t[:]

pandas/_libs/tslibs/np_datetime.pyi

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import numpy as np
1+
from typing import TYPE_CHECKING
22

3-
from pandas._typing import npt
3+
if TYPE_CHECKING:
4+
import numpy as np
5+
6+
from pandas._typing import npt
47

58
class OutOfBoundsDatetime(ValueError): ...
69
class OutOfBoundsTimedelta(ValueError): ...

pandas/_libs/tslibs/offsets.pyi

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ from typing import (
88
Literal,
99
TypeVar,
1010
overload,
11+
TYPE_CHECKING,
1112
)
1213

13-
import numpy as np
14+
if TYPE_CHECKING:
15+
import numpy as np
1416

15-
from pandas._libs.tslibs.nattype import NaTType
16-
from pandas._typing import npt
17+
from pandas._libs.tslibs.nattype import NaTType
18+
from pandas._typing import npt
1719

18-
from .timedeltas import Timedelta
20+
from .timedeltas import Timedelta
1921

2022
_BaseOffsetT = TypeVar("_BaseOffsetT", bound=BaseOffset)
2123
_DatetimeT = TypeVar("_DatetimeT", bound=datetime)

pandas/_libs/tslibs/parsing.pyi

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
from datetime import datetime
1+
from typing import TYPE_CHECKING
22

3-
import numpy as np
3+
if TYPE_CHECKING:
4+
from datetime import datetime
45

5-
from pandas._typing import npt
6+
import numpy as np
7+
8+
from pandas._typing import npt
69

710
class DateParseError(ValueError): ...
811

0 commit comments

Comments
 (0)