diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 36ff38a849969..966fda1ed710a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -268,7 +268,7 @@ repos: |/_testing/ - id: autotyping name: autotyping - entry: python -m libcst.tool codemod autotyping.AutotypeCommand --none-return --scalar-return --annotate-magics --annotate-imprecise-magics --bool-param + entry: python -m libcst.tool codemod autotyping.AutotypeCommand --none-return --scalar-return --annotate-magics --annotate-imprecise-magics --bool-param --bytes-param --str-param --float-param types_or: [python, pyi] files: ^pandas exclude: ^(pandas/tests|pandas/_version.py|pandas/io/clipboard) diff --git a/pandas/_testing/__init__.py b/pandas/_testing/__init__.py index 92c9c28058714..e9bf19899f31e 100644 --- a/pandas/_testing/__init__.py +++ b/pandas/_testing/__init__.py @@ -25,7 +25,10 @@ set_locale, ) -from pandas._typing import Dtype +from pandas._typing import ( + Dtype, + Frequency, +) from pandas.compat import pa_version_under1p01 from pandas.core.dtypes.common import ( @@ -401,13 +404,17 @@ def makeFloatIndex(k=10, name=None) -> Float64Index: return Float64Index(base_idx) -def makeDateIndex(k: int = 10, freq="B", name=None, **kwargs) -> DatetimeIndex: +def makeDateIndex( + k: int = 10, freq: Frequency = "B", name=None, **kwargs +) -> DatetimeIndex: dt = datetime(2000, 1, 1) dr = bdate_range(dt, periods=k, freq=freq, name=name) return DatetimeIndex(dr, name=name, **kwargs) -def makeTimedeltaIndex(k: int = 10, freq="D", name=None, **kwargs) -> TimedeltaIndex: +def makeTimedeltaIndex( + k: int = 10, freq: Frequency = "D", name=None, **kwargs +) -> TimedeltaIndex: return pd.timedelta_range(start="1 day", periods=k, freq=freq, name=name, **kwargs) @@ -484,7 +491,7 @@ def getSeriesData() -> dict[str, Series]: return {c: Series(np.random.randn(_N), index=index) for c in getCols(_K)} -def makeTimeSeries(nper=None, freq="B", name=None) -> Series: +def makeTimeSeries(nper=None, freq: Frequency = "B", name=None) -> Series: if nper is None: nper = _N return Series( @@ -498,7 +505,7 @@ def makePeriodSeries(nper=None, name=None) -> Series: return Series(np.random.randn(nper), index=makePeriodIndex(nper), name=name) -def getTimeSeriesData(nper=None, freq="B") -> dict[str, Series]: +def getTimeSeriesData(nper=None, freq: Frequency = "B") -> dict[str, Series]: return {c: makeTimeSeries(nper, freq) for c in getCols(_K)} @@ -507,7 +514,7 @@ def getPeriodData(nper=None) -> dict[str, Series]: # make frame -def makeTimeDataFrame(nper=None, freq="B") -> DataFrame: +def makeTimeDataFrame(nper=None, freq: Frequency = "B") -> DataFrame: data = getTimeSeriesData(nper, freq) return DataFrame(data) @@ -542,7 +549,7 @@ def makePeriodFrame(nper=None) -> DataFrame: def makeCustomIndex( nentries, nlevels, - prefix="#", + prefix: str = "#", names: bool | str | list[str] | None = False, ndupe_l=None, idx_type=None, @@ -760,7 +767,7 @@ def makeCustomDataframe( return DataFrame(data, index, columns, dtype=dtype) -def _create_missing_idx(nrows, ncols, density, random_state=None): +def _create_missing_idx(nrows, ncols, density: float, random_state=None): if random_state is None: random_state = np.random else: @@ -787,7 +794,7 @@ def _gen_unique_rand(rng, _extra_size): return i.tolist(), j.tolist() -def makeMissingDataframe(density=0.9, random_state=None) -> DataFrame: +def makeMissingDataframe(density: float = 0.9, random_state=None) -> DataFrame: df = makeDataFrame() i, j = _create_missing_idx(*df.shape, density=density, random_state=random_state) df.values[i, j] = np.nan diff --git a/pandas/_testing/_io.py b/pandas/_testing/_io.py index ba94746b0ae6d..9ad0d13e7317e 100644 --- a/pandas/_testing/_io.py +++ b/pandas/_testing/_io.py @@ -117,7 +117,7 @@ def dec(f): @optional_args # type: ignore[misc] def network( t, - url="https://www.google.com", + url: str = "https://www.google.com", raise_on_error: bool = False, check_before_test: bool = False, error_classes=None, @@ -369,7 +369,7 @@ def round_trip_localpath(writer, reader, path: str | None = None): return obj -def write_to_compressed(compression, path, data, dest="test"): +def write_to_compressed(compression, path, data, dest: str = "test"): """ Write data to a compressed file. diff --git a/pandas/_testing/_random.py b/pandas/_testing/_random.py index 81f3b33d266ee..218816308f95d 100644 --- a/pandas/_testing/_random.py +++ b/pandas/_testing/_random.py @@ -2,6 +2,8 @@ import numpy as np +from pandas._typing import NpDtype + def randbool(size=(), p: float = 0.5): return np.random.rand(*size) <= p @@ -14,7 +16,7 @@ def randbool(size=(), p: float = 0.5): ) -def rands_array(nchars, size, dtype="O", replace: bool = True) -> np.ndarray: +def rands_array(nchars, size, dtype: NpDtype = "O", replace: bool = True) -> np.ndarray: """ Generate an array of byte strings. """ diff --git a/pandas/_testing/asserters.py b/pandas/_testing/asserters.py index f05bcc74e6c5d..db850ffdc4e1f 100644 --- a/pandas/_testing/asserters.py +++ b/pandas/_testing/asserters.py @@ -311,7 +311,7 @@ def assert_index_equal( """ __tracebackhide__ = True - def _check_types(left, right, obj="Index") -> None: + def _check_types(left, right, obj: str = "Index") -> None: if not exact: return @@ -429,7 +429,9 @@ def _get_ilevel_values(index, level): assert_categorical_equal(left._values, right._values, obj=f"{obj} category") -def assert_class_equal(left, right, exact: bool | str = True, obj="Input") -> None: +def assert_class_equal( + left, right, exact: bool | str = True, obj: str = "Input" +) -> None: """ Checks classes are equal. """ @@ -527,7 +529,7 @@ def assert_categorical_equal( right, check_dtype: bool = True, check_category_order: bool = True, - obj="Categorical", + obj: str = "Categorical", ) -> None: """ Test that Categoricals are equivalent. @@ -584,7 +586,7 @@ def assert_categorical_equal( def assert_interval_array_equal( - left, right, exact="equiv", obj="IntervalArray" + left, right, exact: bool | Literal["equiv"] = "equiv", obj: str = "IntervalArray" ) -> None: """ Test that two IntervalArrays are equivalent. @@ -614,7 +616,7 @@ def assert_interval_array_equal( assert_attr_equal("closed", left, right, obj=obj) -def assert_period_array_equal(left, right, obj="PeriodArray") -> None: +def assert_period_array_equal(left, right, obj: str = "PeriodArray") -> None: _check_isinstance(left, right, PeriodArray) assert_numpy_array_equal(left._data, right._data, obj=f"{obj}._data") @@ -622,7 +624,7 @@ def assert_period_array_equal(left, right, obj="PeriodArray") -> None: def assert_datetime_array_equal( - left, right, obj="DatetimeArray", check_freq: bool = True + left, right, obj: str = "DatetimeArray", check_freq: bool = True ) -> None: __tracebackhide__ = True _check_isinstance(left, right, DatetimeArray) @@ -634,7 +636,7 @@ def assert_datetime_array_equal( def assert_timedelta_array_equal( - left, right, obj="TimedeltaArray", check_freq: bool = True + left, right, obj: str = "TimedeltaArray", check_freq: bool = True ) -> None: __tracebackhide__ = True _check_isinstance(left, right, TimedeltaArray) @@ -693,7 +695,7 @@ def assert_numpy_array_equal( check_dtype: bool | Literal["equiv"] = True, err_msg=None, check_same=None, - obj="numpy array", + obj: str = "numpy array", index_values=None, ) -> None: """ @@ -887,7 +889,7 @@ def assert_series_equal( check_flags: bool = True, rtol: float = 1.0e-5, atol: float = 1.0e-8, - obj="Series", + obj: str = "Series", *, check_index: bool = True, check_like: bool = False, @@ -1157,7 +1159,7 @@ def assert_frame_equal( check_flags: bool = True, rtol: float = 1.0e-5, atol: float = 1.0e-8, - obj="DataFrame", + obj: str = "DataFrame", ) -> None: """ Check that left and right DataFrame are equal. diff --git a/pandas/_typing.py b/pandas/_typing.py index c7d82be4e24a1..af037ff0473e3 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -332,3 +332,17 @@ def closed(self) -> bool: # dropna AnyAll = Literal["any", "all"] + +MatplotlibColor = Union[str, Sequence[float]] +TimeGrouperOrigin = Union[ + "Timestamp", Literal["epoch", "start", "start_day", "end", "end_day"] +] +TimeAmbiguous = Union[Literal["infer", "NaT", "raise"], "npt.NDArray[np.bool_]"] +TimeNonexistent = Union[ + Literal["shift_forward", "shift_backward", "NaT", "raise"], timedelta +] +DropKeep = Literal["first", "last", False] +CorrelationMethod = Union[ + Literal["pearson", "kendall", "spearman"], Callable[[np.ndarray, np.ndarray], float] +] +AlignJoin = Literal["outer", "inner", "left", "right"] diff --git a/pandas/core/arrays/arrow/array.py b/pandas/core/arrays/arrow/array.py index 9ac77a7d48604..03f734730a0f9 100644 --- a/pandas/core/arrays/arrow/array.py +++ b/pandas/core/arrays/arrow/array.py @@ -12,6 +12,7 @@ from pandas._typing import ( Dtype, PositionalIndexer, + SortKind, TakeIndexer, npt, ) @@ -472,7 +473,7 @@ def isna(self) -> npt.NDArray[np.bool_]: def argsort( self, ascending: bool = True, - kind: str = "quicksort", + kind: SortKind = "quicksort", na_position: str = "last", *args, **kwargs, diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index efce69439ea43..77dfc82e640f2 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -37,6 +37,7 @@ ScalarIndexer, SequenceIndexer, Shape, + SortKind, TakeIndexer, npt, ) @@ -671,7 +672,7 @@ def _values_for_argsort(self) -> np.ndarray: def argsort( self, ascending: bool = True, - kind: str = "quicksort", + kind: SortKind = "quicksort", na_position: str = "last", *args, **kwargs, diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index f2dace75906ad..ee995a0f9d0b7 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -44,6 +44,7 @@ NpDtype, Ordered, Shape, + SortKind, npt, type_t, ) @@ -1827,7 +1828,7 @@ def check_for_ordered(self, op) -> None: # error: Signature of "argsort" incompatible with supertype "ExtensionArray" @deprecate_nonkeyword_arguments(version=None, allowed_args=["self"]) def argsort( # type: ignore[override] - self, ascending: bool = True, kind="quicksort", **kwargs + self, ascending: bool = True, kind: SortKind = "quicksort", **kwargs ): """ Return the indices that would sort the Categorical. @@ -2200,7 +2201,9 @@ def _repr_footer(self) -> str: info = self._repr_categories_info() return f"Length: {len(self)}\n{info}" - def _get_repr(self, length: bool = True, na_rep="NaN", footer: bool = True) -> str: + def _get_repr( + self, length: bool = True, na_rep: str = "NaN", footer: bool = True + ) -> str: from pandas.io.formats import format as fmt formatter = fmt.CategoricalFormatter( @@ -2716,7 +2719,7 @@ def _str_map( result = PandasArray(categories.to_numpy())._str_map(f, na_value, dtype) return take_nd(result, codes, fill_value=na_value) - def _str_get_dummies(self, sep="|"): + def _str_get_dummies(self, sep: str = "|"): # sep may not be in categories. Just bail on this. from pandas.core.arrays import PandasArray diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index d28b9aeeb41d0..5a92cc3c8509c 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -63,6 +63,8 @@ PositionalIndexerTuple, ScalarIndexer, SequenceIndexer, + TimeAmbiguous, + TimeNonexistent, npt, ) from pandas.compat.numpy import function as nv @@ -308,7 +310,7 @@ def asi8(self) -> npt.NDArray[np.int64]: # Rendering Methods def _format_native_types( - self, *, na_rep="NaT", date_format=None + self, *, na_rep: str | float = "NaT", date_format=None ) -> npt.NDArray[np.object_]: """ Helper method for astype when converting to strings. @@ -556,7 +558,7 @@ def _concat_same_type( new_obj._freq = new_freq return new_obj - def copy(self: DatetimeLikeArrayT, order="C") -> DatetimeLikeArrayT: + def copy(self: DatetimeLikeArrayT, order: str = "C") -> DatetimeLikeArrayT: # error: Unexpected keyword argument "order" for "copy" new_obj = super().copy(order=order) # type: ignore[call-arg] new_obj._freq = self.freq @@ -2085,15 +2087,30 @@ def _round(self, freq, mode, ambiguous, nonexistent): return self._simple_new(result, dtype=self.dtype) @Appender((_round_doc + _round_example).format(op="round")) - def round(self, freq, ambiguous="raise", nonexistent="raise"): + def round( + self, + freq, + ambiguous: TimeAmbiguous = "raise", + nonexistent: TimeNonexistent = "raise", + ): return self._round(freq, RoundTo.NEAREST_HALF_EVEN, ambiguous, nonexistent) @Appender((_round_doc + _floor_example).format(op="floor")) - def floor(self, freq, ambiguous="raise", nonexistent="raise"): + def floor( + self, + freq, + ambiguous: TimeAmbiguous = "raise", + nonexistent: TimeNonexistent = "raise", + ): return self._round(freq, RoundTo.MINUS_INFTY, ambiguous, nonexistent) @Appender((_round_doc + _ceil_example).format(op="ceil")) - def ceil(self, freq, ambiguous="raise", nonexistent="raise"): + def ceil( + self, + freq, + ambiguous: TimeAmbiguous = "raise", + nonexistent: TimeNonexistent = "raise", + ): return self._round(freq, RoundTo.PLUS_INFTY, ambiguous, nonexistent) # -------------------------------------------------------------- diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 017ff5abdbe77..a9c1a7e3cdab0 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -41,7 +41,13 @@ tz_convert_from_utc, tzconversion, ) -from pandas._typing import npt +from pandas._typing import ( + DateTimeErrorChoices, + IntervalClosedType, + TimeAmbiguous, + TimeNonexistent, + npt, +) from pandas.errors import ( OutOfBoundsDatetime, PerformanceWarning, @@ -298,7 +304,7 @@ def _from_sequence_not_strict( freq: str | BaseOffset | lib.NoDefault | None = lib.no_default, dayfirst: bool = False, yearfirst: bool = False, - ambiguous="raise", + ambiguous: TimeAmbiguous = "raise", ): explicit_none = freq is None freq = freq if freq is not lib.no_default else None @@ -344,9 +350,9 @@ def _generate_range( # type: ignore[override] freq, tz=None, normalize: bool = False, - ambiguous="raise", - nonexistent="raise", - inclusive="both", + ambiguous: TimeAmbiguous = "raise", + nonexistent: TimeNonexistent = "raise", + inclusive: IntervalClosedType = "both", ) -> DatetimeArray: periods = dtl.validate_periods(periods) @@ -658,7 +664,7 @@ def astype(self, dtype, copy: bool = True): # Rendering Methods def _format_native_types( - self, *, na_rep="NaT", date_format=None, **kwargs + self, *, na_rep: str | float = "NaT", date_format=None, **kwargs ) -> npt.NDArray[np.object_]: from pandas.io.formats.format import get_format_datetime64_from_values @@ -830,7 +836,12 @@ def tz_convert(self, tz) -> DatetimeArray: return self._simple_new(self._ndarray, dtype=dtype, freq=self.freq) @dtl.ravel_compat - def tz_localize(self, tz, ambiguous="raise", nonexistent="raise") -> DatetimeArray: + def tz_localize( + self, + tz, + ambiguous: TimeAmbiguous = "raise", + nonexistent: TimeNonexistent = "raise", + ) -> DatetimeArray: """ Localize tz-naive Datetime Array/Index to tz-aware Datetime Array/Index. @@ -1989,7 +2000,7 @@ def _sequence_to_dt64ns( tz=lib.no_default, dayfirst: bool = False, yearfirst: bool = False, - ambiguous="raise", + ambiguous: TimeAmbiguous = "raise", *, allow_mixed: bool = False, require_iso8601: bool = False, @@ -2144,7 +2155,7 @@ def objects_to_datetime64ns( dayfirst, yearfirst, utc: bool = False, - errors="raise", + errors: DateTimeErrorChoices = "raise", require_iso8601: bool = False, allow_object: bool = False, allow_mixed: bool = False, diff --git a/pandas/core/arrays/interval.py b/pandas/core/arrays/interval.py index 57ef236eb6d5f..f2afc4762e6a8 100644 --- a/pandas/core/arrays/interval.py +++ b/pandas/core/arrays/interval.py @@ -38,6 +38,7 @@ PositionalIndexer, ScalarIndexer, SequenceIndexer, + SortKind, npt, ) from pandas.compat.numpy import function as nv @@ -564,7 +565,7 @@ def from_arrays( def from_tuples( cls: type[IntervalArrayT], data, - closed="right", + closed: IntervalClosedType | None = "right", copy: bool = False, dtype: Dtype | None = None, ) -> IntervalArrayT: @@ -799,7 +800,7 @@ def __le__(self, other): def argsort( self, ascending: bool = True, - kind: str = "quicksort", + kind: SortKind = "quicksort", na_position: str = "last", *args, **kwargs, diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index 91eeee936cba1..c0d476c2452b8 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -642,7 +642,7 @@ def _formatter(self, boxed: bool = False): @dtl.ravel_compat def _format_native_types( - self, *, na_rep="NaT", date_format=None, **kwargs + self, *, na_rep: str | float = "NaT", date_format=None, **kwargs ) -> npt.NDArray[np.object_]: """ actually format my specific types diff --git a/pandas/core/arrays/timedeltas.py b/pandas/core/arrays/timedeltas.py index 06ea661aca6c9..75e4ab6b37bf7 100644 --- a/pandas/core/arrays/timedeltas.py +++ b/pandas/core/arrays/timedeltas.py @@ -33,6 +33,7 @@ ) from pandas._typing import ( AxisInt, + DateTimeErrorChoices, DtypeObj, NpDtype, npt, @@ -373,7 +374,7 @@ def _formatter(self, boxed: bool = False): return get_format_timedelta64(self, box=True) def _format_native_types( - self, *, na_rep="NaT", date_format=None, **kwargs + self, *, na_rep: str | float = "NaT", date_format=None, **kwargs ) -> npt.NDArray[np.object_]: from pandas.io.formats.format import get_format_timedelta64 @@ -846,7 +847,10 @@ def f(x): def sequence_to_td64ns( - data, copy: bool = False, unit=None, errors="raise" + data, + copy: bool = False, + unit=None, + errors: DateTimeErrorChoices = "raise", ) -> tuple[np.ndarray, Tick | None]: """ Parameters @@ -932,7 +936,7 @@ def sequence_to_td64ns( return data, inferred_freq -def ints_to_td64ns(data, unit="ns"): +def ints_to_td64ns(data, unit: str = "ns"): """ Convert an ndarray with integer-dtype to timedelta64[ns] dtype, treating the integers as multiples of the given timedelta unit. @@ -972,7 +976,7 @@ def ints_to_td64ns(data, unit="ns"): return data, copy_made -def _objects_to_td64ns(data, unit=None, errors="raise"): +def _objects_to_td64ns(data, unit=None, errors: DateTimeErrorChoices = "raise"): """ Convert a object-dtyped or string-dtyped array into an timedelta64[ns]-dtyped array. diff --git a/pandas/core/base.py b/pandas/core/base.py index 7f8db4182c71d..a1ca8b59dcffa 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -80,6 +80,7 @@ if TYPE_CHECKING: from pandas._typing import ( + DropKeep, NumpySorter, NumpyValueArrayLike, ) @@ -1308,15 +1309,13 @@ def searchsorted( sorter=sorter, ) - def drop_duplicates(self, keep="first"): + def drop_duplicates(self, keep: DropKeep = "first"): duplicated = self._duplicated(keep=keep) # error: Value of type "IndexOpsMixin" is not indexable return self[~duplicated] # type: ignore[index] @final - def _duplicated( - self, keep: Literal["first", "last", False] = "first" - ) -> npt.NDArray[np.bool_]: + def _duplicated(self, keep: DropKeep = "first") -> npt.NDArray[np.bool_]: return duplicated(self._values, keep=keep) def _arith_method(self, other, op): diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 0ec4caaabb6b5..7064848233581 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -50,6 +50,7 @@ ) from pandas._typing import ( AggFuncType, + AlignJoin, AnyAll, AnyArrayLike, ArrayLike, @@ -58,6 +59,8 @@ AxisInt, ColspaceArgType, CompressionOptions, + CorrelationMethod, + DropKeep, Dtype, DtypeObj, FilePath, @@ -5084,7 +5087,7 @@ def _reindex_multi( def align( self, other: DataFrame, - join: Literal["outer", "inner", "left", "right"] = "outer", + join: AlignJoin = "outer", axis: Axis | None = None, level: Level = None, copy: bool = True, @@ -6594,7 +6597,7 @@ def dropna( def drop_duplicates( self, subset: Hashable | Sequence[Hashable] | None = None, - keep: Literal["first", "last", False] = "first", + keep: DropKeep = "first", inplace: bool = False, ignore_index: bool = False, ) -> DataFrame | None: @@ -6693,7 +6696,7 @@ def drop_duplicates( def duplicated( self, subset: Hashable | Sequence[Hashable] | None = None, - keep: Literal["first", "last", False] = "first", + keep: DropKeep = "first", ) -> Series: """ Return boolean Series denoting duplicate rows. @@ -8727,11 +8730,11 @@ def pivot_table( values=None, index=None, columns=None, - aggfunc="mean", + aggfunc: AggFuncType = "mean", fill_value=None, margins: bool = False, dropna: bool = True, - margins_name="All", + margins_name: Level = "All", observed: bool = False, sort: bool = True, ) -> DataFrame: @@ -9128,7 +9131,7 @@ def melt( id_vars=None, value_vars=None, var_name=None, - value_name="value", + value_name: Hashable = "value", col_level: Level = None, ignore_index: bool = True, ) -> DataFrame: @@ -10242,7 +10245,7 @@ def _series_round(ser: Series, decimals: int): def corr( self, - method: str | Callable[[np.ndarray, np.ndarray], float] = "pearson", + method: CorrelationMethod = "pearson", min_periods: int = 1, numeric_only: bool | lib.NoDefault = lib.no_default, ) -> DataFrame: @@ -10500,8 +10503,7 @@ def corrwith( other: DataFrame | Series, axis: Axis = 0, drop: bool = False, - method: Literal["pearson", "kendall", "spearman"] - | Callable[[np.ndarray, np.ndarray], float] = "pearson", + method: CorrelationMethod = "pearson", numeric_only: bool | lib.NoDefault = lib.no_default, ) -> Series: """ diff --git a/pandas/core/generic.py b/pandas/core/generic.py index f023e5b6adf04..b520aab2cfa5b 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -41,6 +41,7 @@ to_offset, ) from pandas._typing import ( + AlignJoin, AnyArrayLike, ArrayLike, Axis, @@ -70,7 +71,9 @@ StorageOptions, Suffixes, T, + TimeAmbiguous, TimedeltaConvertibleTypes, + TimeNonexistent, TimestampConvertibleTypes, ValueKeyFunc, WriteBuffer, @@ -2823,7 +2826,7 @@ def to_sql( name: str, con, schema: str | None = None, - if_exists: str = "fail", + if_exists: Literal["fail", "replace", "append"] = "fail", index: bool_t = True, index_label: IndexLabel = None, chunksize: int | None = None, @@ -4140,7 +4143,7 @@ def _check_is_chained_assignment_possible(self) -> bool_t: return False @final - def _check_setitem_copy(self, t="setting", force: bool_t = False): + def _check_setitem_copy(self, t: str = "setting", force: bool_t = False): """ Parameters @@ -4331,7 +4334,7 @@ def _is_view(self) -> bool_t: def reindex_like( self: NDFrameT, other, - method: str | None = None, + method: Literal["backfill", "bfill", "pad", "ffill", "nearest"] | None = None, copy: bool_t = True, limit=None, tolerance=None, @@ -9312,7 +9315,7 @@ def compare( def align( self: NDFrameT, other: NDFrameT, - join: Literal["outer", "inner", "left", "right"] = "outer", + join: AlignJoin = "outer", axis: Axis | None = None, level: Level = None, copy: bool_t = True, @@ -9505,7 +9508,7 @@ def align( def _align_frame( self, other, - join="outer", + join: AlignJoin = "outer", axis: Axis | None = None, level=None, copy: bool_t = True, @@ -9569,7 +9572,7 @@ def _align_frame( def _align_series( self, other, - join="outer", + join: AlignJoin = "outer", axis: Axis | None = None, level=None, copy: bool_t = True, @@ -10567,8 +10570,8 @@ def tz_localize( axis=0, level=None, copy: bool_t = True, - ambiguous="raise", - nonexistent: str = "raise", + ambiguous: TimeAmbiguous = "raise", + nonexistent: TimeNonexistent = "raise", ) -> NDFrameT: """ Localize tz-naive index of a Series or DataFrame to target time zone. @@ -10993,7 +10996,7 @@ def describe( def pct_change( self: NDFrameT, periods=1, - fill_method="pad", + fill_method: Literal["backfill", "bfill", "pad", "ffill"] = "pad", limit=None, freq=None, **kwargs, diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 6a2070eb4f46f..4e17276a4eb1b 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -38,6 +38,7 @@ ArrayLike, Axis, AxisInt, + CorrelationMethod, FillnaOptions, IndexLabel, Level, @@ -857,8 +858,7 @@ def idxmax(self, axis: Axis = 0, skipna: bool = True) -> Series: def corr( self, other: Series, - method: Literal["pearson", "kendall", "spearman"] - | Callable[[np.ndarray, np.ndarray], float] = "pearson", + method: CorrelationMethod = "pearson", min_periods: int | None = None, ) -> Series: result = self._op_via_apply( @@ -2220,8 +2220,7 @@ def corrwith( other: DataFrame | Series, axis: Axis = 0, drop: bool = False, - method: Literal["pearson", "kendall", "spearman"] - | Callable[[np.ndarray, np.ndarray], float] = "pearson", + method: CorrelationMethod = "pearson", numeric_only: bool | lib.NoDefault = lib.no_default, ) -> DataFrame: result = self._op_via_apply( diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 3e7fc1458c188..d5151d84e20bb 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -44,9 +44,11 @@ class providing the base-class of operations. ) import pandas._libs.groupby as libgroupby from pandas._typing import ( + AnyArrayLike, ArrayLike, AxisInt, Dtype, + FillnaOptions, IndexLabel, NDFrameT, PositionalIndexer, @@ -3215,7 +3217,7 @@ def nth( @final def quantile( self, - q=0.5, + q: float | AnyArrayLike = 0.5, interpolation: str = "linear", numeric_only: bool | lib.NoDefault = lib.no_default, ): @@ -3336,7 +3338,11 @@ def post_processor( orig_scalar = is_scalar(q) if orig_scalar: - q = [q] + # error: Incompatible types in assignment (expression has type "List[ + # Union[float, ExtensionArray, ndarray[Any, Any], Index, Series]]", + # variable has type "Union[float, Union[Union[ExtensionArray, ndarray[ + # Any, Any]], Index, Series]]") + q = [q] # type: ignore[assignment] qs = np.array(q, dtype=np.float64) ids, _, ngroups = self.grouper.group_info @@ -3991,7 +3997,14 @@ def diff(self, periods: int = 1, axis: AxisInt = 0) -> NDFrameT: @final @Substitution(name="groupby") @Appender(_common_see_also) - def pct_change(self, periods=1, fill_method="ffill", limit=None, freq=None, axis=0): + def pct_change( + self, + periods=1, + fill_method: FillnaOptions = "ffill", + limit=None, + freq=None, + axis=0, + ): """ Calculate pct_change of each value to previous entry in group. diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 6a7f08d38024b..aaa840ef19650 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -50,6 +50,7 @@ ArrayLike, Axes, AxisInt, + DropKeep, Dtype, DtypeObj, F, @@ -1001,7 +1002,7 @@ def dtype(self) -> DtypeObj: return self._data.dtype @final - def ravel(self, order="C"): + def ravel(self, order: str_t = "C"): """ Return an ndarray of the flattened values of the underlying data. @@ -1538,7 +1539,7 @@ def to_native_types(self, slicer=None, **kwargs) -> np.ndarray: return values._format_native_types(**kwargs) def _format_native_types( - self, *, na_rep="", quoting=None, **kwargs + self, *, na_rep: str_t = "", quoting=None, **kwargs ) -> npt.NDArray[np.object_]: """ Actually format specific types of the index. @@ -3067,7 +3068,7 @@ def unique(self: _IndexT, level: Hashable | None = None) -> _IndexT: return self._shallow_copy(result) @deprecate_nonkeyword_arguments(version=None, allowed_args=["self"]) - def drop_duplicates(self: _IndexT, keep: str_t | bool = "first") -> _IndexT: + def drop_duplicates(self: _IndexT, keep: DropKeep = "first") -> _IndexT: """ Return Index with duplicate values removed. @@ -3118,9 +3119,7 @@ def drop_duplicates(self: _IndexT, keep: str_t | bool = "first") -> _IndexT: return super().drop_duplicates(keep=keep) - def duplicated( - self, keep: Literal["first", "last", False] = "first" - ) -> npt.NDArray[np.bool_]: + def duplicated(self, keep: DropKeep = "first") -> npt.NDArray[np.bool_]: """ Indicate duplicate index values. diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 8a3b9b410cb16..bccbc2f861bdd 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -26,7 +26,6 @@ lib, ) from pandas._libs.tslibs import ( - BaseOffset, Resolution, periods_per_day, timezones, @@ -37,8 +36,11 @@ from pandas._typing import ( Dtype, DtypeObj, + Frequency, IntervalClosedType, IntervalLeftRight, + TimeAmbiguous, + TimeNonexistent, npt, ) from pandas.util._decorators import ( @@ -278,7 +280,12 @@ def tz_convert(self, tz) -> DatetimeIndex: return type(self)._simple_new(arr, name=self.name) @doc(DatetimeArray.tz_localize) - def tz_localize(self, tz, ambiguous="raise", nonexistent="raise") -> DatetimeIndex: + def tz_localize( + self, + tz, + ambiguous: TimeAmbiguous = "raise", + nonexistent: TimeNonexistent = "raise", + ) -> DatetimeIndex: arr = self._data.tz_localize(tz, ambiguous, nonexistent) return type(self)._simple_new(arr, name=self.name) @@ -314,11 +321,11 @@ def isocalendar(self) -> DataFrame: def __new__( cls, data=None, - freq: str | BaseOffset | lib.NoDefault = lib.no_default, + freq: Frequency | lib.NoDefault = lib.no_default, tz=lib.no_default, normalize: bool = False, closed=None, - ambiguous="raise", + ambiguous: TimeAmbiguous = "raise", dayfirst: bool = False, yearfirst: bool = False, dtype: Dtype | None = None, @@ -590,7 +597,7 @@ def to_series(self, keep_tz=lib.no_default, index=None, name=None): return Series(values, index=index, name=name) - def snap(self, freq="S") -> DatetimeIndex: + def snap(self, freq: Frequency = "S") -> DatetimeIndex: """ Snap time stamps to nearest occurring frequency. @@ -1142,7 +1149,7 @@ def bdate_range( start=None, end=None, periods: int | None = None, - freq="B", + freq: Frequency = "B", tz=None, normalize: bool = True, name: Hashable = None, diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index 0076edb04f665..c8cb2cfa28640 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -311,7 +311,7 @@ def from_arrays( def from_tuples( cls, data, - closed: str = "right", + closed: IntervalClosedType = "right", name: Hashable = None, copy: bool = False, dtype: Dtype | None = None, @@ -823,7 +823,7 @@ def _format_with_header(self, header: list[str], na_rep: str) -> list[str]: return header + list(self._format_native_types(na_rep=na_rep)) def _format_native_types( - self, *, na_rep="NaN", quoting=None, **kwargs + self, *, na_rep: str = "NaN", quoting=None, **kwargs ) -> npt.NDArray[np.object_]: # GH 28210: use base method but with different default na_rep return super()._format_native_types(na_rep=na_rep, quoting=quoting, **kwargs) diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 06021dfa93325..6e795bc4d13be 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -33,8 +33,10 @@ AnyAll, AnyArrayLike, AxisInt, + DropKeep, DtypeObj, F, + IgnoreRaise, Scalar, Shape, npt, @@ -1328,7 +1330,7 @@ def _formatter_func(self, tup): return tuple(func(val) for func, val in zip(formatter_funcs, tup)) def _format_native_types( - self, *, na_rep="nan", **kwargs + self, *, na_rep: str = "nan", **kwargs ) -> npt.NDArray[np.object_]: new_levels = [] new_codes = [] @@ -1626,7 +1628,7 @@ def _inferred_type_levels(self) -> list[str]: return [i.inferred_type for i in self.levels] @doc(Index.duplicated) - def duplicated(self, keep="first") -> npt.NDArray[np.bool_]: + def duplicated(self, keep: DropKeep = "first") -> npt.NDArray[np.bool_]: shape = tuple(len(lev) for lev in self.levels) ids = get_group_index(self.codes, shape, sort=False, xnull=False) @@ -2256,7 +2258,13 @@ def repeat(self, repeats: int, axis=None) -> MultiIndex: verify_integrity=False, ) - def drop(self, codes, level=None, errors="raise"): + # error: Signature of "drop" incompatible with supertype "Index" + def drop( # type: ignore[override] + self, + codes, + level: Index | np.ndarray | Iterable[Hashable] | None = None, + errors: IgnoreRaise = "raise", + ) -> MultiIndex: """ Make new MultiIndex with passed list of codes deleted @@ -2310,7 +2318,9 @@ def drop(self, codes, level=None, errors="raise"): return self.delete(inds) - def _drop_from_level(self, codes, level, errors="raise") -> MultiIndex: + def _drop_from_level( + self, codes, level, errors: IgnoreRaise = "raise" + ) -> MultiIndex: codes = com.index_labels_to_array(codes) i = self._get_level_number(level) index = self.levels[i] @@ -3917,7 +3927,7 @@ def _lexsort_depth(codes: list[np.ndarray], nlevels: int) -> int: return 0 -def sparsify_labels(label_list, start: int = 0, sentinel=""): +def sparsify_labels(label_list, start: int = 0, sentinel: object = ""): pivoted = list(zip(*label_list)) k = len(label_list) diff --git a/pandas/core/indexes/numeric.py b/pandas/core/indexes/numeric.py index 6dc100dde67a0..7838600f626de 100644 --- a/pandas/core/indexes/numeric.py +++ b/pandas/core/indexes/numeric.py @@ -281,7 +281,13 @@ def _assert_safe_casting(cls, data: np.ndarray, subarr: np.ndarray) -> None: raise TypeError("Unsafe NumPy casting, you must explicitly cast") def _format_native_types( - self, *, na_rep="", float_format=None, decimal=".", quoting=None, **kwargs + self, + *, + na_rep: str = "", + float_format=None, + decimal: str = ".", + quoting=None, + **kwargs, ) -> npt.NDArray[np.object_]: from pandas.io.formats.format import FloatArrayFormatter diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 37d211d4d3cf0..60b687167a7a3 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -1660,7 +1660,7 @@ def _get_setitem_indexer(self, key): # ------------------------------------------------------------------- - def _setitem_with_indexer(self, indexer, value, name="iloc"): + def _setitem_with_indexer(self, indexer, value, name: str = "iloc"): """ _setitem_with_indexer is for setting values on a Series/DataFrame using positional indexers. diff --git a/pandas/core/internals/array_manager.py b/pandas/core/internals/array_manager.py index d2c626a9cf247..4aa16257b0802 100644 --- a/pandas/core/internals/array_manager.py +++ b/pandas/core/internals/array_manager.py @@ -23,6 +23,7 @@ ArrayLike, AxisInt, DtypeObj, + QuantileInterpolation, npt, ) from pandas.util._validators import validate_bool_kwarg @@ -1057,7 +1058,7 @@ def quantile( qs: Float64Index, axis: AxisInt = 0, transposed: bool = False, - interpolation="linear", + interpolation: QuantileInterpolation = "linear", ) -> ArrayManager: arrs = [ensure_block_shape(x, 2) for x in self.arrays] diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 432431c89b334..62d8d7e504b4a 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -31,6 +31,7 @@ F, FillnaOptions, IgnoreRaise, + QuantileInterpolation, Shape, npt, ) @@ -539,7 +540,7 @@ def astype( return newb @final - def to_native_types(self, na_rep="nan", quoting=None, **kwargs) -> Block: + def to_native_types(self, na_rep: str = "nan", quoting=None, **kwargs) -> Block: """convert to our native types format""" result = to_native_types(self.values, na_rep=na_rep, quoting=quoting, **kwargs) return self.make_block(result) @@ -1055,7 +1056,7 @@ def putmask(self, mask, new) -> list[Block]: res_blocks.extend(rbs) return res_blocks - def where(self, other, cond, _downcast="infer") -> list[Block]: + def where(self, other, cond, _downcast: str | bool = "infer") -> list[Block]: """ evaluate the block; return result block(s) from the result @@ -1214,7 +1215,7 @@ def fillna( def interpolate( self, - method: str = "pad", + method: FillnaOptions = "pad", axis: AxisInt = 0, index: Index | None = None, inplace: bool = False, @@ -1318,7 +1319,10 @@ def shift( @final def quantile( - self, qs: Float64Index, interpolation="linear", axis: AxisInt = 0 + self, + qs: Float64Index, + interpolation: QuantileInterpolation = "linear", + axis: AxisInt = 0, ) -> Block: """ compute the quantiles of the @@ -1442,7 +1446,7 @@ def setitem(self, indexer, value): else: return self - def where(self, other, cond, _downcast="infer") -> list[Block]: + def where(self, other, cond, _downcast: str | bool = "infer") -> list[Block]: # _downcast private bc we only specify it when calling from fillna arr = self.values.T @@ -2267,10 +2271,10 @@ def ensure_block_shape(values: ArrayLike, ndim: int = 1) -> ArrayLike: def to_native_types( values: ArrayLike, *, - na_rep="nan", + na_rep: str = "nan", quoting=None, float_format=None, - decimal=".", + decimal: str = ".", **kwargs, ) -> np.ndarray: """convert to our native types format""" diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index c6762b72f82d7..5a398533e1510 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -28,6 +28,7 @@ ArrayLike, AxisInt, DtypeObj, + QuantileInterpolation, Shape, npt, type_t, @@ -1582,7 +1583,7 @@ def quantile( *, qs: Float64Index, axis: AxisInt = 0, - interpolation="linear", + interpolation: QuantileInterpolation = "linear", ) -> T: """ Iterate over blocks applying quantile reduction. diff --git a/pandas/core/missing.py b/pandas/core/missing.py index 242ee43b32393..9a55076c71f5f 100644 --- a/pandas/core/missing.py +++ b/pandas/core/missing.py @@ -629,7 +629,9 @@ def _akima_interpolate(xi, yi, x, der=0, axis=0): return P(x, nu=der) -def _cubicspline_interpolate(xi, yi, x, axis=0, bc_type="not-a-knot", extrapolate=None): +def _cubicspline_interpolate( + xi, yi, x, axis=0, bc_type: str | tuple[Any, Any] = "not-a-knot", extrapolate=None +): """ Convenience function for cubic spline data interpolator. diff --git a/pandas/core/nanops.py b/pandas/core/nanops.py index e61970b1d7dcb..8e162a8249fd9 100644 --- a/pandas/core/nanops.py +++ b/pandas/core/nanops.py @@ -23,6 +23,7 @@ from pandas._typing import ( ArrayLike, AxisInt, + CorrelationMethod, Dtype, DtypeObj, F, @@ -1536,7 +1537,11 @@ def _zero_out_fperr(arg): @disallow("M8", "m8") def nancorr( - a: np.ndarray, b: np.ndarray, *, method="pearson", min_periods: int | None = None + a: np.ndarray, + b: np.ndarray, + *, + method: CorrelationMethod = "pearson", + min_periods: int | None = None, ) -> float: """ a, b: ndarrays @@ -1559,7 +1564,9 @@ def nancorr( return f(a, b) -def get_corr_func(method) -> Callable[[np.ndarray, np.ndarray], float]: +def get_corr_func( + method: CorrelationMethod, +) -> Callable[[np.ndarray, np.ndarray], float]: if method == "kendall": from scipy.stats import kendalltau diff --git a/pandas/core/resample.py b/pandas/core/resample.py index 827dde886a216..0e0aa9e272c89 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -27,11 +27,15 @@ to_offset, ) from pandas._typing import ( + AnyArrayLike, AxisInt, + Frequency, IndexLabel, NDFrameT, + QuantileInterpolation, T, TimedeltaConvertibleTypes, + TimeGrouperOrigin, TimestampConvertibleTypes, npt, ) @@ -921,11 +925,11 @@ def fillna(self, method, limit=None): @doc(NDFrame.interpolate, **_shared_docs_kwargs) def interpolate( self, - method="linear", + method: QuantileInterpolation = "linear", axis=0, limit=None, inplace: bool = False, - limit_direction="forward", + limit_direction: Literal["forward", "backward", "both"] = "forward", limit_area=None, downcast=None, **kwargs, @@ -1052,7 +1056,7 @@ def count(self): return result - def quantile(self, q=0.5, **kwargs): + def quantile(self, q: float | AnyArrayLike = 0.5, **kwargs): """ Return value at the given quantile. @@ -1585,12 +1589,14 @@ class TimeGrouper(Grouper): "offset", ) + origin: TimeGrouperOrigin + def __init__( self, - freq="Min", + freq: Frequency = "Min", closed: Literal["left", "right"] | None = None, label: Literal["left", "right"] | None = None, - how="mean", + how: str = "mean", axis=0, fill_method=None, limit=None, @@ -1598,7 +1604,8 @@ def __init__( kind: str | None = None, convention: Literal["start", "end", "e", "s"] | None = None, base: int | None = None, - origin: str | TimestampConvertibleTypes = "start_day", + origin: Literal["epoch", "start", "start_day", "end", "end_day"] + | TimestampConvertibleTypes = "start_day", offset: TimedeltaConvertibleTypes | None = None, group_keys: bool | lib.NoDefault = True, **kwargs, @@ -1649,7 +1656,12 @@ def __init__( self.group_keys = group_keys if origin in ("epoch", "start", "start_day", "end", "end_day"): - self.origin = origin + # error: Incompatible types in assignment (expression has type "Union[Union[ + # Timestamp, datetime, datetime64, signedinteger[_64Bit], float, str], + # Literal['epoch', 'start', 'start_day', 'end', 'end_day']]", variable has + # type "Union[Timestamp, Literal['epoch', 'start', 'start_day', 'end', + # 'end_day']]") + self.origin = origin # type: ignore[assignment] else: try: self.origin = Timestamp(origin) @@ -1975,7 +1987,7 @@ def _get_timestamp_range_edges( last: Timestamp, freq: BaseOffset, closed: Literal["right", "left"] = "left", - origin="start_day", + origin: TimeGrouperOrigin = "start_day", offset: Timedelta | None = None, ) -> tuple[Timestamp, Timestamp]: """ @@ -2053,7 +2065,7 @@ def _get_period_range_edges( last: Period, freq: BaseOffset, closed: Literal["right", "left"] = "left", - origin="start_day", + origin: TimeGrouperOrigin = "start_day", offset: Timedelta | None = None, ) -> tuple[Period, Period]: """ @@ -2127,7 +2139,7 @@ def _adjust_dates_anchored( last: Timestamp, freq: Tick, closed: Literal["right", "left"] = "right", - origin="start_day", + origin: TimeGrouperOrigin = "start_day", offset: Timedelta | None = None, ) -> tuple[Timestamp, Timestamp]: # First and last offsets should be calculated from the start day to fix an @@ -2143,11 +2155,11 @@ def _adjust_dates_anchored( elif isinstance(origin, Timestamp): origin_nanos = origin.value elif origin in ["end", "end_day"]: - origin = last if origin == "end" else last.ceil("D") - sub_freq_times = (origin.value - first.value) // freq.nanos + origin_last = last if origin == "end" else last.ceil("D") + sub_freq_times = (origin_last.value - first.value) // freq.nanos if closed == "left": sub_freq_times += 1 - first = origin - sub_freq_times * freq + first = origin_last - sub_freq_times * freq origin_nanos = first.value origin_nanos += offset.value if offset else 0 diff --git a/pandas/core/reshape/encoding.py b/pandas/core/reshape/encoding.py index 9567a1053c9a6..6670633fcc587 100644 --- a/pandas/core/reshape/encoding.py +++ b/pandas/core/reshape/encoding.py @@ -2,7 +2,10 @@ from collections import defaultdict import itertools -from typing import Hashable +from typing import ( + Hashable, + Iterable, +) import numpy as np @@ -25,7 +28,7 @@ def get_dummies( data, prefix=None, - prefix_sep="_", + prefix_sep: str | Iterable[str] | dict[str, str] = "_", dummy_na: bool = False, columns=None, sparse: bool = False, @@ -221,7 +224,7 @@ def check_len(item, name): def _get_dummies_1d( data, prefix, - prefix_sep="_", + prefix_sep: str | Iterable[str] | dict[str, str] = "_", dummy_na: bool = False, sparse: bool = False, drop_first: bool = False, diff --git a/pandas/core/reshape/melt.py b/pandas/core/reshape/melt.py index 73f6aff82f330..f35430e37e964 100644 --- a/pandas/core/reshape/melt.py +++ b/pandas/core/reshape/melt.py @@ -2,7 +2,10 @@ import inspect import re -from typing import TYPE_CHECKING +from typing import ( + TYPE_CHECKING, + Hashable, +) import warnings import numpy as np @@ -42,7 +45,7 @@ def melt( id_vars=None, value_vars=None, var_name=None, - value_name="value", + value_name: Hashable = "value", col_level=None, ignore_index: bool = True, ) -> DataFrame: diff --git a/pandas/core/reshape/pivot.py b/pandas/core/reshape/pivot.py index a55a84735699d..8d1c20d5507a8 100644 --- a/pandas/core/reshape/pivot.py +++ b/pandas/core/reshape/pivot.py @@ -64,7 +64,7 @@ def pivot_table( fill_value=None, margins: bool = False, dropna: bool = True, - margins_name: str = "All", + margins_name: Hashable = "All", observed: bool = False, sort: bool = True, ) -> DataFrame: @@ -119,7 +119,7 @@ def __internal_pivot_table( fill_value, margins: bool, dropna: bool, - margins_name: str, + margins_name: Hashable, observed: bool, sort: bool, ) -> DataFrame: @@ -262,7 +262,7 @@ def _add_margins( cols, aggfunc, observed=None, - margins_name: str = "All", + margins_name: Hashable = "All", fill_value=None, ): if not isinstance(margins_name, str): @@ -334,7 +334,9 @@ def _add_margins( return result -def _compute_grand_margin(data: DataFrame, values, aggfunc, margins_name: str = "All"): +def _compute_grand_margin( + data: DataFrame, values, aggfunc, margins_name: Hashable = "All" +): if values: grand_margin = {} @@ -357,7 +359,7 @@ def _compute_grand_margin(data: DataFrame, values, aggfunc, margins_name: str = def _generate_marginal_results( - table, data, values, rows, cols, aggfunc, observed, margins_name: str = "All" + table, data, values, rows, cols, aggfunc, observed, margins_name: Hashable = "All" ): if len(cols) > 0: # need to "interleave" the margins @@ -427,7 +429,13 @@ def _all_key(key): def _generate_marginal_results_without_values( - table: DataFrame, data, rows, cols, aggfunc, observed, margins_name: str = "All" + table: DataFrame, + data, + rows, + cols, + aggfunc, + observed, + margins_name: Hashable = "All", ): if len(cols) > 0: # need to "interleave" the margins @@ -555,7 +563,7 @@ def crosstab( colnames=None, aggfunc=None, margins: bool = False, - margins_name: str = "All", + margins_name: Hashable = "All", dropna: bool = True, normalize: bool = False, ) -> DataFrame: @@ -696,7 +704,7 @@ def crosstab( kwargs = {"aggfunc": aggfunc} # error: Argument 7 to "pivot_table" of "DataFrame" has incompatible type - # "**Dict[str, object]"; expected "bool" + # "**Dict[str, object]"; expected "Union[...]" table = df.pivot_table( "__dummy__", index=unique_rownames, @@ -720,7 +728,7 @@ def crosstab( def _normalize( - table: DataFrame, normalize, margins: bool, margins_name="All" + table: DataFrame, normalize, margins: bool, margins_name: Hashable = "All" ) -> DataFrame: if not isinstance(normalize, (bool, str)): diff --git a/pandas/core/series.py b/pandas/core/series.py index 77a978647be31..b91d5540335f1 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -35,11 +35,14 @@ from pandas._libs.lib import no_default from pandas._typing import ( AggFuncType, + AlignJoin, AnyAll, AnyArrayLike, ArrayLike, Axis, AxisInt, + CorrelationMethod, + DropKeep, Dtype, DtypeObj, FilePath, @@ -2251,28 +2254,23 @@ def unique(self) -> ArrayLike: @overload def drop_duplicates( - self, - keep: Literal["first", "last", False] = ..., - *, - inplace: Literal[False] = ..., + self, keep: DropKeep = ..., *, inplace: Literal[False] = ... ) -> Series: ... @overload - def drop_duplicates( - self, keep: Literal["first", "last", False] = ..., *, inplace: Literal[True] - ) -> None: + def drop_duplicates(self, keep: DropKeep = ..., *, inplace: Literal[True]) -> None: ... @overload def drop_duplicates( - self, keep: Literal["first", "last", False] = ..., *, inplace: bool = ... + self, keep: DropKeep = ..., *, inplace: bool = ... ) -> Series | None: ... @deprecate_nonkeyword_arguments(version=None, allowed_args=["self"]) def drop_duplicates( - self, keep: Literal["first", "last", False] = "first", inplace: bool = False + self, keep: DropKeep = "first", inplace: bool = False ) -> Series | None: """ Return Series with duplicate values removed. @@ -2357,7 +2355,7 @@ def drop_duplicates( else: return result - def duplicated(self, keep: Literal["first", "last", False] = "first") -> Series: + def duplicated(self, keep: DropKeep = "first") -> Series: """ Indicate duplicate Series values. @@ -2706,8 +2704,7 @@ def quantile( def corr( self, other: Series, - method: Literal["pearson", "kendall", "spearman"] - | Callable[[np.ndarray, np.ndarray], float] = "pearson", + method: CorrelationMethod = "pearson", min_periods: int | None = None, ) -> float: """ @@ -4860,7 +4857,7 @@ def _needs_reindex_multi(self, axes, method, level) -> bool: def align( self, other: Series, - join: Literal["outer", "inner", "left", "right"] = "outer", + join: AlignJoin = "outer", axis: Axis | None = None, level: Level = None, copy: bool = True, diff --git a/pandas/core/strings/accessor.py b/pandas/core/strings/accessor.py index ab5439188cd0e..3f1176f42e44c 100644 --- a/pandas/core/strings/accessor.py +++ b/pandas/core/strings/accessor.py @@ -9,6 +9,7 @@ Callable, Hashable, Iterator, + Literal, cast, ) import warnings @@ -17,6 +18,7 @@ import pandas._libs.lib as lib from pandas._typing import ( + AlignJoin, DtypeObj, F, Scalar, @@ -427,7 +429,11 @@ def _get_series_list(self, others): @forbid_nonstring_types(["bytes", "mixed", "mixed-integer"]) def cat( - self, others=None, sep=None, na_rep=None, join="left" + self, + others=None, + sep=None, + na_rep=None, + join: AlignJoin = "left", ) -> str | Series | Index: """ Concatenate strings in the Series/Index with given separator. @@ -979,7 +985,7 @@ def rsplit(self, pat=None, n=-1, expand: bool = False): } ) @forbid_nonstring_types(["bytes"]) - def partition(self, sep=" ", expand: bool = True): + def partition(self, sep: str = " ", expand: bool = True): result = self._data.array._str_partition(sep, expand) return self._wrap_result(result, expand=expand, returns_string=expand) @@ -993,7 +999,7 @@ def partition(self, sep=" ", expand: bool = True): } ) @forbid_nonstring_types(["bytes"]) - def rpartition(self, sep=" ", expand: bool = True): + def rpartition(self, sep: str = " ", expand: bool = True): result = self._data.array._str_rpartition(sep, expand) return self._wrap_result(result, expand=expand, returns_string=expand) @@ -1553,7 +1559,12 @@ def repeat(self, repeats): return self._wrap_result(result) @forbid_nonstring_types(["bytes"]) - def pad(self, width, side="left", fillchar=" "): + def pad( + self, + width, + side: Literal["left", "right", "both"] = "left", + fillchar: str = " ", + ): """ Pad strings in the Series/Index up to width. @@ -1642,17 +1653,17 @@ def pad(self, width, side="left", fillchar=" "): @Appender(_shared_docs["str_pad"] % {"side": "left and right", "method": "center"}) @forbid_nonstring_types(["bytes"]) - def center(self, width, fillchar=" "): + def center(self, width, fillchar: str = " "): return self.pad(width, side="both", fillchar=fillchar) @Appender(_shared_docs["str_pad"] % {"side": "right", "method": "ljust"}) @forbid_nonstring_types(["bytes"]) - def ljust(self, width, fillchar=" "): + def ljust(self, width, fillchar: str = " "): return self.pad(width, side="right", fillchar=fillchar) @Appender(_shared_docs["str_pad"] % {"side": "left", "method": "rjust"}) @forbid_nonstring_types(["bytes"]) - def rjust(self, width, fillchar=" "): + def rjust(self, width, fillchar: str = " "): return self.pad(width, side="left", fillchar=fillchar) @forbid_nonstring_types(["bytes"]) @@ -1874,7 +1885,7 @@ def slice_replace(self, start=None, stop=None, repl=None): result = self._data.array._str_slice_replace(start, stop, repl) return self._wrap_result(result) - def decode(self, encoding, errors="strict"): + def decode(self, encoding, errors: str = "strict"): """ Decode character string in the Series/Index using indicated encoding. @@ -1903,7 +1914,7 @@ def decode(self, encoding, errors="strict"): return self._wrap_result(result) @forbid_nonstring_types(["bytes"]) - def encode(self, encoding, errors="strict"): + def encode(self, encoding, errors: str = "strict"): """ Encode character string in the Series/Index using indicated encoding. @@ -2152,7 +2163,7 @@ def wrap(self, width, **kwargs): return self._wrap_result(result) @forbid_nonstring_types(["bytes"]) - def get_dummies(self, sep="|"): + def get_dummies(self, sep: str = "|"): """ Return DataFrame of dummy/indicator variables for Series. diff --git a/pandas/core/strings/base.py b/pandas/core/strings/base.py index ae9a480ef73be..ae39526871d63 100644 --- a/pandas/core/strings/base.py +++ b/pandas/core/strings/base.py @@ -3,7 +3,10 @@ import abc from collections.abc import Callable # noqa: PDF001 import re -from typing import TYPE_CHECKING +from typing import ( + TYPE_CHECKING, + Literal, +) import numpy as np @@ -40,7 +43,12 @@ def _str_count(self, pat, flags=0): pass @abc.abstractmethod - def _str_pad(self, width, side="left", fillchar=" "): + def _str_pad( + self, + width, + side: Literal["left", "right", "both"] = "left", + fillchar: str = " ", + ): pass @abc.abstractmethod @@ -90,7 +98,7 @@ def _str_fullmatch( pass @abc.abstractmethod - def _str_encode(self, encoding, errors="strict"): + def _str_encode(self, encoding, errors: str = "strict"): pass @abc.abstractmethod @@ -150,7 +158,7 @@ def _str_wrap(self, width, **kwargs): pass @abc.abstractmethod - def _str_get_dummies(self, sep="|"): + def _str_get_dummies(self, sep: str = "|"): pass @abc.abstractmethod diff --git a/pandas/core/strings/object_array.py b/pandas/core/strings/object_array.py index 26843146b3633..e9b05f0d4e0e4 100644 --- a/pandas/core/strings/object_array.py +++ b/pandas/core/strings/object_array.py @@ -3,7 +3,10 @@ from collections.abc import Callable # noqa: PDF001 import re import textwrap -from typing import TYPE_CHECKING +from typing import ( + TYPE_CHECKING, + Literal, +) import unicodedata import numpy as np @@ -103,7 +106,12 @@ def _str_count(self, pat, flags=0): f = lambda x: len(regex.findall(x)) return self._str_map(f, dtype="int64") - def _str_pad(self, width, side="left", fillchar=" "): + def _str_pad( + self, + width, + side: Literal["left", "right", "both"] = "left", + fillchar: str = " ", + ): if side == "left": f = lambda x: x.rjust(width, fillchar) elif side == "right": @@ -220,7 +228,7 @@ def _str_fullmatch( f = lambda x: regex.fullmatch(x) is not None return self._str_map(f, na_value=na, dtype=np.dtype(bool)) - def _str_encode(self, encoding, errors="strict"): + def _str_encode(self, encoding, errors: str = "strict"): f = lambda x: x.encode(encoding, errors=errors) return self._str_map(f, dtype=object) @@ -356,7 +364,7 @@ def _str_wrap(self, width, **kwargs): tw = textwrap.TextWrapper(**kwargs) return self._str_map(lambda s: "\n".join(tw.wrap(s))) - def _str_get_dummies(self, sep="|"): + def _str_get_dummies(self, sep: str = "|"): from pandas import Series arr = Series(self).fillna("") diff --git a/pandas/core/tools/datetimes.py b/pandas/core/tools/datetimes.py index 565d2f2897514..dd4b21ade5cf8 100644 --- a/pandas/core/tools/datetimes.py +++ b/pandas/core/tools/datetimes.py @@ -329,7 +329,7 @@ def _convert_listlike_datetimes( name: Hashable = None, tz: Timezone | None = None, unit: str | None = None, - errors: str = "raise", + errors: DateTimeErrorChoices = "raise", infer_datetime_format: bool = False, dayfirst: bool | None = None, yearfirst: bool | None = None, @@ -713,7 +713,7 @@ def to_datetime( exact: bool = True, unit: str | None = None, infer_datetime_format: bool = False, - origin="unix", + origin: str = "unix", cache: bool = True, ) -> DatetimeIndex | Series | DatetimeScalar | NaTType | None: """ @@ -1306,7 +1306,12 @@ def calc_with_mask(carg, mask): return None -def to_time(arg, format=None, infer_time_format: bool = False, errors="raise"): +def to_time( + arg, + format=None, + infer_time_format: bool = False, + errors: DateTimeErrorChoices = "raise", +): # GH#34145 warnings.warn( "`to_time` has been moved, should be imported from pandas.core.tools.times. " diff --git a/pandas/core/tools/numeric.py b/pandas/core/tools/numeric.py index ef7f4bc92e25b..9b158a6b5aed2 100644 --- a/pandas/core/tools/numeric.py +++ b/pandas/core/tools/numeric.py @@ -1,9 +1,14 @@ from __future__ import annotations +from typing import Literal + import numpy as np from pandas._libs import lib -from pandas._typing import npt +from pandas._typing import ( + DateTimeErrorChoices, + npt, +) from pandas.core.dtypes.cast import maybe_downcast_numeric from pandas.core.dtypes.common import ( @@ -25,7 +30,11 @@ from pandas.core.arrays.numeric import NumericArray -def to_numeric(arg, errors="raise", downcast=None): +def to_numeric( + arg, + errors: DateTimeErrorChoices = "raise", + downcast: Literal["integer", "signed", "unsigned", "float"] | None = None, +): """ Convert argument to a numeric type. diff --git a/pandas/core/tools/timedeltas.py b/pandas/core/tools/timedeltas.py index 5026c97c0b2b0..705c77090e168 100644 --- a/pandas/core/tools/timedeltas.py +++ b/pandas/core/tools/timedeltas.py @@ -211,7 +211,9 @@ def to_timedelta( return _coerce_scalar_to_timedelta_type(arg, unit=unit, errors=errors) -def _coerce_scalar_to_timedelta_type(r, unit="ns", errors="raise"): +def _coerce_scalar_to_timedelta_type( + r, unit: UnitChoices | None = "ns", errors: DateTimeErrorChoices = "raise" +): """Convert string 'r' to a timedelta object.""" result: Timedelta | NaTType @@ -229,7 +231,9 @@ def _coerce_scalar_to_timedelta_type(r, unit="ns", errors="raise"): return result -def _convert_listlike(arg, unit=None, errors="raise", name=None): +def _convert_listlike( + arg, unit=None, errors: DateTimeErrorChoices = "raise", name=None +): """Convert a list of objects to a timedelta index object.""" if isinstance(arg, (list, tuple)) or not hasattr(arg, "dtype"): # This is needed only to ensure that in the case where we end up diff --git a/pandas/core/tools/times.py b/pandas/core/tools/times.py index bb100fab0ba8d..d0a4342254e16 100644 --- a/pandas/core/tools/times.py +++ b/pandas/core/tools/times.py @@ -8,6 +8,7 @@ import numpy as np from pandas._libs.lib import is_list_like +from pandas._typing import DateTimeErrorChoices from pandas.core.dtypes.generic import ( ABCIndex, @@ -16,7 +17,12 @@ from pandas.core.dtypes.missing import notna -def to_time(arg, format=None, infer_time_format: bool = False, errors="raise"): +def to_time( + arg, + format=None, + infer_time_format: bool = False, + errors: DateTimeErrorChoices = "raise", +): """ Parse time strings to time objects using fixed strptime formats ("%H:%M", "%H%M", "%I:%M%p", "%I%M%p", "%H:%M:%S", "%H%M%S", "%I:%M:%S%p", diff --git a/pandas/core/window/ewm.py b/pandas/core/window/ewm.py index 32559d0d88bcf..6fae119bffdf1 100644 --- a/pandas/core/window/ewm.py +++ b/pandas/core/window/ewm.py @@ -447,7 +447,7 @@ def _get_window_indexer(self) -> BaseIndexer: return ExponentialMovingWindowIndexer() def online( - self, engine="numba", engine_kwargs=None + self, engine: str = "numba", engine_kwargs=None ) -> OnlineExponentialMovingWindow: """ Return an ``OnlineExponentialMovingWindow`` object to calculate diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 5045b351a9525..cdc21f04da43a 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1857,7 +1857,7 @@ def _format_strings(self) -> list[str]: def get_format_timedelta64( values: np.ndarray | TimedeltaIndex | TimedeltaArray, - nat_rep: str = "NaT", + nat_rep: str | float = "NaT", box: bool = False, ) -> Callable: """ diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index be8f0e22a5174..0d8c970c414f0 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -9,6 +9,7 @@ import inspect import operator from typing import ( + TYPE_CHECKING, Any, Callable, Generator, @@ -71,6 +72,9 @@ refactor_levels, ) +if TYPE_CHECKING: + from matplotlib.colors import Colormap + try: import matplotlib as mpl import matplotlib.pyplot as plt @@ -2996,7 +3000,7 @@ def _get_numeric_subset_default(self): @Substitution(subset=subset) def background_gradient( self, - cmap="PuBu", + cmap: str | Colormap = "PuBu", low: float = 0, high: float = 0, axis: Axis | None = 0, @@ -3151,7 +3155,7 @@ def background_gradient( ) def text_gradient( self, - cmap="PuBu", + cmap: str | Colormap = "PuBu", low: float = 0, high: float = 0, axis: Axis | None = 0, @@ -3907,7 +3911,7 @@ def _validate_apply_axis_arg( def _background_gradient( data, - cmap="PuBu", + cmap: str | Colormap = "PuBu", low: float = 0, high: float = 0, text_color_threshold: float = 0.408, diff --git a/pandas/io/formats/style_render.py b/pandas/io/formats/style_render.py index dd56928d3a496..b8ea0374c0288 100644 --- a/pandas/io/formats/style_render.py +++ b/pandas/io/formats/style_render.py @@ -621,12 +621,12 @@ def _translate_body(self, idx_lengths: dict, max_rows: int, max_cols: int): def _check_trim( self, - count, - max, - obj, - element, - css=None, - value="...", + count: int, + max: int, + obj: list, + element: str, + css: str | None = None, + value: str = "...", ) -> bool: """ Indicates whether to break render loops and append a trimming indicator @@ -1503,7 +1503,7 @@ def alias_(x, value): def _element( html_element: str, - html_class: str, + html_class: str | None, value: Any, is_visible: bool, **kwargs, @@ -1528,7 +1528,7 @@ def _get_trimming_maximums( max_elements, max_rows=None, max_cols=None, - scaling_factor=0.8, + scaling_factor: float = 0.8, ) -> tuple[int, int]: """ Recursively reduce the number of rows and columns to satisfy max elements. diff --git a/pandas/io/parquet.py b/pandas/io/parquet.py index b4abd6aea6b20..6f297457ced41 100644 --- a/pandas/io/parquet.py +++ b/pandas/io/parquet.py @@ -3,7 +3,10 @@ import io import os -from typing import Any +from typing import ( + Any, + Literal, +) from warnings import catch_warnings from pandas._typing import ( @@ -270,7 +273,7 @@ def write( self, df: DataFrame, path, - compression="snappy", + compression: Literal["snappy", "gzip", "brotli"] | None = "snappy", index=None, partition_cols=None, storage_options: StorageOptions = None, diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 75cbf57f82644..39273a28b6d0f 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -1531,7 +1531,7 @@ def get_storer(self, key: str) -> GenericFixed | Table: def copy( self, file, - mode="w", + mode: str = "w", propindexes: bool = True, keys=None, complib=None, diff --git a/pandas/io/sql.py b/pandas/io/sql.py index 4bc2de32a20d5..9beafb9032676 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -18,6 +18,7 @@ TYPE_CHECKING, Any, Iterator, + Literal, cast, overload, ) @@ -603,7 +604,7 @@ def to_sql( name: str, con, schema: str | None = None, - if_exists: str = "fail", + if_exists: Literal["fail", "replace", "append"] = "fail", index: bool = True, index_label: IndexLabel = None, chunksize: int | None = None, @@ -784,7 +785,7 @@ def __init__( pandas_sql_engine, frame=None, index: bool | str | list[str] | None = True, - if_exists: str = "fail", + if_exists: Literal["fail", "replace", "append"] = "fail", prefix: str = "pandas", index_label=None, schema=None, @@ -1269,7 +1270,7 @@ def to_sql( self, frame, name, - if_exists: str = "fail", + if_exists: Literal["fail", "replace", "append"] = "fail", index: bool = True, index_label=None, schema=None, @@ -1589,7 +1590,7 @@ def prep_table( self, frame, name, - if_exists="fail", + if_exists: Literal["fail", "replace", "append"] = "fail", index: bool | str | list[str] | None = True, index_label=None, schema=None, @@ -1666,14 +1667,14 @@ def to_sql( self, frame, name, - if_exists: str = "fail", + if_exists: Literal["fail", "replace", "append"] = "fail", index: bool = True, index_label=None, schema=None, chunksize=None, dtype: DtypeArg | None = None, method=None, - engine="auto", + engine: str = "auto", **engine_kwargs, ) -> int | None: """ diff --git a/pandas/plotting/_matplotlib/boxplot.py b/pandas/plotting/_matplotlib/boxplot.py index ae61a9743ca1d..6067f7e7fca84 100644 --- a/pandas/plotting/_matplotlib/boxplot.py +++ b/pandas/plotting/_matplotlib/boxplot.py @@ -3,6 +3,7 @@ import inspect from typing import ( TYPE_CHECKING, + Collection, Literal, NamedTuple, ) @@ -11,6 +12,7 @@ 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 @@ -68,8 +70,11 @@ def _args_adjust(self) -> None: else: self.sharey = False + # error: Signature of "_plot" incompatible with supertype "MPLPlot" @classmethod - def _plot(cls, ax, y, column_num=None, return_type="axes", **kwds): + def _plot( # type: ignore[override] + cls, ax, y, column_num=None, return_type: str = "axes", **kwds + ): if y.ndim == 2: y = [remove_na_arraylike(v) for v in y] # Boxplot fails with empty arrays, so need to add a NaN @@ -118,7 +123,14 @@ def _validate_color_args(self): self._medians_c = colors[2] self._caps_c = colors[0] - def _get_colors(self, num_colors=None, color_kwds="color") -> None: + def _get_colors( + self, + num_colors=None, + color_kwds: dict[str, MatplotlibColor] + | MatplotlibColor + | Collection[MatplotlibColor] + | None = "color", + ) -> None: pass def maybe_color_bp(self, bp) -> None: diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index a02e81935f696..9dcc858c6e589 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -987,7 +987,11 @@ def _apply_style_colors(self, colors, kwds, col_num, label): kwds["color"] = colors[col_num % len(colors)] return style, kwds - def _get_colors(self, num_colors=None, color_kwds="color"): + def _get_colors( + self, + num_colors: int | None = None, + color_kwds: str = "color", + ): if num_colors is None: num_colors = self.nseries diff --git a/pandas/plotting/_matplotlib/style.py b/pandas/plotting/_matplotlib/style.py index d8823c7ec8d3d..c1b37eca2a76c 100644 --- a/pandas/plotting/_matplotlib/style.py +++ b/pandas/plotting/_matplotlib/style.py @@ -6,8 +6,6 @@ TYPE_CHECKING, Collection, Iterator, - Sequence, - Union, cast, ) import warnings @@ -17,6 +15,7 @@ import matplotlib.colors import numpy as np +from pandas._typing import MatplotlibColor as Color from pandas.util._exceptions import find_stack_level from pandas.core.dtypes.common import is_list_like @@ -29,9 +28,6 @@ from matplotlib.colors import Colormap -Color = Union[str, Sequence[float]] - - def get_standard_colors( num_colors: int, colormap: Colormap | None = None, diff --git a/pyright_reportGeneralTypeIssues.json b/pyright_reportGeneralTypeIssues.json index 940364e580d12..761018c3ce496 100644 --- a/pyright_reportGeneralTypeIssues.json +++ b/pyright_reportGeneralTypeIssues.json @@ -17,6 +17,7 @@ # and all files that currently don't pass "pandas/_testing/__init__.py", "pandas/_testing/_hypothesis.py", + "pandas/_testing/_io.py", "pandas/compat/pickle_compat.py", "pandas/core/algorithms.py", "pandas/core/apply.py", @@ -80,6 +81,7 @@ "pandas/core/sorting.py", "pandas/core/strings/accessor.py", "pandas/core/tools/datetimes.py", + "pandas/core/tools/numeric.py", "pandas/core/tools/timedeltas.py", "pandas/core/util/hashing.py", "pandas/core/window/ewm.py",