Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pandas-stubs/_libs/tslibs/offsets.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,15 @@ class _CustomBusinessMonth(SingleConstructorOffset):
n: int = ...,
normalize: bool = ...,
offset: timedelta = ...,
holidays: list | None = ...,
holidays: list[Any] | None = ...,
) -> None: ...

class CustomBusinessDay(BusinessDay):
def __init__(
self,
n: int = ...,
normalize: bool = ...,
holidays: list = ...,
holidays: list[Any] = ...,
calendar: AbstractHolidayCalendar | np.busdaycalendar = ...,
) -> None: ...

Expand All @@ -225,7 +225,7 @@ class CustomBusinessHour(BusinessHour):
start: str | time | Collection[str | time] = ...,
end: str | time | Collection[str | time] = ...,
offset: timedelta = ...,
holidays: list | None = ...,
holidays: list[Any] | None = ...,
) -> None: ...

class CustomBusinessMonthEnd(_CustomBusinessMonth): ...
Expand Down
4 changes: 2 additions & 2 deletions pandas-stubs/_typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ Level: TypeAlias = Hashable
Shape: TypeAlias = tuple[int, ...]
Suffixes: TypeAlias = tuple[str | None, str | None] | list[str | None]
Ordered: TypeAlias = bool | None
JSONSerializable: TypeAlias = PythonScalar | list | dict
JSONSerializable: TypeAlias = PythonScalar | list[Any] | dict
Frequency: TypeAlias = str | BaseOffset
PeriodFrequency: TypeAlias = (
str
Expand Down Expand Up @@ -966,7 +966,7 @@ ListLikeT = TypeVar("ListLikeT", bound=ListLike)
ListLikeExceptSeriesAndStr: TypeAlias = (
MutableSequence[Any] | np_1darray | tuple[Any, ...] | Index
)
ListLikeU: TypeAlias = Sequence | np_1darray | Series | Index
ListLikeU: TypeAlias = Sequence[Any] | np_1darray | Series | Index
ListLikeHashable: TypeAlias = (
MutableSequence[HashableT] | np_1darray | tuple[HashableT, ...] | range
)
Expand Down
8 changes: 4 additions & 4 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -552,15 +552,15 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
*,
into: MutableMapping | type[MutableMapping],
index: bool = ...,
) -> MutableMapping[str, list]: ...
) -> MutableMapping[str, list[Any]]: ...
@overload
def to_dict(
self,
orient: Literal["split", "tight"],
*,
into: type[dict] = ...,
index: bool = ...,
) -> dict[str, list]: ...
) -> dict[str, list[Any]]: ...
@classmethod
def from_records(
cls,
Expand Down Expand Up @@ -1256,7 +1256,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
keep: NsmallestNlargestKeep = "first",
) -> Self: ...
def swaplevel(self, i: Level = ..., j: Level = ..., axis: Axis = 0) -> Self: ...
def reorder_levels(self, order: list, axis: Axis = 0) -> Self: ...
def reorder_levels(self, order: list[int] | list[str], axis: Axis = 0) -> Self: ...
def compare(
self,
other: DataFrame,
Expand Down Expand Up @@ -1796,7 +1796,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
def hist(
self,
by: _str | ListLike | None = None,
bins: int | list = 10,
bins: int | Sequence[int] = 10,
*,
grid: _bool = True,
xlabelsize: float | str | None = None,
Expand Down
6 changes: 4 additions & 2 deletions pandas-stubs/core/groupby/generic.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,17 @@ _TT = TypeVar("_TT", bound=Literal[True, False])
class DFCallable1(Protocol[P]): # ty: ignore[invalid-argument-type]
def __call__(
self, df: DataFrame, /, *args: P.args, **kwargs: P.kwargs
) -> Scalar | list | dict: ...
) -> Scalar | list[Any] | dict: ...

class DFCallable2(Protocol[P]): # ty: ignore[invalid-argument-type]
def __call__(
self, df: DataFrame, /, *args: P.args, **kwargs: P.kwargs
) -> DataFrame | Series: ...

class DFCallable3(Protocol[P]): # ty: ignore[invalid-argument-type]
def __call__(self, df: Iterable, /, *args: P.args, **kwargs: P.kwargs) -> float: ...
def __call__(
self, df: Iterable[Any], /, *args: P.args, **kwargs: P.kwargs
) -> float: ...

class DataFrameGroupBy(GroupBy[DataFrame], Generic[ByT, _TT]):
# error: Overload 3 for "apply" will never be used because its parameters overlap overload 1
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/groupby/groupby.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ class GroupBy(BaseGroupBy[NDFrameT]):
n: int | None = None,
frac: float | None = None,
replace: bool = False,
weights: Sequence | Series | None = ...,
weights: Sequence[float] | Series | None = ...,
random_state: RandomState | None = ...,
) -> NDFrameT: ...

Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/indexes/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
def intersection(
self, other: list[S1] | Self, sort: bool | None = False
) -> Self: ...
def difference(self, other: list | Self, sort: bool | None = None) -> Self: ...
def difference(self, other: list[Any] | Self, sort: bool | None = None) -> Self: ...
def symmetric_difference(
self,
other: list[S1] | Self,
Expand Down
11 changes: 0 additions & 11 deletions pandas-stubs/core/indexes/multi.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from collections.abc import (
Callable,
Collection,
Hashable,
Iterable,
Expand Down Expand Up @@ -91,16 +90,6 @@ class MultiIndex(Index):
def memory_usage(self, deep: bool = False) -> int: ...
@property
def nbytes(self) -> int: ...
def format(
self,
name: bool | None = ...,
formatter: Callable[..., Any] | None = ...,
na_rep: str | None = ...,
names: bool = ...,
space: int = ...,
sparsify: bool | None = ...,
adjoin: bool = ...,
) -> list: ...
Comment on lines -94 to -103
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Undocumented

def __len__(self) -> int: ...
@property
def values(self): ...
Expand Down
12 changes: 7 additions & 5 deletions pandas-stubs/core/reshape/pivot.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ from pandas._typing import (
Label,
Scalar,
ScalarT,
SequenceNotStr,
np_ndarray,
)

Expand Down Expand Up @@ -61,6 +62,7 @@ _PivotTableColumnsTypes: TypeAlias = (
_PivotTableValuesTypes: TypeAlias = Label | Sequence[HashableT3] | None

_ExtendedAnyArrayLike: TypeAlias = AnyArrayLike | ArrayLike
_Values: TypeAlias = SequenceNotStr[Any] | _ExtendedAnyArrayLike

@overload
def pivot_table(
Expand Down Expand Up @@ -123,9 +125,9 @@ def pivot(
) -> DataFrame: ...
@overload
def crosstab(
index: list | _ExtendedAnyArrayLike | list[Sequence | _ExtendedAnyArrayLike],
columns: list | _ExtendedAnyArrayLike | list[Sequence | _ExtendedAnyArrayLike],
values: list | _ExtendedAnyArrayLike,
index: _Values | list[_Values],
columns: _Values | list[_Values],
values: _Values,
rownames: list[HashableT1] | None = ...,
colnames: list[HashableT2] | None = ...,
*,
Expand All @@ -137,8 +139,8 @@ def crosstab(
) -> DataFrame: ...
@overload
def crosstab(
index: list | _ExtendedAnyArrayLike | list[Sequence | _ExtendedAnyArrayLike],
columns: list | _ExtendedAnyArrayLike | list[Sequence | _ExtendedAnyArrayLike],
index: _Values | list[_Values],
columns: _Values | list[_Values],
values: None = None,
rownames: list[HashableT1] | None = ...,
colnames: list[HashableT2] | None = ...,
Expand Down
7 changes: 3 additions & 4 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ from collections.abc import (
Mapping,
MutableMapping,
Sequence,
Set as AbstractSet,
ValuesView,
)
from datetime import (
Expand Down Expand Up @@ -564,8 +565,6 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
def __array__( # ty: ignore[invalid-method-override]
self, dtype: _str | np.dtype = ..., copy: bool | None = ...
) -> np_1darray: ...
@property
def axes(self) -> list: ...
@final
def __getattr__(self, name: _str) -> S1: ...

Expand Down Expand Up @@ -1171,7 +1170,7 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
def apply(
self,
func: Callable[
..., Scalar | Sequence | set | Mapping | NAType | frozenset | None
..., Scalar | Sequence[Any] | AbstractSet[Any] | Mapping | NAType | None
],
convertDType: _bool = ...,
args: tuple[Any, ...] = ...,
Expand Down Expand Up @@ -1373,7 +1372,7 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
ylabelsize: float | _str | None = None,
yrot: float | None = None,
figsize: tuple[float, float] | None = None,
bins: int | Sequence = 10,
bins: int | Sequence[int] = 10,
backend: _str | None = None,
legend: _bool = False,
**kwargs: Any,
Expand Down
4 changes: 2 additions & 2 deletions pandas-stubs/io/formats/style.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ from pandas.io.formats.style_render import (
class _SeriesFunc(Protocol):
def __call__(
self, series: Series, /, *args: Any, **kwargs: Any
) -> list | Series: ...
) -> list[Any] | Series: ...

class _DataFrameFunc(Protocol):
def __call__(
Expand Down Expand Up @@ -233,7 +233,7 @@ class Styler(StylerRenderer):
@overload
def apply(
self,
func: _SeriesFunc | Callable[[Series], list | Series],
func: _SeriesFunc | Callable[[Series], list[Any] | Series],
axis: Axis = ...,
subset: Subset | None = ...,
**kwargs: Any,
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/io/json/_normalize.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ from pandas._typing import IgnoreRaise

def json_normalize(
data: dict | list[dict],
record_path: str | list | None = None,
record_path: str | list[str] | None = None,
meta: str | list[str | list[str]] | None = None,
meta_prefix: str | None = None,
record_prefix: str | None = None,
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/io/parsers/readers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ class TextFileReader(abc.Iterator):
squeeze: bool
def __init__(
self,
f: FilePath | ReadCsvBuffer[bytes] | ReadCsvBuffer[str] | list,
f: FilePath | ReadCsvBuffer[bytes] | ReadCsvBuffer[str] | list[str],
engine: CSVEngine | None = ...,
**kwds: Any,
) -> None: ...
Expand Down
4 changes: 2 additions & 2 deletions pandas-stubs/io/pytables.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ class HDFStore:
"namereplace",
] = "strict",
) -> None: ...
def groups(self) -> list: ...
def groups(self) -> list[object]: ...
def walk(
self, where: str = "/"
) -> Generator[tuple[str, list, list[str]], None, None]: ...
) -> Generator[tuple[str, list[str], list[str]], None, None]: ...
def info(self) -> str: ...

class TableIterator:
Expand Down
4 changes: 2 additions & 2 deletions pandas-stubs/plotting/_core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ class PlotAccessor:
x: Hashable,
y: Hashable,
C: Hashable | None = ...,
reduce_C_function: Callable[[list], float] | None = ...,
reduce_C_function: Callable[[list[Any]], float] | None = ...,
gridsize: int | tuple[int, int] | None = ...,
*,
subplots: Literal[False] | None = ...,
Expand All @@ -466,7 +466,7 @@ class PlotAccessor:
x: Hashable,
y: Hashable,
C: Hashable | None = ...,
reduce_C_function: Callable[[list], float] | None = ...,
reduce_C_function: Callable[[list[Any]], float] | None = ...,
gridsize: int | tuple[int, int] | None = ...,
*,
subplots: Literal[True],
Expand Down
2 changes: 1 addition & 1 deletion tests/series/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ def retseries(x: float) -> float:

check(assert_type(s.apply(retseries).tolist(), list), list)

def retlist(x: float) -> list:
def retlist(x: float) -> list[float]:
return [x]

check(assert_type(s.apply(retlist), pd.Series), pd.Series, list)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,7 @@ def test_merge_asof() -> None:

def test_crosstab_args() -> None:
a = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2]
b: list = [4, 5, 6, 3, 4, 3, 5, 6, 5, 5]
b: list[Any] = [4, 5, 6, 3, 4, 3, 5, 6, 5, 5]
c = [1, 3, 2, 3, 1, 2, 3, 1, 3, 2]
check(assert_type(pd.crosstab(a, b), pd.DataFrame), pd.DataFrame)
check(assert_type(pd.crosstab(a, [b, c]), pd.DataFrame), pd.DataFrame)
Expand Down