Skip to content

Commit 52c653b

Browse files
Clark-WMarcoGorelli
Clark-W
andauthored
STYLE enable ruff TCH on pandas/core/arrays (#51786)
* added changes to array with pre-commit run * updated dtype.py * Updated string_arrow.py to remove added comments thanks for the feedback, really appreciate it! * removed the comments they were in typechecking * run pre-commit --------- Co-authored-by: Marco Edward Gorelli <[email protected]>
1 parent 251b512 commit 52c653b

17 files changed

+124
-109
lines changed

pandas/core/arrays/_ranges.py

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

7+
from typing import TYPE_CHECKING
8+
79
import numpy as np
810

911
from pandas._libs.lib import i8max
@@ -14,7 +16,9 @@
1416
Timestamp,
1517
iNaT,
1618
)
17-
from pandas._typing import npt
19+
20+
if TYPE_CHECKING:
21+
from pandas._typing import npt
1822

1923

2024
def generate_regular_range(

pandas/core/arrays/arrow/dtype.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,14 @@
88
)
99
from decimal import Decimal
1010
import re
11+
from typing import TYPE_CHECKING
1112

1213
import numpy as np
1314

1415
from pandas._libs.tslibs import (
1516
Timedelta,
1617
Timestamp,
1718
)
18-
from pandas._typing import (
19-
TYPE_CHECKING,
20-
DtypeObj,
21-
type_t,
22-
)
2319
from pandas.compat import pa_version_under7p0
2420
from pandas.util._decorators import cache_readonly
2521

@@ -33,6 +29,11 @@
3329
import pyarrow as pa
3430

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

3839

pandas/core/arrays/arrow/extension_types.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
from __future__ import annotations
22

33
import json
4+
from typing import TYPE_CHECKING
45

56
import pyarrow
67

7-
from pandas._typing import IntervalClosedType
8-
98
from pandas.core.arrays.interval import VALID_CLOSED
109

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

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

pandas/core/arrays/base.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,6 @@
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-
)
4228
from pandas.compat import set_function_name
4329
from pandas.compat.numpy import function as nv
4430
from pandas.errors import AbstractMethodError
@@ -90,8 +76,20 @@
9076

9177
if TYPE_CHECKING:
9278
from pandas._typing import (
79+
ArrayLike,
80+
AstypeArg,
81+
AxisInt,
82+
Dtype,
83+
FillnaOptions,
9384
NumpySorter,
9485
NumpyValueArrayLike,
86+
PositionalIndexer,
87+
ScalarIndexer,
88+
SequenceIndexer,
89+
Shape,
90+
SortKind,
91+
TakeIndexer,
92+
npt,
9593
)
9694

9795
_extension_array_shared_docs: dict[str, str] = {}

pandas/core/arrays/boolean.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
lib,
1313
missing as libmissing,
1414
)
15-
from pandas._typing import (
16-
Dtype,
17-
DtypeObj,
18-
type_t,
19-
)
2015

2116
from pandas.core.dtypes.common import (
2217
is_list_like,
@@ -35,7 +30,12 @@
3530
if TYPE_CHECKING:
3631
import pyarrow
3732

38-
from pandas._typing import npt
33+
from pandas._typing import (
34+
Dtype,
35+
DtypeObj,
36+
npt,
37+
type_t,
38+
)
3939

4040

4141
@register_extension_dtype

pandas/core/arrays/categorical.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,6 @@
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-
)
4028
from pandas.compat.numpy import function as nv
4129
from pandas.util._validators import validate_bool_kwarg
4230

@@ -109,6 +97,19 @@
10997
from pandas.io.formats import console
11098

11199
if TYPE_CHECKING:
100+
from pandas._typing import (
101+
ArrayLike,
102+
AstypeArg,
103+
AxisInt,
104+
Dtype,
105+
NpDtype,
106+
Ordered,
107+
Shape,
108+
SortKind,
109+
npt,
110+
type_t,
111+
)
112+
112113
from pandas import (
113114
DataFrame,
114115
Index,

pandas/core/arrays/datetimes.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@
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-
)
5245
from pandas.errors import PerformanceWarning
5346
from pandas.util._exceptions import find_stack_level
5447
from pandas.util._validators import validate_inclusive
@@ -87,6 +80,14 @@
8780
)
8881

