Skip to content

STYLE: Enable ruff TCH on pandas/core/indexers and more #51779

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 1 commit into from
Mar 4, 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
25 changes: 13 additions & 12 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@
lib,
reduction as libreduction,
)
from pandas._typing import (
ArrayLike,
Axis,
AxisInt,
CorrelationMethod,
FillnaOptions,
IndexLabel,
Manager,
Manager2D,
SingleManager,
TakeIndexer,
)
from pandas.errors import SpecificationError
from pandas.util._decorators import (
Appender,
Expand Down Expand Up @@ -96,6 +84,19 @@
from pandas.plotting import boxplot_frame_groupby

if TYPE_CHECKING:
from pandas._typing import (
ArrayLike,
Axis,
AxisInt,
CorrelationMethod,
FillnaOptions,
IndexLabel,
Manager,
Manager2D,
SingleManager,
TakeIndexer,
)

from pandas import Categorical
from pandas.core.generic import NDFrame

Expand Down
13 changes: 7 additions & 6 deletions pandas/core/groupby/grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@
from pandas._config import using_copy_on_write

from pandas._libs import lib
from pandas._typing import (
ArrayLike,
Axis,
NDFrameT,
npt,
)
from pandas.errors import InvalidIndexError
from pandas.util._decorators import cache_readonly
from pandas.util._exceptions import find_stack_level
Expand Down Expand Up @@ -52,6 +46,13 @@
from pandas.io.formats.printing import pprint_thing

if TYPE_CHECKING:
from pandas._typing import (
ArrayLike,
Axis,
NDFrameT,
npt,
)

from pandas.core.generic import NDFrame


Expand Down
3 changes: 2 additions & 1 deletion pandas/core/groupby/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import numpy as np

from pandas._typing import PositionalIndexer
from pandas.util._decorators import (
cache_readonly,
doc,
Expand All @@ -21,6 +20,8 @@
)

if TYPE_CHECKING:
from pandas._typing import PositionalIndexer

from pandas import (
DataFrame,
Series,
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/groupby/numba_.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@

import numpy as np

from pandas._typing import Scalar
from pandas.compat._optional import import_optional_dependency

from pandas.core.util.numba_ import (
NumbaUtilError,
jit_user_function,
)

if TYPE_CHECKING:
from pandas._typing import Scalar


def validate_udf(func: Callable) -> None:
"""
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/indexers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

import numpy as np

from pandas._typing import AnyArrayLike

from pandas.core.dtypes.common import (
is_array_like,
is_bool_dtype,
Expand All @@ -26,6 +24,8 @@
)

if TYPE_CHECKING:
from pandas._typing import AnyArrayLike

from pandas.core.frame import DataFrame
from pandas.core.indexes.base import Index

Expand Down
8 changes: 6 additions & 2 deletions pandas/core/indexes/api.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from __future__ import annotations

import textwrap
from typing import cast
from typing import (
TYPE_CHECKING,
cast,
)

import numpy as np

from pandas._libs import (
NaT,
lib,
)
from pandas._typing import Axis
from pandas.errors import InvalidIndexError

from pandas.core.dtypes.cast import find_common_type
Expand All @@ -30,6 +32,8 @@
from pandas.core.indexes.range import RangeIndex
from pandas.core.indexes.timedeltas import TimedeltaIndex

if TYPE_CHECKING:
from pandas._typing import Axis
_sort_msg = textwrap.dedent(
"""\
Sorting because non-concatenation axis is not aligned. A future version
Expand Down
12 changes: 7 additions & 5 deletions pandas/core/indexes/category.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
from __future__ import annotations

from typing import (
TYPE_CHECKING,
Any,
Hashable,
)

import numpy as np

from pandas._libs import index as libindex
from pandas._typing import (
Dtype,
DtypeObj,
npt,
)
from pandas.util._decorators import (
cache_readonly,
doc,
Expand Down Expand Up @@ -45,6 +41,12 @@

from pandas.io.formats.printing import pprint_thing

if TYPE_CHECKING:
from pandas._typing import (
Dtype,
DtypeObj,
npt,
)
_index_doc_kwargs: dict[str, str] = dict(ibase._index_doc_kwargs)
_index_doc_kwargs.update({"target_klass": "CategoricalIndex"})

Expand Down
12 changes: 7 additions & 5 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
ABC,
abstractmethod,
)
from datetime import datetime
from typing import (
TYPE_CHECKING,
Any,
Expand All @@ -32,10 +31,6 @@
parsing,
to_offset,
)
from pandas._typing import (
Axis,
npt,
)
from pandas.compat.numpy import function as nv
from pandas.errors import NullFrequencyError
from pandas.util._decorators import (
Expand Down Expand Up @@ -70,6 +65,13 @@
from pandas.core.tools.timedeltas import to_timedelta

if TYPE_CHECKING:
from datetime import datetime

from pandas._typing import (
Axis,
npt,
)

from pandas import CategoricalIndex

_index_doc_kwargs = dict(ibase._index_doc_kwargs)
Expand Down
19 changes: 10 additions & 9 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@
to_offset,
)
from pandas._libs.tslibs.offsets import prefix_mapping
from pandas._typing import (
Dtype,
DtypeObj,
Frequency,
IntervalClosedType,
TimeAmbiguous,
TimeNonexistent,
npt,
)
from pandas.util._decorators import (
cache_readonly,
doc,
Expand All @@ -60,6 +51,16 @@
from pandas.core.tools.times import to_time

if TYPE_CHECKING:
from pandas._typing import (
Dtype,
DtypeObj,
Frequency,
IntervalClosedType,
TimeAmbiguous,
TimeNonexistent,
npt,
)

from pandas.core.api import (
DataFrame,
PeriodIndex,
Expand Down
9 changes: 5 additions & 4 deletions pandas/core/indexes/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@

import numpy as np

from pandas._typing import (
ArrayLike,
npt,
)
from pandas.util._decorators import (
cache_readonly,
doc,
Expand All @@ -25,6 +21,11 @@
from pandas.core.indexes.base import Index

if TYPE_CHECKING:
from pandas._typing import (
ArrayLike,
npt,
)

from pandas.core.arrays import IntervalArray
from pandas.core.arrays._mixins import NDArrayBackedExtensionArray

Expand Down
14 changes: 8 additions & 6 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
)
import textwrap
from typing import (
TYPE_CHECKING,
Any,
Hashable,
Literal,
Expand All @@ -26,12 +27,6 @@
Timestamp,
to_offset,
)
from pandas._typing import (
Dtype,
DtypeObj,
IntervalClosedType,
npt,
)
from pandas.errors import InvalidIndexError
from pandas.util._decorators import (
Appender,
Expand Down Expand Up @@ -92,6 +87,13 @@
timedelta_range,
)

if TYPE_CHECKING:
from pandas._typing import (
Dtype,
DtypeObj,
IntervalClosedType,
npt,
)
_index_doc_kwargs = dict(ibase._index_doc_kwargs)

_index_doc_kwargs.update(
Expand Down
16 changes: 10 additions & 6 deletions pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
datetime,
timedelta,
)
from typing import Hashable
from typing import (
TYPE_CHECKING,
Hashable,
)

import numpy as np

Expand All @@ -16,11 +19,6 @@
Resolution,
Tick,
)
from pandas._typing import (
Dtype,
DtypeObj,
npt,
)
from pandas.util._decorators import (
cache_readonly,
doc,
Expand All @@ -46,6 +44,12 @@
)
from pandas.core.indexes.extension import inherit_names

if TYPE_CHECKING:
from pandas._typing import (
Dtype,
DtypeObj,
npt,
)
_index_doc_kwargs = dict(ibase._index_doc_kwargs)
_index_doc_kwargs.update({"target_klass": "PeriodIndex or list of Periods"})
_shared_doc_kwargs = {
Expand Down
10 changes: 6 additions & 4 deletions pandas/core/indexes/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import operator
from sys import getsizeof
from typing import (
TYPE_CHECKING,
Any,
Callable,
Hashable,
Expand All @@ -20,10 +21,6 @@
)
from pandas._libs.algos import unique_deltas
from pandas._libs.lib import no_default
from pandas._typing import (
Dtype,
npt,
)
from pandas.compat.numpy import function as nv
from pandas.util._decorators import (
cache_readonly,
Expand Down Expand Up @@ -51,6 +48,11 @@
)
from pandas.core.ops.common import unpack_zerodim_and_defer

if TYPE_CHECKING:
from pandas._typing import (
Dtype,
npt,
)
_empty_range = range(0)


Expand Down
6 changes: 5 additions & 1 deletion pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
""" implement the TimedeltaIndex """
from __future__ import annotations

from typing import TYPE_CHECKING

from pandas._libs import (
index as libindex,
lib,
Expand All @@ -10,7 +12,6 @@
Timedelta,
to_offset,
)
from pandas._typing import DtypeObj

from pandas.core.dtypes.common import (
is_dtype_equal,
Expand All @@ -28,6 +29,9 @@
from pandas.core.indexes.datetimelike import DatetimeTimedeltaMixin
from pandas.core.indexes.extension import inherit_names

if TYPE_CHECKING:
from pandas._typing import DtypeObj


@inherit_names(
["__neg__", "__pos__", "__abs__", "total_seconds", "round", "floor", "ceil"]
Expand Down
Loading