diff --git a/LICENSES/SCIPY_LICENSE b/LICENSES/SCIPY_LICENSE index d887ce5f9890f..3d617560f408a 100644 --- a/LICENSES/SCIPY_LICENSE +++ b/LICENSES/SCIPY_LICENSE @@ -28,4 +28,3 @@ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - diff --git a/pandas/__init__.py b/pandas/__init__.py index 1a549c09d22f7..e5eb2a32c5081 100644 --- a/pandas/__init__.py +++ b/pandas/__init__.py @@ -22,7 +22,11 @@ from pandas.compat import is_numpy_dev as _is_numpy_dev # pyright: ignore # noqa:F401 try: - from pandas._libs import hashtable as _hashtable, lib as _lib, tslib as _tslib + from pandas._libs import ( + hashtable as _hashtable, + lib as _lib, + tslib as _tslib, + ) except ImportError as _err: # pragma: no cover _module = _err.name raise ImportError( @@ -34,149 +38,138 @@ del _tslib, _lib, _hashtable from pandas._config import ( - get_option, - set_option, - reset_option, describe_option, + get_option, option_context, options, + reset_option, + set_option, ) -# let init-time option registration happen -import pandas.core.config_init # pyright: ignore # noqa:F401 +from pandas.util._print_versions import show_versions +from pandas.util._tester import test -from pandas.core.api import ( - # dtype +from pandas import ( + api, + arrays, + errors, + io, + plotting, + testing, + tseries, +) + +# use the closest tagged version if possible +from pandas._version import get_versions +from pandas.core.api import ( # dtype; missing; indexes; tseries; conversion; misc + NA, ArrowDtype, + BooleanDtype, + Categorical, + CategoricalDtype, + CategoricalIndex, + DataFrame, + DateOffset, + DatetimeIndex, + DatetimeTZDtype, + Flags, + Float32Dtype, + Float64Dtype, + Grouper, + Index, + IndexSlice, Int8Dtype, Int16Dtype, Int32Dtype, Int64Dtype, + Interval, + IntervalDtype, + IntervalIndex, + MultiIndex, + NamedAgg, + NaT, + Period, + PeriodDtype, + PeriodIndex, + RangeIndex, + Series, + StringDtype, + Timedelta, + TimedeltaIndex, + Timestamp, UInt8Dtype, UInt16Dtype, UInt32Dtype, UInt64Dtype, - Float32Dtype, - Float64Dtype, - CategoricalDtype, - PeriodDtype, - IntervalDtype, - DatetimeTZDtype, - StringDtype, - BooleanDtype, - # missing - NA, + array, + bdate_range, + date_range, + factorize, + interval_range, isna, isnull, notna, notnull, - # indexes - Index, - CategoricalIndex, - RangeIndex, - MultiIndex, - IntervalIndex, - TimedeltaIndex, - DatetimeIndex, - PeriodIndex, - IndexSlice, - # tseries - NaT, - Period, period_range, - Timedelta, + set_eng_float_format, timedelta_range, - Timestamp, - date_range, - bdate_range, - Interval, - interval_range, - DateOffset, - # conversion - to_numeric, to_datetime, + to_numeric, to_timedelta, - # misc - Flags, - Grouper, - factorize, unique, value_counts, - NamedAgg, - array, - Categorical, - set_eng_float_format, - Series, - DataFrame, ) - from pandas.core.arrays.sparse import SparseDtype - -from pandas.tseries.api import infer_freq -from pandas.tseries import offsets - from pandas.core.computation.api import eval +# let init-time option registration happen +import pandas.core.config_init # pyright: ignore # noqa:F401 from pandas.core.reshape.api import ( concat, + crosstab, + cut, + from_dummies, + get_dummies, lreshape, melt, - wide_to_long, merge, merge_asof, merge_ordered, - crosstab, pivot, pivot_table, - get_dummies, - from_dummies, - cut, qcut, + wide_to_long, ) -from pandas import api, arrays, errors, io, plotting, tseries -from pandas import testing -from pandas.util._print_versions import show_versions - -from pandas.io.api import ( - # excel +from pandas.io.api import ( # excel; parsers; pickle; pytables; sql; misc ExcelFile, ExcelWriter, - read_excel, - # parsers - read_csv, - read_fwf, - read_table, - # pickle - read_pickle, - to_pickle, - # pytables HDFStore, - read_hdf, - # sql - read_sql, - read_sql_query, - read_sql_table, - # misc read_clipboard, - read_parquet, - read_orc, + read_csv, + read_excel, read_feather, + read_fwf, read_gbq, + read_hdf, read_html, - read_xml, read_json, - read_stata, + read_orc, + read_parquet, + read_pickle, read_sas, read_spss, + read_sql, + read_sql_query, + read_sql_table, + read_stata, + read_table, + read_xml, + to_pickle, ) - from pandas.io.json._normalize import json_normalize - -from pandas.util._tester import test - -# use the closest tagged version if possible -from pandas._version import get_versions +from pandas.tseries import offsets +from pandas.tseries.api import infer_freq v = get_versions() __version__ = v.get("closest-tag", v["version"]) diff --git a/pandas/_libs/algos.pyx b/pandas/_libs/algos.pyx index adb920e0cca6d..81fd5792ee9e5 100644 --- a/pandas/_libs/algos.pyx +++ b/pandas/_libs/algos.pyx @@ -166,7 +166,7 @@ cpdef ndarray[int64_t, ndim=1] unique_deltas(const int64_t[:] arr): @cython.wraparound(False) @cython.boundscheck(False) -def is_lexsorted(list_of_arrays: list) -> bool: +def is_lexsorted(list_of_arrays: list) -> bint: cdef: Py_ssize_t i Py_ssize_t n, nlevels @@ -752,7 +752,7 @@ def is_monotonic(ndarray[numeric_object_t, ndim=1] arr, bint timelike): tuple is_monotonic_inc : bool is_monotonic_dec : bool - is_strict_monotonic : bool + is_unique : bool """ cdef: Py_ssize_t i, n diff --git a/pandas/_libs/index.pyx b/pandas/_libs/index.pyx index 1050d15439ebf..1b42ad1c0fda7 100644 --- a/pandas/_libs/index.pyx +++ b/pandas/_libs/index.pyx @@ -256,24 +256,24 @@ cdef class IndexEngine: cdef _do_monotonic_check(self): cdef: - bint is_strict_monotonic + bint is_unique if self.mask is not None and np.any(self.mask): self.monotonic_inc = 0 self.monotonic_dec = 0 else: try: values = self.values - self.monotonic_inc, self.monotonic_dec, is_strict_monotonic = \ + self.monotonic_inc, self.monotonic_dec, is_unique = \ self._call_monotonic(values) except TypeError: self.monotonic_inc = 0 self.monotonic_dec = 0 - is_strict_monotonic = 0 + is_unique = 0 self.need_monotonic_check = 0 - # we can only be sure of uniqueness if is_strict_monotonic=1 - if is_strict_monotonic: + # we can only be sure of uniqueness if is_unique=1 + if is_unique: self.unique = 1 self.need_unique_check = 0 diff --git a/pandas/_libs/join.pyx b/pandas/_libs/join.pyx index 2b3b147470cef..667eda1b1f1da 100644 --- a/pandas/_libs/join.pyx +++ b/pandas/_libs/join.pyx @@ -834,10 +834,10 @@ def asof_join_forward_on_X_by_Y(numeric_t[:] left_values, return left_indexer, right_indexer -def asof_join_nearest_on_X_by_Y(ndarray[numeric_t] left_values, - ndarray[numeric_t] right_values, - ndarray[by_t] left_by_values, - ndarray[by_t] right_by_values, +def asof_join_nearest_on_X_by_Y(numeric_t[:] left_values, + numeric_t[:] right_values, + by_t[:] left_by_values, + by_t[:] right_by_values, bint allow_exact_matches=True, tolerance=None, bint use_hashtable=True): @@ -850,17 +850,7 @@ def asof_join_nearest_on_X_by_Y(ndarray[numeric_t] left_values, numeric_t bdiff, fdiff # search both forward and backward - # TODO(cython3): - # Bug in beta1 preventing Cython from choosing - # right specialization when one fused memview is None - # Doesn't matter what type we choose - # (nothing happens anyways since it is None) - # GH 51640 - if left_by_values is not None and left_by_values.dtype != object: - by_dtype = f"{left_by_values.dtype}_t" - else: - by_dtype = object - bli, bri = asof_join_backward_on_X_by_Y[f"{left_values.dtype}_t", by_dtype]( + bli, bri = asof_join_backward_on_X_by_Y( left_values, right_values, left_by_values, @@ -869,7 +859,7 @@ def asof_join_nearest_on_X_by_Y(ndarray[numeric_t] left_values, tolerance, use_hashtable ) - fli, fri = asof_join_forward_on_X_by_Y[f"{left_values.dtype}_t", by_dtype]( + fli, fri = asof_join_forward_on_X_by_Y( left_values, right_values, left_by_values, diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index 0c22f9bec6fde..d20f87ec91d1b 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -150,11 +150,11 @@ def memory_usage_of_objects(arr: object[:]) -> int64_t: Does not include the actual bytes of the pointers """ - cdef: - Py_ssize_t i - Py_ssize_t n - int64_t size = 0 + i: Py_ssize_t + n: Py_ssize_t + size: int64_t + size = 0 n = len(arr) for i in range(n): size += arr[i].__sizeof__() diff --git a/pandas/_libs/sparse_op_helper.pxi.in b/pandas/_libs/sparse_op_helper.pxi.in index 774a8c579f6ce..ac0c705fafbcd 100644 --- a/pandas/_libs/sparse_op_helper.pxi.in +++ b/pandas/_libs/sparse_op_helper.pxi.in @@ -128,9 +128,7 @@ def get_dispatch(dtypes): {{for opname, dtype, rdtype in get_dispatch(dtypes)}} -{{if opname == "pow"}} -@cython.cpow(True) # Cython 3 matches Python pow, which isn't what we want here -{{endif}} + @cython.wraparound(False) @cython.boundscheck(False) cdef tuple block_op_{{opname}}_{{dtype}}({{dtype}}_t[:] x_, @@ -231,9 +229,7 @@ cdef tuple block_op_{{opname}}_{{dtype}}({{dtype}}_t[:] x_, return out, out_index, {{(opname, 'xfill', 'yfill', dtype) | get_op}} -{{if opname == "pow"}} -@cython.cpow(True) # Cython 3 matches Python pow, which isn't what we want here -{{endif}} + @cython.wraparound(False) @cython.boundscheck(False) cdef tuple int_op_{{opname}}_{{dtype}}({{dtype}}_t[:] x_, diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 1b959acfcdd3f..e8e0ddbb404de 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -4109,7 +4109,6 @@ cpdef to_offset(freq): Examples -------- - >>> from pandas.tseries.frequencies import to_offset >>> to_offset("5min") <5 * Minutes> @@ -4125,7 +4124,7 @@ cpdef to_offset(freq): >>> to_offset(pd.Timedelta(days=1)) - >>> to_offset(pd.offsets.Hour()) + >>> to_offset(Hour()) """ if freq is None: @@ -4564,7 +4563,7 @@ def roll_qtrday(other: datetime, n: int, month: int, cdef int _roll_qtrday(npy_datetimestruct* dts, int n, int months_since, - str day_opt) except? -1 nogil: + str day_opt) nogil except? -1: """ See roll_qtrday.__doc__ """ diff --git a/pandas/_libs/tslibs/parsing.pyx b/pandas/_libs/tslibs/parsing.pyx index c314149e24a4c..445683968c58f 100644 --- a/pandas/_libs/tslibs/parsing.pyx +++ b/pandas/_libs/tslibs/parsing.pyx @@ -722,18 +722,6 @@ cdef datetime dateutil_parse( f'Parsed string "{timestr}" gives an invalid tzoffset, ' "which must be between -timedelta(hours=24) and timedelta(hours=24)" ) - elif res.tzname is not None: - # e.g. "1994 Jan 15 05:16 FOO" where FOO is not recognized - # GH#18702 - warnings.warn( - f'Parsed string "{timestr}" included an un-recognized timezone ' - f'"{res.tzname}". Dropping unrecognized timezones is deprecated; ' - "in a future version this will raise. Instead pass the string " - "without the timezone, then use .tz_localize to convert to a " - "recognized timezone.", - FutureWarning, - stacklevel=find_stack_level() - ) out_bestunit[0] = attrname_to_npy_unit[reso] return ret @@ -877,8 +865,6 @@ def guess_datetime_format(dt_str: str, bint dayfirst=False) -> str | None: datetime format string (for `strftime` or `strptime`), or None if it can't be guessed. """ - cdef: - NPY_DATETIMEUNIT out_bestunit day_attribute_and_format = (("day",), "%d", 2) # attr name, format, padding (if any) @@ -909,17 +895,8 @@ def guess_datetime_format(dt_str: str, bint dayfirst=False) -> str | None: datetime_attrs_to_format.remove(day_attribute_and_format) datetime_attrs_to_format.insert(0, day_attribute_and_format) - # same default used by dateutil - default = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) try: - parsed_datetime = dateutil_parse( - dt_str, - default=default, - dayfirst=dayfirst, - yearfirst=False, - ignoretz=False, - out_bestunit=&out_bestunit, - ) + parsed_datetime = du_parse(dt_str, dayfirst=dayfirst) except (ValueError, OverflowError, InvalidOperation): # In case the datetime can't be parsed, its format cannot be guessed return None diff --git a/pandas/_libs/tslibs/timedeltas.pyx b/pandas/_libs/tslibs/timedeltas.pyx index 8f8be37b9f23f..d68fea7d08b2a 100644 --- a/pandas/_libs/tslibs/timedeltas.pyx +++ b/pandas/_libs/tslibs/timedeltas.pyx @@ -489,7 +489,6 @@ cdef int64_t _item_to_timedelta64( raise -@cython.cpow(True) cdef int64_t parse_timedelta_string(str ts) except? -1: """ Parse a regular format timedelta string. Return an int64_t (in ns) diff --git a/pandas/_libs/window/aggregations.pyx b/pandas/_libs/window/aggregations.pyx index 511df25c3a87f..3055b8ff48cc9 100644 --- a/pandas/_libs/window/aggregations.pyx +++ b/pandas/_libs/window/aggregations.pyx @@ -21,8 +21,6 @@ from numpy cimport ( cnp.import_array() -import cython - from pandas._libs.algos import is_monotonic @@ -1735,7 +1733,7 @@ def roll_weighted_var(const float64_t[:] values, const float64_t[:] weights, # ---------------------------------------------------------------------- # Exponentially weighted moving -@cython.cpow(True) + def ewm(const float64_t[:] vals, const int64_t[:] start, const int64_t[:] end, int minp, float64_t com, bint adjust, bint ignore_na, const float64_t[:] deltas=None, bint normalize=True) -> np.ndarray: diff --git a/pandas/core/arrays/_ranges.py b/pandas/core/arrays/_ranges.py index c93fc94685358..f2582cd6f2e58 100644 --- a/pandas/core/arrays/_ranges.py +++ b/pandas/core/arrays/_ranges.py @@ -4,6 +4,8 @@ """ from __future__ import annotations +from typing import TYPE_CHECKING + import numpy as np from pandas._libs.lib import i8max @@ -14,7 +16,9 @@ Timestamp, iNaT, ) -from pandas._typing import npt + +if TYPE_CHECKING: + from pandas._typing import npt def generate_regular_range( diff --git a/pandas/core/arrays/arrow/dtype.py b/pandas/core/arrays/arrow/dtype.py index b6515c2875718..50bb287e54365 100644 --- a/pandas/core/arrays/arrow/dtype.py +++ b/pandas/core/arrays/arrow/dtype.py @@ -8,6 +8,7 @@ ) from decimal import Decimal import re +from typing import TYPE_CHECKING import numpy as np @@ -15,11 +16,6 @@ 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 @@ -32,6 +28,11 @@ import pyarrow as pa if TYPE_CHECKING: + from pandas._typing import ( + DtypeObj, + type_t, + ) + from pandas.core.arrays.arrow import ArrowExtensionArray diff --git a/pandas/core/arrays/arrow/extension_types.py b/pandas/core/arrays/arrow/extension_types.py index 25f597af5e3cf..05b70afc2e24c 100644 --- a/pandas/core/arrays/arrow/extension_types.py +++ b/pandas/core/arrays/arrow/extension_types.py @@ -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: diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index 1a082a7579dc3..4adc09be2f09d 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -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 @@ -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] = {} diff --git a/pandas/core/arrays/boolean.py b/pandas/core/arrays/boolean.py index 2dba557eda169..54bd4220bc060 100644 --- a/pandas/core/arrays/boolean.py +++ b/pandas/core/arrays/boolean.py @@ -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, @@ -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 diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index dd48da9ab6c16..09861f0c3749e 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -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 @@ -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, diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 1624870705b8f..2a014e3b1b49c 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -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 @@ -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 diff --git a/pandas/core/arrays/numeric.py b/pandas/core/arrays/numeric.py index 2d9a3ae63259d..d5fd759adc202 100644 --- a/pandas/core/arrays/numeric.py +++ b/pandas/core/arrays/numeric.py @@ -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 @@ -40,6 +35,12 @@ if TYPE_CHECKING: import pyarrow + from pandas._typing import ( + Dtype, + DtypeObj, + npt, + ) + T = TypeVar("T", bound="NumericArray") diff --git a/pandas/core/arrays/numpy_.py b/pandas/core/arrays/numpy_.py index 216dbede39a6a..35182cb3a58de 100644 --- a/pandas/core/arrays/numpy_.py +++ b/pandas/core/arrays/numpy_.py @@ -1,5 +1,7 @@ from __future__ import annotations +from typing import TYPE_CHECKING + import numpy as np from pandas._libs import lib @@ -7,13 +9,6 @@ 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 @@ -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, diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index f9404fbf57382..54190b0fdcaf7 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -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, @@ -81,8 +75,12 @@ if TYPE_CHECKING: from pandas._typing import ( + AnyArrayLike, + Dtype, + NpDtype, NumpySorter, NumpyValueArrayLike, + npt, ) from pandas.core.arrays import ( diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index fcebd17ace2d3..31f404c30c262 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -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 @@ -120,6 +107,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: diff --git a/pandas/core/arrays/sparse/dtype.py b/pandas/core/arrays/sparse/dtype.py index c7a44d3606fa6..dadd161ceeb38 100644 --- a/pandas/core/arrays/sparse/dtype.py +++ b/pandas/core/arrays/sparse/dtype.py @@ -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 @@ -36,6 +31,12 @@ ) if TYPE_CHECKING: + from pandas._typing import ( + Dtype, + DtypeObj, + type_t, + ) + from pandas.core.arrays.sparse.array import SparseArray diff --git a/pandas/core/arrays/sparse/scipy_sparse.py b/pandas/core/arrays/sparse/scipy_sparse.py index 723449dfcd4a3..1d190ad1919b3 100644 --- a/pandas/core/arrays/sparse/scipy_sparse.py +++ b/pandas/core/arrays/sparse/scipy_sparse.py @@ -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 @@ -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) diff --git a/pandas/core/arrays/string_.py b/pandas/core/arrays/string_.py index 30b18bac7b73b..89f44de3386c7 100644 --- a/pandas/core/arrays/string_.py +++ b/pandas/core/arrays/string_.py @@ -14,13 +14,6 @@ missing as libmissing, ) from pandas._libs.arrays import NDArrayBacked -from pandas._typing import ( - AxisInt, - Dtype, - Scalar, - npt, - type_t, -) from pandas.compat import pa_version_under7p0 from pandas.compat.numpy import function as nv from pandas.util._decorators import doc @@ -58,8 +51,13 @@ import pyarrow from pandas._typing import ( + AxisInt, + Dtype, NumpySorter, NumpyValueArrayLike, + Scalar, + npt, + type_t, ) from pandas import Series diff --git a/pandas/core/arrays/string_arrow.py b/pandas/core/arrays/string_arrow.py index 4d2b39ec61fca..afec3a9340510 100644 --- a/pandas/core/arrays/string_arrow.py +++ b/pandas/core/arrays/string_arrow.py @@ -2,6 +2,7 @@ import re from typing import ( + TYPE_CHECKING, Callable, Union, ) @@ -12,11 +13,12 @@ lib, missing as libmissing, ) -from pandas._typing import ( - Dtype, - Scalar, - npt, -) + +# from pandas._typing import ( +# Dtype, +# Scalar, +# npt, +# ) from pandas.compat import pa_version_under7p0 from pandas.core.dtypes.common import ( @@ -46,6 +48,15 @@ from pandas.core.arrays.arrow._arrow_utils import fallback_performancewarning + +if TYPE_CHECKING: + from pandas._typing import ( + Dtype, + Scalar, + npt, + ) + + ArrowStringScalarOrNAT = Union[str, libmissing.NAType] diff --git a/pandas/core/arrays/timedeltas.py b/pandas/core/arrays/timedeltas.py index d38145295a4db..9c63dc92ca28b 100644 --- a/pandas/core/arrays/timedeltas.py +++ b/pandas/core/arrays/timedeltas.py @@ -39,13 +39,6 @@ parse_timedelta_unit, truediv_object_array, ) -from pandas._typing import ( - AxisInt, - DateTimeErrorChoices, - DtypeObj, - NpDtype, - npt, -) from pandas.compat.numpy import function as nv from pandas.util._validators import validate_endpoints @@ -72,6 +65,14 @@ from pandas.core.ops.common import unpack_zerodim_and_defer if TYPE_CHECKING: + from pandas._typing import ( + AxisInt, + DateTimeErrorChoices, + DtypeObj, + NpDtype, + npt, + ) + from pandas import DataFrame diff --git a/pyproject.toml b/pyproject.toml index b7e4a3cf2416f..508a5bd4faa16 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -291,7 +291,6 @@ exclude = [ # relative imports allowed for asv_bench "asv_bench/*" = ["TID"] # TCH to be enabled gradually -"pandas/core/arrays/*" = ["TCH"] "pandas/core/io/*" = ["TCH"] "pandas/core/indexers/*" = ["TCH"] "pandas/core/indexes/*" = ["TCH"]