diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f8cb869e6ed89..f65c42dab1852 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -230,7 +230,7 @@ repos: language: python additional_dependencies: - flake8==4.0.1 - - flake8-pyi==22.5.1 + - flake8-pyi==22.7.0 - id: future-annotations name: import annotations from __future__ entry: 'from __future__ import annotations' diff --git a/pandas/_libs/algos.pyi b/pandas/_libs/algos.pyi index f55ff0ae8b574..9ffcf25f6eacd 100644 --- a/pandas/_libs/algos.pyi +++ b/pandas/_libs/algos.pyi @@ -1,5 +1,3 @@ -from __future__ import annotations - from typing import Any import numpy as np diff --git a/pandas/_libs/interval.pyi b/pandas/_libs/interval.pyi index bad0f2bab93d8..b27d2b5f8fd4d 100644 --- a/pandas/_libs/interval.pyi +++ b/pandas/_libs/interval.pyi @@ -1,5 +1,3 @@ -from __future__ import annotations - from typing import ( Any, Generic, @@ -84,7 +82,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]): self: Interval[_OrderableTimesT], key: _OrderableTimesT ) -> bool: ... @overload - def __contains__(self: Interval[_OrderableScalarT], key: int | float) -> bool: ... + def __contains__(self: Interval[_OrderableScalarT], key: float) -> bool: ... @overload def __add__( self: Interval[_OrderableTimesT], y: Timedelta @@ -94,7 +92,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]): self: Interval[int], y: _OrderableScalarT ) -> Interval[_OrderableScalarT]: ... @overload - def __add__(self: Interval[float], y: int | float) -> Interval[float]: ... + def __add__(self: Interval[float], y: float) -> Interval[float]: ... @overload def __radd__( self: Interval[_OrderableTimesT], y: Timedelta @@ -104,7 +102,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]): self: Interval[int], y: _OrderableScalarT ) -> Interval[_OrderableScalarT]: ... @overload - def __radd__(self: Interval[float], y: int | float) -> Interval[float]: ... + def __radd__(self: Interval[float], y: float) -> Interval[float]: ... @overload def __sub__( self: Interval[_OrderableTimesT], y: Timedelta @@ -114,7 +112,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]): self: Interval[int], y: _OrderableScalarT ) -> Interval[_OrderableScalarT]: ... @overload - def __sub__(self: Interval[float], y: int | float) -> Interval[float]: ... + def __sub__(self: Interval[float], y: float) -> Interval[float]: ... @overload def __rsub__( self: Interval[_OrderableTimesT], y: Timedelta @@ -124,31 +122,31 @@ class Interval(IntervalMixin, Generic[_OrderableT]): self: Interval[int], y: _OrderableScalarT ) -> Interval[_OrderableScalarT]: ... @overload - def __rsub__(self: Interval[float], y: int | float) -> Interval[float]: ... + def __rsub__(self: Interval[float], y: float) -> Interval[float]: ... @overload def __mul__( self: Interval[int], y: _OrderableScalarT ) -> Interval[_OrderableScalarT]: ... @overload - def __mul__(self: Interval[float], y: int | float) -> Interval[float]: ... + def __mul__(self: Interval[float], y: float) -> Interval[float]: ... @overload def __rmul__( self: Interval[int], y: _OrderableScalarT ) -> Interval[_OrderableScalarT]: ... @overload - def __rmul__(self: Interval[float], y: int | float) -> Interval[float]: ... + def __rmul__(self: Interval[float], y: float) -> Interval[float]: ... @overload def __truediv__( self: Interval[int], y: _OrderableScalarT ) -> Interval[_OrderableScalarT]: ... @overload - def __truediv__(self: Interval[float], y: int | float) -> Interval[float]: ... + def __truediv__(self: Interval[float], y: float) -> Interval[float]: ... @overload def __floordiv__( self: Interval[int], y: _OrderableScalarT ) -> Interval[_OrderableScalarT]: ... @overload - def __floordiv__(self: Interval[float], y: int | float) -> Interval[float]: ... + def __floordiv__(self: Interval[float], y: float) -> Interval[float]: ... def overlaps(self: Interval[_OrderableT], other: Interval[_OrderableT]) -> bool: ... def intervals_to_interval_bounds( diff --git a/pandas/_libs/join.pyi b/pandas/_libs/join.pyi index 8d02f8f57dee1..11b65b859095f 100644 --- a/pandas/_libs/join.pyi +++ b/pandas/_libs/join.pyi @@ -55,7 +55,7 @@ def asof_join_backward_on_X_by_Y( left_by_values: np.ndarray, # by_t[:] right_by_values: np.ndarray, # by_t[:] allow_exact_matches: bool = ..., - tolerance: np.number | int | float | None = ..., + tolerance: np.number | float | None = ..., use_hashtable: bool = ..., ) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ... def asof_join_forward_on_X_by_Y( @@ -64,7 +64,7 @@ def asof_join_forward_on_X_by_Y( left_by_values: np.ndarray, # by_t[:] right_by_values: np.ndarray, # by_t[:] allow_exact_matches: bool = ..., - tolerance: np.number | int | float | None = ..., + tolerance: np.number | float | None = ..., use_hashtable: bool = ..., ) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ... def asof_join_nearest_on_X_by_Y( @@ -73,6 +73,6 @@ def asof_join_nearest_on_X_by_Y( left_by_values: np.ndarray, # by_t[:] right_by_values: np.ndarray, # by_t[:] allow_exact_matches: bool = ..., - tolerance: np.number | int | float | None = ..., + tolerance: np.number | float | None = ..., use_hashtable: bool = ..., ) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ... diff --git a/pandas/_libs/json.pyi b/pandas/_libs/json.pyi index 555484a37c83f..8e7ba60ccce24 100644 --- a/pandas/_libs/json.pyi +++ b/pandas/_libs/json.pyi @@ -12,7 +12,7 @@ def dumps( date_unit: str = ..., iso_dates: bool = ..., default_handler: None - | Callable[[Any], str | int | float | bool | list | dict | None] = ..., + | Callable[[Any], str | float | bool | list | dict | None] = ..., ) -> str: ... def loads( s: str, diff --git a/pandas/_libs/tslibs/offsets.pyi b/pandas/_libs/tslibs/offsets.pyi index c885b869f983a..c3d550c7a5ba9 100644 --- a/pandas/_libs/tslibs/offsets.pyi +++ b/pandas/_libs/tslibs/offsets.pyi @@ -1,5 +1,3 @@ -from __future__ import annotations - from datetime import ( datetime, timedelta, diff --git a/pandas/_libs/tslibs/timedeltas.pyi b/pandas/_libs/tslibs/timedeltas.pyi index 1921329da9e24..7969c0901e08f 100644 --- a/pandas/_libs/tslibs/timedeltas.pyi +++ b/pandas/_libs/tslibs/timedeltas.pyi @@ -86,7 +86,7 @@ class Timedelta(timedelta): cls: type[_S], value=..., unit: str = ..., - **kwargs: int | float | np.integer | np.floating, + **kwargs: float | np.integer | np.floating, ) -> _S: ... # GH 46171 # While Timedelta can return pd.NaT, having the constructor return @@ -123,7 +123,7 @@ class Timedelta(timedelta): @overload # type: ignore[override] def __floordiv__(self, other: timedelta) -> int: ... @overload - def __floordiv__(self, other: int | float) -> Timedelta: ... + def __floordiv__(self, other: float) -> Timedelta: ... @overload def __floordiv__( self, other: npt.NDArray[np.timedelta64] diff --git a/pandas/_libs/tslibs/timestamps.pyi b/pandas/_libs/tslibs/timestamps.pyi index 082f26cf6f213..f39d1f44d82c0 100644 --- a/pandas/_libs/tslibs/timestamps.pyi +++ b/pandas/_libs/tslibs/timestamps.pyi @@ -33,13 +33,7 @@ class Timestamp(datetime): value: int # np.int64 def __new__( cls: type[_DatetimeT], - ts_input: int - | np.integer - | float - | str - | _date - | datetime - | np.datetime64 = ..., + ts_input: np.integer | float | str | _date | datetime | np.datetime64 = ..., freq: int | None | str | BaseOffset = ..., tz: str | _tzinfo | None | int = ..., unit: str | int | None = ..., diff --git a/pandas/_libs/writers.pyi b/pandas/_libs/writers.pyi index 0d2096eee3573..611c0c7cd1512 100644 --- a/pandas/_libs/writers.pyi +++ b/pandas/_libs/writers.pyi @@ -1,5 +1,3 @@ -from __future__ import annotations - import numpy as np from pandas._typing import ArrayLike diff --git a/pandas/_typing.py b/pandas/_typing.py index 4bc5f75400455..6e531d10336b5 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -82,7 +82,7 @@ # scalars -PythonScalar = Union[str, int, float, bool] +PythonScalar = Union[str, float, bool] DatetimeLikeScalar = Union["Period", "Timestamp", "Timedelta"] PandasScalar = Union["Period", "Timestamp", "Timedelta", "Interval"] Scalar = Union[PythonScalar, PandasScalar, np.datetime64, np.timedelta64, datetime] @@ -92,10 +92,10 @@ # timestamp and timedelta convertible types TimestampConvertibleTypes = Union[ - "Timestamp", datetime, np.datetime64, int, np.int64, float, str + "Timestamp", datetime, np.datetime64, np.int64, float, str ] TimedeltaConvertibleTypes = Union[ - "Timedelta", timedelta, np.timedelta64, int, np.int64, float, str + "Timedelta", timedelta, np.timedelta64, np.int64, float, str ] Timezone = Union[str, tzinfo] @@ -126,7 +126,7 @@ ] # dtypes -NpDtype = Union[str, np.dtype, type_t[Union[str, float, int, complex, bool, object]]] +NpDtype = Union[str, np.dtype, type_t[Union[str, complex, bool, object]]] Dtype = Union["ExtensionDtype", NpDtype] AstypeArg = Union["ExtensionDtype", "npt.DTypeLike"] # DtypeArg specifies all allowable dtypes in a functions its dtype argument diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index c3fbd716ad09d..ea9414aaaa1a8 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -2170,11 +2170,11 @@ def validate_periods(periods: None) -> None: @overload -def validate_periods(periods: int | float) -> int: +def validate_periods(periods: float) -> int: ... -def validate_periods(periods: int | float | None) -> int | None: +def validate_periods(periods: float | None) -> int | None: """ If a `periods` argument is passed to the Datetime/Timedelta Array/Index constructor, cast it to an integer. diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 47203fbf315e5..a541cbfe502fb 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -2563,7 +2563,7 @@ def to_stata( compression: CompressionOptions = "infer", storage_options: StorageOptions = None, *, - value_labels: dict[Hashable, dict[float | int, str]] | None = None, + value_labels: dict[Hashable, dict[float, str]] | None = None, ) -> None: """ Export DataFrame object to Stata dta format. diff --git a/pandas/core/nanops.py b/pandas/core/nanops.py index 81766dc91f271..6658b25d09e6d 100644 --- a/pandas/core/nanops.py +++ b/pandas/core/nanops.py @@ -827,7 +827,7 @@ def _get_counts_nanvar( axis: int | None, ddof: int, dtype: np.dtype = np.dtype(np.float64), -) -> tuple[int | float | np.ndarray, int | float | np.ndarray]: +) -> tuple[float | np.ndarray, float | np.ndarray]: """ Get the count of non-null values along an axis, accounting for degrees of freedom. @@ -1414,7 +1414,7 @@ def _get_counts( mask: npt.NDArray[np.bool_] | None, axis: int | None, dtype: np.dtype = np.dtype(np.float64), -) -> int | float | np.ndarray: +) -> float | np.ndarray: """ Get the count of non-null values along an axis diff --git a/pandas/core/reshape/encoding.py b/pandas/core/reshape/encoding.py index fc908a5648885..da4de8cc57e65 100644 --- a/pandas/core/reshape/encoding.py +++ b/pandas/core/reshape/encoding.py @@ -272,7 +272,7 @@ def get_empty_frame(data) -> DataFrame: if sparse: - fill_value: bool | float | int + fill_value: bool | float if is_integer_dtype(dtype): fill_value = 0 elif dtype == np.dtype(bool): diff --git a/pandas/core/tools/datetimes.py b/pandas/core/tools/datetimes.py index 1ec0e6ca83d8f..7ec4bc1016a9d 100644 --- a/pandas/core/tools/datetimes.py +++ b/pandas/core/tools/datetimes.py @@ -91,7 +91,7 @@ # types used in annotations ArrayConvertible = Union[List, Tuple, AnyArrayLike] -Scalar = Union[int, float, str] +Scalar = Union[float, str] DatetimeScalar = Union[Scalar, datetime] DatetimeScalarOrArrayConvertible = Union[DatetimeScalar, ArrayConvertible] diff --git a/pandas/core/tools/timedeltas.py b/pandas/core/tools/timedeltas.py index 720d02f0cf59e..5026c97c0b2b0 100644 --- a/pandas/core/tools/timedeltas.py +++ b/pandas/core/tools/timedeltas.py @@ -45,7 +45,7 @@ @overload def to_timedelta( - arg: str | int | float | timedelta, + arg: str | float | timedelta, unit: UnitChoices | None = ..., errors: DateTimeErrorChoices = ..., ) -> Timedelta: diff --git a/pandas/io/formats/excel.py b/pandas/io/formats/excel.py index 3f9f6c7a5fee7..4279a9707e692 100644 --- a/pandas/io/formats/excel.py +++ b/pandas/io/formats/excel.py @@ -331,7 +331,7 @@ def build_number_format(self, props: Mapping[str, str]) -> dict[str, str | None] def build_font( self, props: Mapping[str, str] - ) -> dict[str, bool | int | float | str | None]: + ) -> dict[str, bool | float | str | None]: font_names = self._get_font_names(props) decoration = self._get_decoration(props) return { diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 57bc534bd67c4..58beba4ddcb44 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1447,7 +1447,7 @@ def __init__(self, *args, **kwargs) -> None: def _value_formatter( self, float_format: FloatFormatType | None = None, - threshold: float | int | None = None, + threshold: float | None = None, ) -> Callable: """Returns a function to be applied on each value to format it""" # the float_format parameter supersedes self.float_format @@ -2047,7 +2047,7 @@ def __init__( self.accuracy = accuracy self.use_eng_prefix = use_eng_prefix - def __call__(self, num: int | float) -> str: + def __call__(self, num: float) -> str: """ Formats a number in engineering notation, appending a letter representing the power of 1000 of the original number. Some examples: diff --git a/pandas/io/formats/info.py b/pandas/io/formats/info.py index 07ec50a2cd6a8..543df8bec657b 100644 --- a/pandas/io/formats/info.py +++ b/pandas/io/formats/info.py @@ -325,7 +325,7 @@ def _put_str(s: str | Dtype, space: int) -> str: return str(s)[:space].ljust(space) -def _sizeof_fmt(num: int | float, size_qualifier: str) -> str: +def _sizeof_fmt(num: float, size_qualifier: str) -> str: """ Return size in human readable format. diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index a557f9b5c0a0d..01b4812d3dc2a 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -3213,7 +3213,7 @@ def bar( cmap: Any | None = None, width: float = 100, height: float = 100, - align: str | float | int | Callable = "mid", + align: str | float | Callable = "mid", vmin: float | None = None, vmax: float | None = None, props: str = "width: 10em;", @@ -4039,7 +4039,7 @@ def _highlight_value(data: DataFrame | Series, op: str, props: str) -> np.ndarra def _bar( data: NDFrame, - align: str | float | int | Callable, + align: str | float | Callable, colors: str | list | tuple, cmap: Any, width: float, diff --git a/pandas/io/formats/style_render.py b/pandas/io/formats/style_render.py index 65720e675a77a..dba161cf6d45c 100644 --- a/pandas/io/formats/style_render.py +++ b/pandas/io/formats/style_render.py @@ -48,7 +48,7 @@ BaseFormatter = Union[str, Callable] ExtFormatter = Union[BaseFormatter, Dict[Any, Optional[BaseFormatter]]] -CSSPair = Tuple[str, Union[str, int, float]] +CSSPair = Tuple[str, Union[str, float]] CSSList = List[CSSPair] CSSProperties = Union[str, CSSList] @@ -2055,7 +2055,7 @@ def _parse_latex_header_span( return display_val -def _parse_latex_options_strip(value: str | int | float, arg: str) -> str: +def _parse_latex_options_strip(value: str | float, arg: str) -> str: """ Strip a css_value which may have latex wrapping arguments, css comment identifiers, and whitespaces, to a valid string for latex options parsing. diff --git a/pandas/io/parsers/readers.py b/pandas/io/parsers/readers.py index 4858d56d71c42..dc4556542d8e2 100644 --- a/pandas/io/parsers/readers.py +++ b/pandas/io/parsers/readers.py @@ -499,7 +499,7 @@ def validate_integer(name, val: None, min_val=...) -> None: @overload -def validate_integer(name, val: int | float, min_val=...) -> int: +def validate_integer(name, val: float, min_val=...) -> int: ... @@ -1910,7 +1910,7 @@ def _floatify_na_values(na_values): def _stringify_na_values(na_values): """return a stringified and numeric for these values""" - result: list[int | str | float] = [] + result: list[str | float] = [] for x in na_values: result.append(str(x)) result.append(x) diff --git a/pandas/io/stata.py b/pandas/io/stata.py index 2662df0361b55..80b6db2500d28 100644 --- a/pandas/io/stata.py +++ b/pandas/io/stata.py @@ -678,7 +678,7 @@ def __init__( self.labname = catarray.name self._encoding = encoding categories = catarray.cat.categories - self.value_labels: list[tuple[int | float, str]] = list( + self.value_labels: list[tuple[float, str]] = list( zip(np.arange(len(categories)), categories) ) self.value_labels.sort(key=lambda x: x[0]) @@ -699,7 +699,7 @@ def _prepare_value_labels(self): # Compute lengths and setup lists of offsets and labels offsets: list[int] = [] - values: list[int | float] = [] + values: list[float] = [] for vl in self.value_labels: category: str | bytes = vl[1] if not isinstance(category, str): @@ -798,7 +798,7 @@ class StataNonCatValueLabel(StataValueLabel): def __init__( self, labname: str, - value_labels: dict[float | int, str], + value_labels: dict[float, str], encoding: Literal["latin-1", "utf-8"] = "latin-1", ) -> None: @@ -807,7 +807,7 @@ def __init__( self.labname = labname self._encoding = encoding - self.value_labels: list[tuple[int | float, str]] = sorted( + self.value_labels: list[tuple[float, str]] = sorted( value_labels.items(), key=lambda x: x[0] ) self._prepare_value_labels() @@ -887,7 +887,7 @@ class StataMissingValue: "float64": struct.unpack(" None: + def __init__(self, value: float) -> None: self._value = value # Conversion to int to avoid hash issues on 32 bit platforms #8968 value = int(value) if value < 2147483648 else float(value) @@ -906,7 +906,7 @@ def string(self) -> str: return self._str @property - def value(self) -> int | float: + def value(self) -> float: """ The binary representation of the missing value. @@ -931,7 +931,7 @@ def __eq__(self, other: Any) -> bool: ) @classmethod - def get_base_missing_value(cls, dtype: np.dtype) -> int | float: + def get_base_missing_value(cls, dtype: np.dtype) -> float: if dtype.type is np.int8: value = cls.BASE_MISSING_VALUES["int8"] elif dtype.type is np.int16: @@ -1526,7 +1526,7 @@ def _read_value_labels(self) -> None: if self.format_version <= 108: # Value labels are not supported in version 108 and earlier. self._value_labels_read = True - self.value_label_dict: dict[str, dict[float | int, str]] = {} + self.value_label_dict: dict[str, dict[float, str]] = {} return if self.format_version >= 117: @@ -1886,7 +1886,7 @@ def _do_select_columns(self, data: DataFrame, columns: Sequence[str]) -> DataFra def _do_convert_categoricals( self, data: DataFrame, - value_label_dict: dict[str, dict[float | int, str]], + value_label_dict: dict[str, dict[float, str]], lbllist: Sequence[str], order_categoricals: bool, ) -> DataFrame: @@ -1977,7 +1977,7 @@ def variable_labels(self) -> dict[str, str]: """ return dict(zip(self.varlist, self._variable_labels)) - def value_labels(self) -> dict[str, dict[float | int, str]]: + def value_labels(self) -> dict[str, dict[float, str]]: """ Return a dict, associating each variable name a dict, associating each value its corresponding label. @@ -2270,7 +2270,7 @@ def __init__( compression: CompressionOptions = "infer", storage_options: StorageOptions = None, *, - value_labels: dict[Hashable, dict[float | int, str]] | None = None, + value_labels: dict[Hashable, dict[float, str]] | None = None, ) -> None: super().__init__() self.data = data @@ -3200,7 +3200,7 @@ def __init__( compression: CompressionOptions = "infer", storage_options: StorageOptions = None, *, - value_labels: dict[Hashable, dict[float | int, str]] | None = None, + value_labels: dict[Hashable, dict[float, str]] | None = None, ) -> None: # Copy to new list since convert_strl might be modified later self._convert_strl: list[Hashable] = [] @@ -3597,7 +3597,7 @@ def __init__( compression: CompressionOptions = "infer", storage_options: StorageOptions = None, *, - value_labels: dict[Hashable, dict[float | int, str]] | None = None, + value_labels: dict[Hashable, dict[float, str]] | None = None, ) -> None: if version is None: version = 118 if data.shape[1] <= 32767 else 119