Skip to content

STYLE enable ruff TCH on pandas/core/arrays #51786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pandas/core/arrays/_ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"""
from __future__ import annotations

from typing import TYPE_CHECKING

import numpy as np

from pandas._libs.lib import i8max
Expand All @@ -14,7 +16,9 @@
Timestamp,
iNaT,
)
from pandas._typing import npt

if TYPE_CHECKING:
from pandas._typing import npt


def generate_regular_range(
Expand Down
11 changes: 6 additions & 5 deletions pandas/core/arrays/arrow/dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@
)
from decimal import Decimal
import re
from typing import TYPE_CHECKING

import numpy as np

from pandas._libs.tslibs import (
Timedelta,
Timestamp,
)
from pandas._typing import (
TYPE_CHECKING,
DtypeObj,
type_t,
)
from pandas.compat import pa_version_under7p0
from pandas.util._decorators import cache_readonly

Expand All @@ -33,6 +29,11 @@
import pyarrow as pa

if TYPE_CHECKING:
from pandas._typing import (
DtypeObj,
type_t,
)

from pandas.core.arrays.arrow import ArrowExtensionArray


Expand Down
6 changes: 4 additions & 2 deletions pandas/core/arrays/arrow/extension_types.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from __future__ import annotations

import json
from typing import TYPE_CHECKING

import pyarrow

from pandas._typing import IntervalClosedType

from pandas.core.arrays.interval import VALID_CLOSED

if TYPE_CHECKING:
from pandas._typing import IntervalClosedType


class ArrowPeriodType(pyarrow.ExtensionType):
def __init__(self, freq) -> None:
Expand Down
26 changes: 12 additions & 14 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,6 @@
import numpy as np

from pandas._libs import lib
from pandas._typing import (
ArrayLike,
AstypeArg,
AxisInt,
Dtype,
FillnaOptions,
PositionalIndexer,
ScalarIndexer,
SequenceIndexer,
Shape,
SortKind,
TakeIndexer,
npt,
)
from pandas.compat import set_function_name
from pandas.compat.numpy import function as nv
from pandas.errors import AbstractMethodError
Expand Down Expand Up @@ -90,8 +76,20 @@

if TYPE_CHECKING:
from pandas._typing import (
ArrayLike,
AstypeArg,
AxisInt,
Dtype,
FillnaOptions,
NumpySorter,
NumpyValueArrayLike,
PositionalIndexer,
ScalarIndexer,
SequenceIndexer,
Shape,
SortKind,
TakeIndexer,
npt,
)

_extension_array_shared_docs: dict[str, str] = {}
Expand Down
12 changes: 6 additions & 6 deletions pandas/core/arrays/boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
lib,
missing as libmissing,
)
from pandas._typing import (
Dtype,
DtypeObj,
type_t,
)

from pandas.core.dtypes.common import (
is_list_like,
Expand All @@ -35,7 +30,12 @@
if TYPE_CHECKING:
import pyarrow

from pandas._typing import npt
from pandas._typing import (
Dtype,
DtypeObj,
npt,
type_t,
)


@register_extension_dtype
Expand Down
25 changes: 13 additions & 12 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,6 @@
lib,
)
from pandas._libs.arrays import NDArrayBacked
from pandas._typing import (
ArrayLike,
AstypeArg,
AxisInt,
Dtype,
NpDtype,
Ordered,
Shape,
SortKind,
npt,
type_t,
)
from pandas.compat.numpy import function as nv
from pandas.util._validators import validate_bool_kwarg

Expand Down Expand Up @@ -109,6 +97,19 @@
from pandas.io.formats import console

if TYPE_CHECKING:
from pandas._typing import (
ArrayLike,
AstypeArg,
AxisInt,
Dtype,
NpDtype,
Ordered,
Shape,
SortKind,
npt,
type_t,
)

from pandas import (
DataFrame,
Index,
Expand Down
15 changes: 8 additions & 7 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@
tzconversion,
)
from pandas._libs.tslibs.dtypes import abbrev_to_npy_unit
from pandas._typing import (
DateTimeErrorChoices,
IntervalClosedType,
TimeAmbiguous,
TimeNonexistent,
npt,
)
from pandas.errors import PerformanceWarning
from pandas.util._exceptions import find_stack_level
from pandas.util._validators import validate_inclusive
Expand Down Expand Up @@ -87,6 +80,14 @@
)

