Skip to content

Commit b29e1c3

Browse files
author
Junheng
committed
Added changes for type checking
1 parent d9ba285 commit b29e1c3

16 files changed

+145
-109
lines changed

pandas/core/arrays/_ranges.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
(and possibly TimedeltaArray/PeriodArray)
44
"""
55
from __future__ import annotations
6+
from typing import (
7+
TYPE_CHECKING,
8+
)
9+
610

711
import numpy as np
812

@@ -14,8 +18,9 @@
1418
Timestamp,
1519
iNaT,
1620
)
17-
from pandas._typing import npt
1821

22+
if TYPE_CHECKING:
23+
from pandas._typing import npt
1924

2025
def generate_regular_range(
2126
start: Timestamp | Timedelta | None,

pandas/core/arrays/arrow/dtype.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
2-
2+
from typing import (
3+
TYPE_CHECKING,)
34
from datetime import (
45
date,
56
datetime,
@@ -15,11 +16,7 @@
1516
Timedelta,
1617
Timestamp,
1718
)
18-
from pandas._typing import (
19-
TYPE_CHECKING,
20-
DtypeObj,
21-
type_t,
22-
)
19+
2320
from pandas.compat import pa_version_under7p0
2421
from pandas.util._decorators import cache_readonly
2522

@@ -33,6 +30,10 @@
3330

3431
if TYPE_CHECKING:
3532
from pandas.core.arrays.arrow import ArrowExtensionArray
33+
from pandas._typing import (
34+
DtypeObj,
35+
type_t,
36+
)
3637

3738

3839
@register_extension_dtype

pandas/core/arrays/arrow/extension_types.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import json
44

55
import pyarrow
6-
7-
from pandas._typing import IntervalClosedType
6+
from typing import (
7+
TYPE_CHECKING,)
88

99
from pandas.core.arrays.interval import VALID_CLOSED
1010

11+
if TYPE_CHECKING:
12+
from pandas._typing import IntervalClosedType
1113

1214
class ArrowPeriodType(pyarrow.ExtensionType):
1315
def __init__(self, freq) -> None:

pandas/core/arrays/base.py

+15-14
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,7 @@
2525
import numpy as np
2626

2727
from pandas._libs import lib
28-
from pandas._typing import (
29-
ArrayLike,
30-
AstypeArg,
31-
AxisInt,
32-
Dtype,
33-
FillnaOptions,
34-
PositionalIndexer,
35-
ScalarIndexer,
36-
SequenceIndexer,
37-
Shape,
38-
SortKind,
39-
TakeIndexer,
40-
npt,
41-
)
28+
4229
from pandas.compat import set_function_name
4330
from pandas.compat.numpy import function as nv
4431
from pandas.errors import AbstractMethodError
@@ -93,6 +80,20 @@
9380
NumpySorter,
9481
NumpyValueArrayLike,
9582
)
83+
from pandas._typing import (
84+
ArrayLike,
85+
AstypeArg,
86+
AxisInt,
87+
Dtype,
88+
FillnaOptions,
89+
PositionalIndexer,
90+
ScalarIndexer,
91+
SequenceIndexer,
92+
Shape,
93+
SortKind,
94+
TakeIndexer,
95+
npt,
96+
)
9697

9798
_extension_array_shared_docs: dict[str, str] = {}
9899

pandas/core/arrays/boolean.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@
1212
lib,
1313
missing as libmissing,
1414
)
15-
from pandas._typing import (
16-
Dtype,
17-
DtypeObj,
18-
type_t,
19-
)
15+
2016

2117
from pandas.core.dtypes.common import (
2218
is_list_like,
@@ -37,6 +33,12 @@
3733

3834
from pandas._typing import npt
3935

36+
from pandas._typing import (
37+
Dtype,
38+
DtypeObj,
39+
type_t,
40+
)
41+
4042

4143
@register_extension_dtype
4244
class BooleanDtype(BaseMaskedDtype):

pandas/core/arrays/categorical.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,7 @@
2525
lib,
2626
)
2727
from pandas._libs.arrays import NDArrayBacked
28-
from pandas._typing import (
29-
ArrayLike,
30-
AstypeArg,
31-
AxisInt,
32-
Dtype,
33-
NpDtype,
34-
Ordered,
35-
Shape,
36-
SortKind,
37-
npt,
38-
type_t,
39-
)
28+
4029
from pandas.compat.numpy import function as nv
4130
from pandas.util._validators import validate_bool_kwarg
4231

@@ -114,6 +103,18 @@
114103
Index,
115104
Series,
116105
)
106+
from pandas._typing import (
107+
ArrayLike,
108+
AstypeArg,
109+
AxisInt,
110+
Dtype,
111+
NpDtype,
112+
Ordered,
113+
Shape,
114+
SortKind,
115+
npt,
116+
type_t,
117+
)
117118

118119

119120
CategoricalT = TypeVar("CategoricalT", bound="Categorical")

pandas/core/arrays/datetimes.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,7 @@
4242
tzconversion,
4343
)
4444
from pandas._libs.tslibs.dtypes import abbrev_to_npy_unit
45-
from pandas._typing import (
46-
DateTimeErrorChoices,
47-
IntervalClosedType,
48-
TimeAmbiguous,
49-
TimeNonexistent,
50-
npt,
51-
)
45+
5246
from pandas.errors import PerformanceWarning
5347
from pandas.util._exceptions import find_stack_level
5448
from pandas.util._validators import validate_inclusive
@@ -89,6 +83,13 @@
8983
if TYPE_CHECKING:
9084
from pandas import DataFrame
9185
from pandas.core.arrays import PeriodArray
86+
from pandas._typing import (
87+
DateTimeErrorChoices,
88+
IntervalClosedType,
89+
TimeAmbiguous,
90+
TimeNonexistent,
91+
npt,
92+
)
9293

9394
_midnight = time(0, 0)
9495

pandas/core/arrays/numeric.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@
1515
lib,
1616
missing as libmissing,
1717
)
18-
from pandas._typing import (
19-
Dtype,
20-
DtypeObj,
21-
npt,
22-
)
18+
2319
from pandas.errors import AbstractMethodError
2420
from pandas.util._decorators import cache_readonly
2521

@@ -39,6 +35,11 @@
3935

4036
if TYPE_CHECKING:
4137
import pyarrow
38+
from pandas._typing import (
39+
Dtype,
40+
DtypeObj,
41+
npt,
42+
)
4243

4344

4445
T = TypeVar("T", bound="NumericArray")

pandas/core/arrays/numpy_.py

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

36
import numpy as np
47

@@ -7,13 +10,7 @@
710
get_unit_from_dtype,
811
is_supported_unit,
912
)
10-
from pandas._typing import (
11-
AxisInt,
12-
Dtype,
13-
NpDtype,
14-
Scalar,
15-
npt,
16-
)
13+
1714
from pandas.compat.numpy import function as nv
1815

1916
from pandas.core.dtypes.astype import astype_array
@@ -35,6 +32,14 @@
3532
from pandas.core.construction import ensure_wrapped_if_datetimelike
3633
from pandas.core.strings.object_array import ObjectStringArrayMixin
3734

35+
if TYPE_CHECKING:
36+
from pandas._typing import (
37+
AxisInt,
38+
Dtype,
39+
NpDtype,
40+
Scalar,
41+
npt,
42+
)
3843

3944
class PandasArray(
4045
OpsMixin,

pandas/core/arrays/period.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,7 @@
4545
get_period_field_arr,
4646
period_asfreq_arr,
4747
)
48-
from pandas._typing import (
49-
AnyArrayLike,
50-
Dtype,
51-
NpDtype,
52-
npt,
53-
)
48+
5449
from pandas.util._decorators import (
5550
cache_readonly,
5651
doc,
@@ -90,6 +85,12 @@
9085
TimedeltaArray,
9186
)
9287
from pandas.core.arrays.base import ExtensionArray
88+
from pandas._typing import (
89+
AnyArrayLike,
90+
Dtype,
91+
NpDtype,
92+
npt,
93+
)
9394

9495

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

pandas/core/arrays/sparse/array.py

+15-13
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,7 @@
2828
SparseIndex,
2929
)
3030
from pandas._libs.tslibs import NaT
31-
from pandas._typing import (
32-
ArrayLike,
33-
AstypeArg,
34-
Axis,
35-
AxisInt,
36-
Dtype,
37-
NpDtype,
38-
PositionalIndexer,
39-
Scalar,
40-
ScalarIndexer,
41-
SequenceIndexer,
42-
npt,
43-
)
31+
4432
from pandas.compat.numpy import function as nv
4533
from pandas.errors import PerformanceWarning
4634
from pandas.util._exceptions import find_stack_level
@@ -122,6 +110,20 @@ class ellipsis(Enum):
122110

123111
from pandas import Series
124112

113+
from pandas._typing import (
114+
ArrayLike,
115+
AstypeArg,
116+
Axis,
117+
AxisInt,
118+
Dtype,
119+
NpDtype,
120+
PositionalIndexer,
121+
Scalar,
122+
ScalarIndexer,
123+
SequenceIndexer,
124+
npt,
125+
)
126+
125127
else:
126128
ellipsis = type(Ellipsis)
127129

pandas/core/arrays/sparse/dtype.py

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

1111
import numpy as np
1212

13-
from pandas._typing import (
14-
Dtype,
15-
DtypeObj,
16-
type_t,
17-
)
1813
from pandas.errors import PerformanceWarning
1914
from pandas.util._exceptions import find_stack_level
2015

@@ -37,7 +32,11 @@
3732

3833
if TYPE_CHECKING:
3934
from pandas.core.arrays.sparse.array import SparseArray
40-
35+
from pandas._typing import (
36+
Dtype,
37+
DtypeObj,
38+
type_t,
39+
)
4140

4241
@register_extension_dtype
4342
class SparseDtype(ExtensionDtype):

pandas/core/arrays/sparse/scipy_sparse.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@
1010
Iterable,
1111
)
1212

13-
import numpy as np
1413

1514
from pandas._libs import lib
16-
from pandas._typing import (
17-
IndexLabel,
18-
npt,
19-
)
15+
2016

2117
from pandas.core.dtypes.missing import notna
2218

@@ -26,6 +22,11 @@
2622

2723
if TYPE_CHECKING:
2824
import scipy.sparse
25+
from pandas._typing import (
26+
IndexLabel,
27+
npt,
28+
)
29+
import numpy as np
2930

3031

3132
def _check_is_partition(parts: Iterable, whole: Iterable):

0 commit comments

Comments
 (0)