Skip to content

Commit 7214f85

Browse files
authored
TYP: move imports inside TYPE_CHECKING (#47968)
1 parent 8b5dfa2 commit 7214f85

File tree

28 files changed

+109
-45
lines changed

28 files changed

+109
-45
lines changed

pandas/core/arrays/period.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777

7878
import pandas.core.algorithms as algos
7979
from pandas.core.arrays import datetimelike as dtl
80-
from pandas.core.arrays.base import ExtensionArray
8180
import pandas.core.common as com
8281

8382
if TYPE_CHECKING:
@@ -91,6 +90,8 @@
9190
DatetimeArray,
9291
TimedeltaArray,
9392
)
93+
from pandas.core.arrays.base import ExtensionArray
94+
9495

9596
BaseOffsetT = TypeVar("BaseOffsetT", bound=BaseOffset)
9697

pandas/core/computation/engines.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,24 @@
44
from __future__ import annotations
55

66
import abc
7+
from typing import TYPE_CHECKING
78

89
from pandas.errors import NumExprClobberingError
910

1011
from pandas.core.computation.align import (
1112
align_terms,
1213
reconstruct_object,
1314
)
14-
from pandas.core.computation.expr import Expr
1515
from pandas.core.computation.ops import (
1616
MATHOPS,
1717
REDUCTIONS,
1818
)
1919

2020
import pandas.io.formats.printing as printing
2121

22+
if TYPE_CHECKING:
23+
from pandas.core.computation.expr import Expr
24+
2225
_ne_builtins = frozenset(MATHOPS + REDUCTIONS)
2326

2427

pandas/core/computation/eval.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from __future__ import annotations
55

66
import tokenize
7+
from typing import TYPE_CHECKING
78
import warnings
89

910
from pandas._libs.lib import no_default
@@ -15,12 +16,14 @@
1516
PARSERS,
1617
Expr,
1718
)
18-
from pandas.core.computation.ops import BinOp
1919
from pandas.core.computation.parsing import tokenize_string
2020
from pandas.core.computation.scope import ensure_scope
2121

2222
from pandas.io.formats.printing import pprint_thing
2323

24+
if TYPE_CHECKING:
25+
from pandas.core.computation.ops import BinOp
26+
2427

2528
def _check_engine(engine: str | None) -> str:
2629
"""

pandas/core/computation/pytables.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33

44
import ast
55
from functools import partial
6-
from typing import Any
6+
from typing import (
7+
TYPE_CHECKING,
8+
Any,
9+
)
710

811
import numpy as np
912

@@ -12,7 +15,6 @@
1215
Timestamp,
1316
)
1417
from pandas._typing import npt
15-
from pandas.compat.chainmap import DeepChainMap
1618
from pandas.errors import UndefinedVariableError
1719

1820
from pandas.core.dtypes.common import is_list_like
@@ -34,6 +36,9 @@
3436
pprint_thing_encoded,
3537
)
3638

39+
if TYPE_CHECKING:
40+
from pandas.compat.chainmap import DeepChainMap
41+
3742

3843
class PyTablesScope(_scope.Scope):
3944
__slots__ = ("queryables",)

pandas/core/groupby/categorical.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
from typing import TYPE_CHECKING
4+
35
import numpy as np
46

57
from pandas.core.algorithms import unique1d
@@ -8,7 +10,9 @@
810
CategoricalDtype,
911
recode_for_categories,
1012
)
11-
from pandas.core.indexes.api import CategoricalIndex
13+
14+
if TYPE_CHECKING:
15+
from pandas.core.indexes.api import CategoricalIndex
1216

1317

1418
def recode_for_groupby(

pandas/core/groupby/generic.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from functools import partial
1212
from textwrap import dedent
1313
from typing import (
14+
TYPE_CHECKING,
1415
Any,
1516
Callable,
1617
Hashable,
@@ -72,7 +73,6 @@
7273
import pandas.core.common as com
7374
from pandas.core.construction import create_series_with_explicit_dtype
7475
from pandas.core.frame import DataFrame
75-
from pandas.core.generic import NDFrame
7676
from pandas.core.groupby import base
7777
from pandas.core.groupby.groupby import (
7878
GroupBy,
@@ -93,6 +93,9 @@
9393

9494
from pandas.plotting import boxplot_frame_groupby
9595

96+
if TYPE_CHECKING:
97+
from pandas.core.generic import NDFrame
98+
9699
# TODO(typing) the return value on this callable should be any *scalar*.
97100
AggScalar = Union[str, Callable[..., Any]]
98101
# TODO: validate types on ScalarResult and move to _typing

pandas/core/groupby/ops.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import collections
1111
import functools
1212
from typing import (
13+
TYPE_CHECKING,
1314
Callable,
1415
Generic,
1516
Hashable,
@@ -77,7 +78,6 @@
7778
)
7879
from pandas.core.arrays.string_ import StringDtype
7980
from pandas.core.frame import DataFrame
80-
from pandas.core.generic import NDFrame
8181
from pandas.core.groupby import grouper
8282
from pandas.core.indexes.api import (
8383
CategoricalIndex,
@@ -95,6 +95,9 @@
9595
get_indexer_dict,
9696
)
9797

98+
if TYPE_CHECKING:
99+
from pandas.core.generic import NDFrame
100+
98101

99102
class WrappedCythonOp:
100103
"""

pandas/core/indexes/extension.py

Lines changed: 5 additions & 2 deletions
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
Callable,
89
TypeVar,
910
)
@@ -21,10 +22,12 @@
2122

2223
from pandas.core.dtypes.generic import ABCDataFrame
2324

24-
from pandas.core.arrays import IntervalArray
25-
from pandas.core.arrays._mixins import NDArrayBackedExtensionArray
2625
from pandas.core.indexes.base import Index
2726

27+
if TYPE_CHECKING:
28+
from pandas.core.arrays import IntervalArray
29+
from pandas.core.arrays._mixins import NDArrayBackedExtensionArray
30+
2831
_T = TypeVar("_T", bound="NDArrayBackedExtensionIndex")
2932
_ExtensionIndexT = TypeVar("_ExtensionIndexT", bound="ExtensionIndex")
3033

pandas/core/interchange/dataframe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
from collections import abc
44
from typing import TYPE_CHECKING
55

6-
import pandas as pd
76
from pandas.core.interchange.column import PandasColumn
87
from pandas.core.interchange.dataframe_protocol import DataFrame as DataFrameXchg
98

109
if TYPE_CHECKING:
10+
import pandas as pd
1111
from pandas import Index
1212

1313

pandas/core/internals/blocks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@
9898
PeriodArray,
9999
TimedeltaArray,
100100
)
101-
from pandas.core.arrays._mixins import NDArrayBackedExtensionArray
102101
from pandas.core.arrays.sparse import SparseDtype
103102
from pandas.core.base import PandasObject
104103
import pandas.core.common as com
@@ -115,6 +114,7 @@
115114
Float64Index,
116115
Index,
117116
)
117+
from pandas.core.arrays._mixins import NDArrayBackedExtensionArray
118118

119119
# comparison is faster than is_object_dtype
120120
_dtype_obj = np.dtype("object")

0 commit comments

Comments
 (0)