if TYPE_CHECKING:
from pandas._typing import (
DateTimeErrorChoices,
IntervalClosedType,
TimeAmbiguous,
TimeNonexistent,
npt,
)

from pandas import DataFrame
from pandas.core.arrays import PeriodArray

Expand Down
11 changes: 6 additions & 5 deletions pandas/core/arrays/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
lib,
missing as libmissing,
)
from pandas._typing import (
Dtype,
DtypeObj,
npt,
)
from pandas.errors import AbstractMethodError
from pandas.util._decorators import cache_readonly

Expand All @@ -40,6 +35,12 @@
if TYPE_CHECKING:
import pyarrow

from pandas._typing import (
Dtype,
DtypeObj,
npt,
)


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

Expand Down
18 changes: 11 additions & 7 deletions pandas/core/arrays/numpy_.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
from __future__ import annotations

from typing import TYPE_CHECKING

import numpy as np

from pandas._libs import lib
from pandas._libs.tslibs import (
get_unit_from_dtype,
is_supported_unit,
)
from pandas._typing import (
AxisInt,
Dtype,
NpDtype,
Scalar,
npt,
)
from pandas.compat.numpy import function as nv

from pandas.core.dtypes.astype import astype_array
Expand All @@ -35,6 +30,15 @@
from pandas.core.construction import ensure_wrapped_if_datetimelike
from pandas.core.strings.object_array import ObjectStringArrayMixin

if TYPE_CHECKING:
from pandas._typing import (
AxisInt,
Dtype,
NpDtype,
Scalar,
npt,
)


class PandasArray(
OpsMixin,
Expand Down
10 changes: 4 additions & 6 deletions pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@
get_period_field_arr,
period_asfreq_arr,
)
from pandas._typing import (
AnyArrayLike,
Dtype,
NpDtype,
npt,
)
from pandas.util._decorators import (
cache_readonly,
doc,
Expand Down Expand Up @@ -81,8 +75,12 @@

if TYPE_CHECKING:
from pandas._typing import (
AnyArrayLike,
Dtype,
NpDtype,
NumpySorter,
NumpyValueArrayLike,
npt,
)

from pandas.core.arrays import (
Expand Down
27 changes: 14 additions & 13 deletions pandas/core/arrays/sparse/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,6 @@
SparseIndex,
)
from pandas._libs.tslibs import NaT
from pandas._typing import (
ArrayLike,
AstypeArg,
Axis,
AxisInt,
Dtype,
NpDtype,
PositionalIndexer,
Scalar,
ScalarIndexer,
SequenceIndexer,
npt,
)
from pandas.compat.numpy import function as nv
from pandas.errors import PerformanceWarning
from pandas.util._exceptions import find_stack_level
Expand Down Expand Up @@ -117,6 +104,20 @@ class ellipsis(Enum):

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

from pandas._typing import (
ArrayLike,
AstypeArg,
Axis,
AxisInt,
Dtype,
NpDtype,
PositionalIndexer,
Scalar,
ScalarIndexer,
SequenceIndexer,
npt,
)

from pandas import Series

else:
Expand Down
11 changes: 6 additions & 5 deletions pandas/core/arrays/sparse/dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@

import numpy as np

from pandas._typing import (
Dtype,
DtypeObj,
type_t,
)
from pandas.errors import PerformanceWarning
from pandas.util._exceptions import find_stack_level

Expand All @@ -36,6 +31,12 @@
)

if TYPE_CHECKING:
from pandas._typing import (
Dtype,
DtypeObj,
type_t,
)

from pandas.core.arrays.sparse.array import SparseArray


Expand Down
12 changes: 6 additions & 6 deletions pandas/core/arrays/sparse/scipy_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@
Iterable,
)

import numpy as np

from pandas._libs import lib
from pandas._typing import (
IndexLabel,
npt,
)

from pandas.core.dtypes.missing import notna

Expand All @@ -25,8 +19,14 @@
from pandas.core.series import Series

if TYPE_CHECKING:
import numpy as np
import scipy.sparse

from pandas._typing import (
IndexLabel,
npt,
)


def _check_is_partition(parts: Iterable, whole: Iterable):
whole = set(whole)
Expand Down
Loading