diff --git a/pandas/core/array_algos/masked_accumulations.py b/pandas/core/array_algos/masked_accumulations.py index 07113128e0947..1798c0b366a46 100644 --- a/pandas/core/array_algos/masked_accumulations.py +++ b/pandas/core/array_algos/masked_accumulations.py @@ -5,18 +5,22 @@ from __future__ import annotations -from typing import Callable +from typing import ( + TYPE_CHECKING, + Callable, +) import numpy as np -from pandas._typing import npt - from pandas.core.dtypes.common import ( is_bool_dtype, is_float_dtype, is_integer_dtype, ) +if TYPE_CHECKING: + from pandas._typing import npt + def _cum_func( func: Callable, diff --git a/pandas/core/array_algos/masked_reductions.py b/pandas/core/array_algos/masked_reductions.py index 4be053cba75b7..7900bcc6a8e6e 100644 --- a/pandas/core/array_algos/masked_reductions.py +++ b/pandas/core/array_algos/masked_reductions.py @@ -4,18 +4,23 @@ """ from __future__ import annotations -from typing import Callable +from typing import ( + TYPE_CHECKING, + Callable, +) import numpy as np from pandas._libs import missing as libmissing -from pandas._typing import ( - AxisInt, - npt, -) from pandas.core.nanops import check_below_min_count +if TYPE_CHECKING: + from pandas._typing import ( + AxisInt, + npt, + ) + def _reductions( func: Callable, diff --git a/pandas/core/array_algos/putmask.py b/pandas/core/array_algos/putmask.py index 3e2c711d12f26..3b9aad0790df9 100644 --- a/pandas/core/array_algos/putmask.py +++ b/pandas/core/array_algos/putmask.py @@ -11,10 +11,6 @@ import numpy as np from pandas._libs import lib -from pandas._typing import ( - ArrayLike, - npt, -) from pandas.compat import np_version_under1p21 from pandas.core.dtypes.cast import infer_dtype_from @@ -23,6 +19,11 @@ from pandas.core.arrays import ExtensionArray if TYPE_CHECKING: + from pandas._typing import ( + ArrayLike, + npt, + ) + from pandas import MultiIndex diff --git a/pandas/core/array_algos/quantile.py b/pandas/core/array_algos/quantile.py index d3d9cb1b29b9a..7647f321e1d4b 100644 --- a/pandas/core/array_algos/quantile.py +++ b/pandas/core/array_algos/quantile.py @@ -1,12 +1,9 @@ from __future__ import annotations +from typing import TYPE_CHECKING + import numpy as np -from pandas._typing import ( - ArrayLike, - Scalar, - npt, -) from pandas.compat.numpy import np_percentile_argname from pandas.core.dtypes.missing import ( @@ -14,6 +11,13 @@ na_value_for_dtype, ) +if TYPE_CHECKING: + from pandas._typing import ( + ArrayLike, + Scalar, + npt, + ) + def quantile_compat( values: ArrayLike, qs: npt.NDArray[np.float64], interpolation: str diff --git a/pandas/core/array_algos/replace.py b/pandas/core/array_algos/replace.py index 14bf26f40ea0d..af01a692bc0ce 100644 --- a/pandas/core/array_algos/replace.py +++ b/pandas/core/array_algos/replace.py @@ -6,18 +6,13 @@ import operator import re from typing import ( + TYPE_CHECKING, Any, Pattern, ) import numpy as np -from pandas._typing import ( - ArrayLike, - Scalar, - npt, -) - from pandas.core.dtypes.common import ( is_re, is_re_compilable, @@ -25,6 +20,13 @@ ) from pandas.core.dtypes.missing import isna +if TYPE_CHECKING: + from pandas._typing import ( + ArrayLike, + Scalar, + npt, + ) + def should_use_regex(regex: bool, to_replace: Any) -> bool: """ diff --git a/pandas/core/array_algos/take.py b/pandas/core/array_algos/take.py index 7282b0729f73f..c97891b0a460d 100644 --- a/pandas/core/array_algos/take.py +++ b/pandas/core/array_algos/take.py @@ -13,11 +13,6 @@ algos as libalgos, lib, ) -from pandas._typing import ( - ArrayLike, - AxisInt, - npt, -) from pandas.core.dtypes.cast import maybe_promote from pandas.core.dtypes.common import ( @@ -29,6 +24,12 @@ from pandas.core.construction import ensure_wrapped_if_datetimelike if TYPE_CHECKING: + from pandas._typing import ( + ArrayLike, + AxisInt, + npt, + ) + from pandas.core.arrays._mixins import NDArrayBackedExtensionArray from pandas.core.arrays.base import ExtensionArray diff --git a/pandas/core/array_algos/transforms.py b/pandas/core/array_algos/transforms.py index 56648189f1759..090bbc4c7be24 100644 --- a/pandas/core/array_algos/transforms.py +++ b/pandas/core/array_algos/transforms.py @@ -4,9 +4,12 @@ from __future__ import annotations +from typing import TYPE_CHECKING + import numpy as np -from pandas._typing import AxisInt +if TYPE_CHECKING: + from pandas._typing import AxisInt def shift(values: np.ndarray, periods: int, axis: AxisInt, fill_value) -> np.ndarray: diff --git a/pandas/core/dtypes/astype.py b/pandas/core/dtypes/astype.py index 7ae5993c857e2..cd91f06d7ff04 100644 --- a/pandas/core/dtypes/astype.py +++ b/pandas/core/dtypes/astype.py @@ -15,11 +15,6 @@ from pandas._libs import lib from pandas._libs.tslibs.timedeltas import array_to_timedelta64 -from pandas._typing import ( - ArrayLike, - DtypeObj, - IgnoreRaise, -) from pandas.errors import IntCastingNaNError from pandas.core.dtypes.common import ( @@ -37,8 +32,13 @@ ) if TYPE_CHECKING: - from pandas.core.arrays import ExtensionArray + from pandas._typing import ( + ArrayLike, + DtypeObj, + IgnoreRaise, + ) + from pandas.core.arrays import ExtensionArray _dtype_obj = np.dtype(object) diff --git a/pandas/core/dtypes/base.py b/pandas/core/dtypes/base.py index 65a47452b1fe8..34f22cf13f8e9 100644 --- a/pandas/core/dtypes/base.py +++ b/pandas/core/dtypes/base.py @@ -15,12 +15,6 @@ from pandas._libs import missing as libmissing from pandas._libs.hashtable import object_hash -from pandas._typing import ( - DtypeObj, - Shape, - npt, - type_t, -) from pandas.errors import AbstractMethodError from pandas.core.dtypes.generic import ( @@ -30,6 +24,13 @@ ) if TYPE_CHECKING: + from pandas._typing import ( + DtypeObj, + Shape, + npt, + type_t, + ) + from pandas.core.arrays import ExtensionArray # To parameterize on same ExtensionDtype diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index 8aadb67aea533..cfcae7f40919a 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -36,14 +36,6 @@ is_supported_unit, ) from pandas._libs.tslibs.timedeltas import array_to_timedelta64 -from pandas._typing import ( - ArrayLike, - Dtype, - DtypeObj, - NumpyIndexT, - Scalar, - npt, -) from pandas.errors import ( IntCastingNaNError, LossySetitemError, @@ -100,6 +92,15 @@ ) if TYPE_CHECKING: + from pandas._typing import ( + ArrayLike, + Dtype, + DtypeObj, + NumpyIndexT, + Scalar, + npt, + ) + from pandas import Index from pandas.core.arrays import ( Categorical, diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index 678b3d6752f02..6802cf096e868 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -4,6 +4,7 @@ from __future__ import annotations from typing import ( + TYPE_CHECKING, Any, Callable, ) @@ -17,10 +18,6 @@ lib, ) from pandas._libs.tslibs import conversion -from pandas._typing import ( - ArrayLike, - DtypeObj, -) from pandas.core.dtypes.base import _registry as registry from pandas.core.dtypes.dtypes import ( @@ -54,6 +51,12 @@ is_sequence, ) +if TYPE_CHECKING: + from pandas._typing import ( + ArrayLike, + DtypeObj, + ) + DT64NS_DTYPE = conversion.DT64NS_DTYPE TD64NS_DTYPE = conversion.TD64NS_DTYPE INT64_DTYPE = np.dtype(np.int64) diff --git a/pandas/core/dtypes/concat.py b/pandas/core/dtypes/concat.py index 28bc849088d5f..9917af9da7665 100644 --- a/pandas/core/dtypes/concat.py +++ b/pandas/core/dtypes/concat.py @@ -7,8 +7,6 @@ import numpy as np -from pandas._typing import AxisInt - from pandas.core.dtypes.astype import astype_array from pandas.core.dtypes.cast import ( common_dtype_categorical_compat, @@ -26,6 +24,8 @@ ) if TYPE_CHECKING: + from pandas._typing import AxisInt + from pandas.core.arrays import Categorical diff --git a/pandas/core/dtypes/dtypes.py b/pandas/core/dtypes/dtypes.py index 2909b24840831..2f689b17830f8 100644 --- a/pandas/core/dtypes/dtypes.py +++ b/pandas/core/dtypes/dtypes.py @@ -31,13 +31,6 @@ PeriodDtypeBase, abbrev_to_npy_unit, ) -from pandas._typing import ( - Dtype, - DtypeObj, - Ordered, - npt, - type_t, -) from pandas.core.dtypes.base import ( ExtensionDtype, @@ -57,6 +50,14 @@ import pyarrow + from pandas._typing import ( + Dtype, + DtypeObj, + Ordered, + npt, + type_t, + ) + from pandas import ( Categorical, Index, diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 8cd0ffadcc17c..98acab52e62f0 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -12,7 +12,6 @@ import collections from collections import abc -import datetime import functools from io import StringIO import itertools @@ -52,46 +51,6 @@ is_range_indexer, no_default, ) -from pandas._typing import ( - AggFuncType, - AlignJoin, - AnyAll, - AnyArrayLike, - ArrayLike, - Axes, - Axis, - AxisInt, - ColspaceArgType, - CompressionOptions, - CorrelationMethod, - DropKeep, - Dtype, - DtypeObj, - FilePath, - FillnaOptions, - FloatFormatType, - FormattersType, - Frequency, - IgnoreRaise, - IndexKeyFunc, - IndexLabel, - Level, - MergeHow, - NaPosition, - PythonFuncType, - QuantileInterpolation, - ReadBuffer, - Renamer, - Scalar, - SortKind, - StorageOptions, - Suffixes, - TimedeltaConvertibleTypes, - TimestampConvertibleTypes, - ValueKeyFunc, - WriteBuffer, - npt, -) from pandas.compat import PYPY from pandas.compat._optional import import_optional_dependency from pandas.compat.numpy import ( @@ -235,6 +194,49 @@ import pandas.plotting if TYPE_CHECKING: + import datetime + + from pandas._typing import ( + AggFuncType, + AlignJoin, + AnyAll, + AnyArrayLike, + ArrayLike, + Axes, + Axis, + AxisInt, + ColspaceArgType, + CompressionOptions, + CorrelationMethod, + DropKeep, + Dtype, + DtypeObj, + FilePath, + FillnaOptions, + FloatFormatType, + FormattersType, + Frequency, + IgnoreRaise, + IndexKeyFunc, + IndexLabel, + Level, + MergeHow, + NaPosition, + PythonFuncType, + QuantileInterpolation, + ReadBuffer, + Renamer, + Scalar, + SortKind, + StorageOptions, + Suffixes, + TimedeltaConvertibleTypes, + TimestampConvertibleTypes, + ValueKeyFunc, + WriteBuffer, + npt, + ) + from pandas.core.groupby.generic import DataFrameGroupBy from pandas.core.interchange.dataframe_protocol import DataFrame as DataFrameXchg from pandas.core.internals import SingleDataManager diff --git a/pandas/core/series.py b/pandas/core/series.py index 03d7b25aca49a..95ee3f1af58f1 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -34,43 +34,10 @@ properties, reshape, ) -from pandas._libs.internals import BlockValuesRefs from pandas._libs.lib import ( is_range_indexer, no_default, ) -from pandas._typing import ( - AggFuncType, - AlignJoin, - AnyAll, - AnyArrayLike, - ArrayLike, - Axis, - AxisInt, - CorrelationMethod, - DropKeep, - Dtype, - DtypeObj, - FilePath, - FillnaOptions, - Frequency, - IgnoreRaise, - IndexKeyFunc, - IndexLabel, - Level, - NaPosition, - QuantileInterpolation, - Renamer, - Scalar, - SingleManager, - SortKind, - StorageOptions, - TimedeltaConvertibleTypes, - TimestampConvertibleTypes, - ValueKeyFunc, - WriteBuffer, - npt, -) from pandas.compat import PYPY from pandas.compat.numpy import function as nv from pandas.errors import ( @@ -176,10 +143,41 @@ import pandas.plotting if TYPE_CHECKING: + from pandas._libs.internals import BlockValuesRefs from pandas._typing import ( + AggFuncType, + AlignJoin, + AnyAll, + AnyArrayLike, + ArrayLike, + Axis, + AxisInt, + CorrelationMethod, + DropKeep, + Dtype, + DtypeObj, + FilePath, + FillnaOptions, + Frequency, + IgnoreRaise, + IndexKeyFunc, + IndexLabel, + Level, + NaPosition, NumpySorter, NumpyValueArrayLike, + QuantileInterpolation, + Renamer, + Scalar, + SingleManager, + SortKind, + StorageOptions, Suffixes, + TimedeltaConvertibleTypes, + TimestampConvertibleTypes, + ValueKeyFunc, + WriteBuffer, + npt, ) from pandas.core.frame import DataFrame diff --git a/pyproject.toml b/pyproject.toml index 8760d9695f704..58a70b584ca21 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -293,11 +293,6 @@ exclude = [ # TCH to be enabled gradually "pandas/core/arrays/*" = ["TCH"] "pandas/core/io/*" = ["TCH"] -"pandas/core/array_algos/*" = ["TCH"] -"pandas/core/dtypes/*" = ["TCH"] -"pandas/core/generic.py" = ["TCH"] -"pandas/core/frame.py" = ["TCH"] -"pandas/core/series.py" = ["TCH"] "pandas/core/nanops.py" = ["TCH"] "pandas/core/apply.py" = ["TCH"] "pandas/core/base.py" = ["TCH"]