Skip to content

STYLE: enable ruff TCH on some file #51835

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 8 commits into from
Mar 9, 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: 4 additions & 2 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from __future__ import annotations

import importlib
import types
from typing import (
TYPE_CHECKING,
Sequence,
)

from pandas._config import get_option

from pandas._typing import IndexLabel
from pandas.util._decorators import (
Appender,
Substitution,
Expand All @@ -27,8 +25,12 @@
from pandas.core.base import PandasObject

if TYPE_CHECKING:
import types

from matplotlib.axes import Axes

from pandas._typing import IndexLabel

from pandas import DataFrame


Expand Down
3 changes: 2 additions & 1 deletion pandas/plotting/_matplotlib/boxplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from matplotlib.artist import setp
import numpy as np

from pandas._typing import MatplotlibColor
from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.common import is_dict_like
Expand All @@ -37,6 +36,8 @@
from matplotlib.axes import Axes
from matplotlib.lines import Line2D

from pandas._typing import MatplotlibColor


class BoxPlot(LinePlot):
@property
Expand Down
13 changes: 7 additions & 6 deletions pandas/plotting/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,8 @@
import warnings

import matplotlib as mpl
from matplotlib.artist import Artist
import numpy as np

from pandas._typing import (
IndexLabel,
PlottingOrientation,
npt,
)
from pandas.errors import AbstractMethodError
from pandas.util._decorators import cache_readonly
from pandas.util._exceptions import find_stack_level
Expand Down Expand Up @@ -79,9 +73,16 @@
)

if TYPE_CHECKING:
from matplotlib.artist import Artist
from matplotlib.axes import Axes
from matplotlib.axis import Axis

from pandas._typing import (
IndexLabel,
PlottingOrientation,
npt,
)