8982
if TYPE_CHECKING:
83+
from pandas._typing import (
84+
DateTimeErrorChoices,
85+
IntervalClosedType,
86+
TimeAmbiguous,
87+
TimeNonexistent,
88+
npt,
89+
)
90+
9091
from pandas import DataFrame
9192
from pandas.core.arrays import PeriodArray
9293

pandas/core/arrays/numeric.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@
1515
lib,
1616
missing as libmissing,
1717
)
18-
from pandas._typing import (
19-
Dtype,
20-
DtypeObj,
21-
npt,
22-
)
2318
from pandas.errors import AbstractMethodError
2419
from pandas.util._decorators import cache_readonly
2520

@@ -40,6 +35,12 @@
4035
if TYPE_CHECKING:
4136
import pyarrow
4237

38+
from pandas._typing import (
39+
Dtype,
40+
DtypeObj,
41+
npt,
42+
)
43+
4344

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

pandas/core/arrays/numpy_.py

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

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

57
from pandas._libs import lib
68
from pandas._libs.tslibs import (
79
get_unit_from_dtype,
810
is_supported_unit,
911
)
10-
from pandas._typing import (
11-
AxisInt,
12-
Dtype,
13-
NpDtype,
14-
Scalar,
15-
npt,
16-
)
1712
from pandas.compat.numpy import function as nv
1813

1914
from pandas.core.dtypes.astype import astype_array
@@ -35,6 +30,15 @@
3530
from pandas.core.construction import ensure_wrapped_if_datetimelike
3631
from pandas.core.strings.object_array import ObjectStringArrayMixin
3732

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

3943
class PandasArray(
4044
OpsMixin,

pandas/core/arrays/period.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@
4545
get_period_field_arr,
4646
period_asfreq_arr,
4747
)
48-
from pandas._typing import (
49-
AnyArrayLike,
50-
Dtype,
51-
NpDtype,
52-
npt,
53-
)
5448
from pandas.util._decorators import (
5549
cache_readonly,
5650
doc,
@@ -81,8 +75,12 @@
8175

8276
if TYPE_CHECKING:
8377
from pandas._typing import (
78+
AnyArrayLike,
79+
Dtype,
80+
NpDtype,
8481
NumpySorter,
8582
NumpyValueArrayLike,
83+
npt,
8684
)
8785

8886
from pandas.core.arrays import (

pandas/core/arrays/sparse/array.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,6 @@
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-
)
4431
from pandas.compat.numpy import function as nv
4532
from pandas.errors import PerformanceWarning
4633
from pandas.util._exceptions import find_stack_level
@@ -117,6 +104,20 @@ class ellipsis(Enum):
117104

118105
SparseIndexKind = Literal["integer", "block"]
119106

107+
from pandas._typing import (
108+
ArrayLike,
109+
AstypeArg,
110+
Axis,
111+
AxisInt,
112+
Dtype,
113+
NpDtype,
114+
PositionalIndexer,
115+
Scalar,
116+
ScalarIndexer,
117+
SequenceIndexer,
118+
npt,
119+
)
120+
120121
from pandas import Series
121122

122123
else:

pandas/core/arrays/sparse/dtype.py

Lines changed: 6 additions & 5 deletions
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

@@ -36,6 +31,12 @@
3631
)
3732

3833
if TYPE_CHECKING:
34+
from pandas._typing import (
35+
Dtype,
36+
DtypeObj,
37+
type_t,
38+
)
39+
3940
from pandas.core.arrays.sparse.array import SparseArray
4041

4142

pandas/core/arrays/sparse/scipy_sparse.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@
1010
Iterable,
1111
)
1212

13-
import numpy as np
14-
1513
from pandas._libs import lib
16-
from pandas._typing import (
17-
IndexLabel,
18-
npt,
19-
)
2014

2115
from pandas.core.dtypes.missing import notna
2216

@@ -25,8 +19,14 @@
2519
from pandas.core.series import Series
2620

2721
if TYPE_CHECKING:
22+
import numpy as np
2823
import scipy.sparse
2924

25+
from pandas._typing import (
26+
IndexLabel,
27+
npt,
28+
)
29+
3030

3131
def _check_is_partition(parts: Iterable, whole: Iterable):
3232
whole = set(whole)

0 commit comments

Comments
 (0)