Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ repos:
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 25.9.0
rev: 25.11.0
hooks:
- id: black
18 changes: 15 additions & 3 deletions pandas-stubs/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sys

from pandas import (
api as api,
arrays as arrays,
Expand Down Expand Up @@ -47,7 +49,6 @@ from pandas.core.api import (
UInt16Dtype as UInt16Dtype,
UInt32Dtype as UInt32Dtype,
UInt64Dtype as UInt64Dtype,
array as array,
bdate_range as bdate_range,
date_range as date_range,
factorize as factorize,
Expand Down Expand Up @@ -100,13 +101,11 @@ from pandas.io.api import (
HDFStore as HDFStore,
read_clipboard as read_clipboard,
read_csv as read_csv,
read_excel as read_excel,
read_feather as read_feather,
read_fwf as read_fwf,
read_hdf as read_hdf,
read_html as read_html,
read_json as read_json,
read_orc as read_orc,
read_parquet as read_parquet,
read_pickle as read_pickle,
read_sas as read_sas,
Expand All @@ -118,8 +117,21 @@ from pandas.io.api import (
read_table as read_table,
read_xml as read_xml,
)
from pandas.io.api import (
read_excel as read_excel, # pyright: ignore[reportUnknownVariableType]
)
from pandas.io.api import (
read_orc as read_orc, # pyright: ignore[reportUnknownVariableType]
)
from pandas.io.json._normalize import json_normalize as json_normalize
from pandas.tseries import offsets as offsets
from pandas.tseries.api import infer_freq as infer_freq

if sys.version_info >= (3, 11):
from pandas.core.construction import array as array
else:
from pandas.core.construction import (
array as array, # pyright: ignore[reportUnknownVariableType]
)

__version__: str
6 changes: 2 additions & 4 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[str, Any]
Frequency: TypeAlias = str | BaseOffset
PeriodFrequency: TypeAlias = (
str
Expand Down Expand Up @@ -967,9 +967,7 @@ ListLikeExceptSeriesAndStr: TypeAlias = (
MutableSequence[Any] | np_1darray | tuple[Any, ...] | Index
)
ListLikeU: TypeAlias = Sequence | np_1darray | Series | Index
ListLikeHashable: TypeAlias = (
MutableSequence[HashableT] | np_1darray | tuple[HashableT, ...] | range
)
ListLikeHashable: TypeAlias = SequenceNotStr[HashableT] | np_1darray | range

class SupportsDType(Protocol[GenericT_co]):
@property
Expand Down
10 changes: 9 additions & 1 deletion pandas-stubs/core/api.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sys

from pandas.core.algorithms import (
factorize as factorize,
unique as unique,
Expand All @@ -20,7 +22,6 @@ from pandas.core.arrays.integer import (
UInt64Dtype as UInt64Dtype,
)
from pandas.core.arrays.string_ import StringDtype as StringDtype
from pandas.core.construction import array as array
from pandas.core.frame import DataFrame as DataFrame
from pandas.core.groupby import (
Grouper as Grouper,
Expand Down Expand Up @@ -75,3 +76,10 @@ from pandas.core.dtypes.missing import (

from pandas.io.formats.format import set_eng_float_format as set_eng_float_format
from pandas.tseries.offsets import DateOffset as DateOffset

if sys.version_info >= (3, 11):
from pandas.core.construction import array as array
else:
from pandas.core.construction import (
array as array, # pyright: ignore[reportUnknownVariableType]
)
2 changes: 1 addition & 1 deletion pandas-stubs/core/computation/eval.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def eval(
engine: Literal["python", "numexpr"] | None = ...,
local_dict: dict[str, Any] | None = None,
global_dict: dict[str, Any] | None = None,
resolvers: list[Mapping] | None = ...,
resolvers: list[Mapping[Any, Any]] | None = ...,
level: int = 0,
target: object | None = None,
inplace: bool = False,
Expand Down
12 changes: 6 additions & 6 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
@overload
def sort_values(
self,
by: _str | Sequence[_str],
by: _str | SequenceNotStr[_str],
*,
axis: Axis = 0,
ascending: _bool | Sequence[_bool] = ...,
Expand All @@ -1187,7 +1187,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
@overload
def sort_values(
self,
by: _str | Sequence[_str],
by: _str | SequenceNotStr[_str],
*,
axis: Axis = 0,
ascending: _bool | Sequence[_bool] = ...,
Expand Down Expand Up @@ -1394,7 +1394,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
@overload
def groupby( # type: ignore[overload-overlap] # pyright: ignore reportOverlappingOverload
self,
by: MultiIndex | GroupByObjectNonScalar | None = ...,
by: MultiIndex | GroupByObjectNonScalar[Any] | None = ...,
level: IndexLabel | None = ...,
as_index: Literal[True] = True,
sort: _bool = ...,
Expand All @@ -1405,7 +1405,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
@overload
def groupby( # type: ignore[overload-overlap]
self,
by: MultiIndex | GroupByObjectNonScalar | None = ...,
by: MultiIndex | GroupByObjectNonScalar[Any] | None = ...,
level: IndexLabel | None = ...,
as_index: Literal[False] = False,
sort: _bool = ...,
Expand Down Expand Up @@ -1862,7 +1862,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
@overload
def boxplot(
self,
by: Hashable | ListLikeHashable,
by: Hashable | ListLikeHashable[Hashable],
ax: PlotAxes | None = None,
fontsize: float | _str | None = None,
rot: float = 0,
Expand All @@ -1877,7 +1877,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
@overload
def boxplot(
self,
by: Hashable | ListLikeHashable,
by: Hashable | ListLikeHashable[Hashable],
ax: PlotAxes | None = None,
fontsize: float | _str | None = None,
rot: float = 0,
Expand Down
58 changes: 42 additions & 16 deletions pandas-stubs/core/reshape/pivot.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ from pandas._typing import (
Label,
Scalar,
ScalarT,
SequenceNotStr,
np_ndarray,
)

_PivotAggCallable: TypeAlias = Callable[[Series], ScalarT]

_PivotAggFunc: TypeAlias = (
_PivotAggCallable
_PivotAggCallable[ScalarT]
| np.ufunc
| Literal["mean", "sum", "count", "min", "max", "median", "std", "var"]
)
Expand Down Expand Up @@ -65,11 +66,17 @@ _ExtendedAnyArrayLike: TypeAlias = AnyArrayLike | ArrayLike
@overload
def pivot_table(
data: DataFrame,
values: _PivotTableValuesTypes = None,
index: _PivotTableIndexTypes = None,
columns: _PivotTableColumnsTypes = None,
values: _PivotTableValuesTypes[
Hashable # ty: ignore[invalid-type-arguments]
] = None,
index: _PivotTableIndexTypes[Hashable] = None, # ty: ignore[invalid-type-arguments]
columns: _PivotTableColumnsTypes[
Hashable # ty: ignore[invalid-type-arguments]
] = None,
aggfunc: (
_PivotAggFunc | Sequence[_PivotAggFunc] | Mapping[Hashable, _PivotAggFunc]
_PivotAggFunc[Any]
| Sequence[_PivotAggFunc[Any]]
| Mapping[Hashable, _PivotAggFunc[Any]]
) = "mean",
fill_value: Scalar | None = None,
margins: bool = False,
Expand All @@ -83,12 +90,20 @@ def pivot_table(
@overload
def pivot_table(
data: DataFrame,
values: _PivotTableValuesTypes = None,
values: _PivotTableValuesTypes[
Hashable # ty: ignore[invalid-type-arguments]
] = None,
*,
index: Grouper,
columns: _PivotTableColumnsTypes | np_ndarray | Index[Any] = None,
columns: (
_PivotTableColumnsTypes[Hashable] # ty: ignore[invalid-type-arguments]
| np_ndarray
| Index[Any]
) = None,
aggfunc: (
_PivotAggFunc | Sequence[_PivotAggFunc] | Mapping[Hashable, _PivotAggFunc]
_PivotAggFunc[Any]
| Sequence[_PivotAggFunc[Any]]
| Mapping[Hashable, _PivotAggFunc[Any]]
) = "mean",
fill_value: Scalar | None = None,
margins: bool = False,
Expand All @@ -100,12 +115,20 @@ def pivot_table(
@overload
def pivot_table(
data: DataFrame,
values: _PivotTableValuesTypes = None,
index: _PivotTableIndexTypes | np_ndarray | Index[Any] = None,
values: _PivotTableValuesTypes[
Hashable # ty: ignore[invalid-type-arguments]
] = None,
index: (
_PivotTableIndexTypes[Hashable] # ty: ignore[invalid-type-arguments]
| np_ndarray
| Index[Any]
) = None,
*,
columns: Grouper,
aggfunc: (
_PivotAggFunc | Sequence[_PivotAggFunc] | Mapping[Hashable, _PivotAggFunc]
_PivotAggFunc[Any]
| Sequence[_PivotAggFunc[Any]]
| Mapping[Hashable, _PivotAggFunc[Any]]
) = "mean",
fill_value: Scalar | None = None,
margins: bool = False,
Expand All @@ -121,11 +144,14 @@ def pivot(
columns: _NonIterableHashable | Sequence[HashableT2] = ...,
values: _NonIterableHashable | Sequence[HashableT3] = ...,
) -> DataFrame: ...

_Values: TypeAlias = SequenceNotStr[Any] | _ExtendedAnyArrayLike

@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 +163,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
15 changes: 11 additions & 4 deletions pandas-stubs/core/reshape/tile.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections.abc import Sequence
from typing import (
Any,
Literal,
overload,
)
Expand Down Expand Up @@ -102,7 +103,7 @@ def cut(
include_lowest: bool = ...,
duplicates: Literal["raise", "drop"] = ...,
ordered: bool = ...,
) -> tuple[Series, IntervalIndex]: ...
) -> tuple[Series, IntervalIndex[Any]]: ...
@overload
def cut(
x: Sequence[float] | np_ndarray_anyint | np_ndarray_float | Index,
Expand Down Expand Up @@ -132,7 +133,9 @@ def cut(
@overload
def cut(
x: Sequence[float] | np_ndarray_anyint | np_ndarray_float | Index,
bins: int | Sequence[float] | Index[int] | Index[float] | IntervalIndex | Series,
bins: (
int | Sequence[float] | Index[int] | Index[float] | IntervalIndex[Any] | Series
),
right: bool = ...,
*,
labels: Literal[False],
Expand Down Expand Up @@ -163,7 +166,9 @@ def cut(
@overload
def cut(
x: Series,
bins: int | Sequence[float] | Index[int] | Index[float] | IntervalIndex | Series,
bins: (
int | Sequence[float] | Index[int] | Index[float] | IntervalIndex[Any] | Series
),
right: bool = ...,
labels: Literal[False] | Sequence[Label] | None = ...,
retbins: Literal[False] = False,
Expand All @@ -175,7 +180,9 @@ def cut(
@overload
def cut(
x: Sequence[float] | np_ndarray_anyint | np_ndarray_float | Index,
bins: int | Sequence[float] | Index[int] | Index[float] | IntervalIndex | Series,
bins: (
int | Sequence[float] | Index[int] | Index[float] | IntervalIndex[Any] | Series
),
right: bool = ...,
labels: Sequence[Label] | None = ...,
retbins: Literal[False] = False,
Expand Down
10 changes: 1 addition & 9 deletions pandas-stubs/core/tools/timedeltas.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from collections.abc import Sequence
from datetime import timedelta
from typing import overload

Expand Down Expand Up @@ -28,14 +27,7 @@ def to_timedelta(
) -> Series[Timedelta]: ...
@overload
def to_timedelta(
arg: (
SequenceNotStr
| Sequence[float | timedelta]
| tuple[str | float | timedelta, ...]
| range
| ArrayLike
| Index
),
arg: SequenceNotStr[str | float | timedelta] | range | ArrayLike | Index,
unit: TimeDeltaUnitChoices | None = ...,
errors: RaiseCoerce = ...,
) -> TimedeltaIndex: ...
10 changes: 7 additions & 3 deletions pandas-stubs/io/api.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ from pandas.io.clipboards import read_clipboard as read_clipboard
from pandas.io.excel import (
ExcelFile as ExcelFile,
ExcelWriter as ExcelWriter,
read_excel as read_excel,
)
from pandas.io.excel import (
read_excel as read_excel, # pyright: ignore[reportUnknownVariableType]
)
from pandas.io.feather_format import read_feather as read_feather
from pandas.io.html import read_html as read_html
from pandas.io.json import read_json as read_json
from pandas.io.orc import read_orc as read_orc
from pandas.io.orc import (
read_orc as read_orc, # pyright: ignore[reportUnknownVariableType]
)
from pandas.io.parquet import read_parquet as read_parquet
from pandas.io.parsers import (
from pandas.io.parsers.readers import (
read_csv as read_csv,
read_fwf as read_fwf,
read_table as read_table,
Expand Down
Loading