def _color_in_style(style: str) -> bool:
"""
Expand Down
13 changes: 8 additions & 5 deletions pandas/plotting/_matplotlib/groupby.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
from __future__ import annotations

import numpy as np
from typing import TYPE_CHECKING

from pandas._typing import (
Dict,
IndexLabel,
)
import numpy as np

from pandas.core.dtypes.missing import remove_na_arraylike

Expand All @@ -18,6 +15,12 @@

from pandas.plotting._matplotlib.misc import unpack_single_str_list

if TYPE_CHECKING:
from pandas._typing import (
Dict,
IndexLabel,
)


def create_iter_data_given_by(
data: DataFrame, kind: str = "hist"
Expand Down
4 changes: 2 additions & 2 deletions pandas/plotting/_matplotlib/hist.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import numpy as np

from pandas._typing import PlottingOrientation

from pandas.core.dtypes.common import (
is_integer,
is_list_like,
Expand Down Expand Up @@ -42,6 +40,8 @@
if TYPE_CHECKING:
from matplotlib.axes import Axes

from pandas._typing import PlottingOrientation

from pandas import DataFrame


Expand Down
3 changes: 2 additions & 1 deletion pandas/plotting/_matplotlib/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from __future__ import annotations

from datetime import timedelta
import functools
from typing import (
TYPE_CHECKING,
Expand Down Expand Up @@ -37,6 +36,8 @@
)

if TYPE_CHECKING:
from datetime import timedelta

from matplotlib.axes import Axes

from pandas import (
Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/extension/array_with_attr/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
from __future__ import annotations

import numbers
from typing import TYPE_CHECKING

import numpy as np

from pandas._typing import type_t

from pandas.core.dtypes.base import ExtensionDtype

import pandas as pd
from pandas.core.arrays import ExtensionArray

if TYPE_CHECKING:
from pandas._typing import type_t


class FloatAttrDtype(ExtensionDtype):
type = float
Expand Down
35 changes: 18 additions & 17 deletions pandas/tests/extension/date/array.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
from __future__ import annotations

import datetime as dt
from typing import (
TYPE_CHECKING,
Any,
Optional,
Sequence,
Tuple,
Union,
cast,
)

import numpy as np

from pandas._typing import (
Dtype,
PositionalIndexer,
)

from pandas.core.dtypes.dtypes import register_extension_dtype

from pandas.api.extensions import (
Expand All @@ -23,6 +18,12 @@
)
from pandas.api.types import pandas_dtype

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


@register_extension_dtype
class DateDtype(ExtensionDtype):
Expand Down Expand Up @@ -61,12 +62,12 @@ def __repr__(self) -> str:
class DateArray(ExtensionArray):
def __init__(
self,
dates: Union[
dt.date,
Sequence[dt.date],
Tuple[np.ndarray, np.ndarray, np.ndarray],
np.ndarray,
],
dates: (
dt.date
| Sequence[dt.date]
| tuple[np.ndarray, np.ndarray, np.ndarray]
| np.ndarray
),
) -> None:
if isinstance(dates, dt.date):
self._year = np.array([dates.year])
Expand Down Expand Up @@ -146,7 +147,7 @@ def __getitem__(self, item: PositionalIndexer):
else:
raise NotImplementedError("only ints are supported as indexes")

def __setitem__(self, key: Union[int, slice, np.ndarray], value: Any):
def __setitem__(self, key: int | slice | np.ndarray, value: Any):
if not isinstance(key, int):
raise NotImplementedError("only ints are supported as indexes")

Expand All @@ -160,7 +161,7 @@ def __setitem__(self, key: Union[int, slice, np.ndarray], value: Any):
def __repr__(self) -> str:
return f"DateArray{list(zip(self._year, self._month, self._day))}"

def copy(self) -> "DateArray":
def copy(self) -> DateArray:
return DateArray((self._year.copy(), self._month.copy(), self._day.copy()))

def isna(self) -> np.ndarray:
Expand All @@ -172,7 +173,7 @@ def isna(self) -> np.ndarray:
)

@classmethod
def _from_sequence(cls, scalars, *, dtype: Optional[Dtype] = None, copy=False):
def _from_sequence(cls, scalars, *, dtype: Dtype | None = None, copy=False):
if isinstance(scalars, dt.date):
pass
elif isinstance(scalars, DateArray):
Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/extension/decimal/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import numbers
import random
import sys
from typing import TYPE_CHECKING

import numpy as np

from pandas._typing import type_t

from pandas.core.dtypes.base import ExtensionDtype
from pandas.core.dtypes.common import (
is_dtype_equal,
Expand All @@ -33,6 +32,9 @@
)
from pandas.core.indexers import check_array_indexer

if TYPE_CHECKING:
from pandas._typing import type_t


@register_extension_dtype
class DecimalDtype(ExtensionDtype):
Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/extension/json/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
import string
import sys
from typing import (
TYPE_CHECKING,
Any,
Mapping,
)

import numpy as np

from pandas._typing import type_t

from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike
from pandas.core.dtypes.common import (
is_bool_dtype,
Expand All @@ -45,6 +44,9 @@
)
from pandas.core.indexers import unpack_tuple_and_ellipses

if TYPE_CHECKING:
from pandas._typing import type_t


class JSONDtype(ExtensionDtype):
type = abc.Mapping
Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/extension/list/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
import numbers
import random
import string
from typing import TYPE_CHECKING

import numpy as np

from pandas._typing import type_t

from pandas.core.dtypes.base import ExtensionDtype

import pandas as pd
Expand All @@ -22,6 +21,9 @@
)
from pandas.core.arrays import ExtensionArray

if TYPE_CHECKING:
from pandas._typing import type_t


class ListDtype(ExtensionDtype):
type = list
Expand Down
5 changes: 4 additions & 1 deletion pandas/tests/frame/common.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from __future__ import annotations

from pandas._typing import AxisInt
from typing import TYPE_CHECKING

from pandas import (
DataFrame,
concat,
)

if TYPE_CHECKING:
from pandas._typing import AxisInt


def _check_mixed_float(df, dtype=None):
# float16 are most likely to be upcasted to float32
Expand Down
5 changes: 4 additions & 1 deletion pandas/tests/tseries/offsets/test_custom_business_month.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
datetime,
timedelta,
)
from typing import TYPE_CHECKING

import numpy as np
import pytest
Expand All @@ -29,11 +30,13 @@
assert_is_on_offset,
assert_offset_equal,
)
from pandas.tests.tseries.offsets.test_offsets import _ApplyCases

from pandas.tseries import offsets
from pandas.tseries.holiday import USFederalHolidayCalendar

if TYPE_CHECKING:
from pandas.tests.tseries.offsets.test_offsets import _ApplyCases


@pytest.fixture
def dt():
Expand Down
1 change: 1 addition & 0 deletions pandas/tseries/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: TCH004
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as #51812

from typing import TYPE_CHECKING

if TYPE_CHECKING:
Expand Down
5 changes: 4 additions & 1 deletion pandas/tseries/frequencies.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from typing import TYPE_CHECKING

import numpy as np

from pandas._libs.algos import unique_deltas
Expand All @@ -26,7 +28,6 @@
to_offset,
)
from pandas._libs.tslibs.parsing import get_rule_month
from pandas._typing import npt
from pandas.util._decorators import cache_readonly

from pandas.core.dtypes.common import (
Expand All @@ -42,6 +43,8 @@

from pandas.core.algorithms import unique

if TYPE_CHECKING:
from pandas._typing import npt
# ---------------------------------------------------------------------
# Offset names ("time rules") and related functions

Expand Down
5 changes: 0 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,6 @@ exclude = [
"pandas/core/algorithms.py" = ["TCH"]
"pandas/core/ops/*" = ["TCH"]
"pandas/core/sorting.py" = ["TCH"]
"pandas/core/construction.py" = ["TCH"]
"pandas/core/missing.py" = ["TCH"]
"pandas/tseries/*" = ["TCH"]
"pandas/tests/*" = ["TCH"]
"pandas/plotting/*" = ["TCH"]
"pandas/util/*" = ["TCH"]
"pandas/_libs/*" = ["TCH"]
# Keep this one enabled
Expand Down