Skip to content
Merged
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
34 changes: 18 additions & 16 deletions pandas-stubs/_typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ ListLikeExceptSeriesAndStr: TypeAlias = (
)
ListLikeU: TypeAlias = Sequence[Any] | np_1darray | Series | Index
ListLikeHashable: TypeAlias = (
MutableSequence[HashableT] | np_1darray | tuple[HashableT, ...] | range
MutableSequence[HashableT0] | np_1darray | tuple[HashableT0, ...] | range
)

class SupportsDType(Protocol[GenericT_co]):
Expand Down Expand Up @@ -1100,21 +1100,23 @@ if TYPE_CHECKING: # noqa: PYI002
| Period
| Interval[int | float | Timestamp | Timedelta],
)
GroupByObjectNonScalar: TypeAlias = (
tuple[_HashableTa, ...]
| list[_HashableTa]
| Function
| list[Function]
| list[Series]
| np_ndarray
| list[np_ndarray]
| Mapping[Label, Any]
| list[Mapping[Label, Any]]
| list[Index]
| Grouper
| list[Grouper]
)
GroupByObject: TypeAlias = Scalar | Index | GroupByObjectNonScalar | Series
GroupByObjectNonScalar: TypeAlias = (
tuple[_HashableTa, ...]
| list[_HashableTa]
| Function
| list[Function]
| list[Series]
| np_ndarray
| list[np_ndarray]
| Mapping[Label, Any]
| list[Mapping[Label, Any]]
| list[Index]
| Grouper
| list[Grouper]
)
GroupByObject: TypeAlias = (
Scalar | Index | GroupByObjectNonScalar[_HashableTa] | Series
)

StataDateFormat: TypeAlias = Literal[
"tc",
Expand Down
8 changes: 3 additions & 5 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ from pandas.core.indexing import (
_LocIndexer,
)
from pandas.core.reshape.pivot import (
_PivotAggFunc,
_PivotAggFuncTypes,
_PivotTableColumnsTypes,
_PivotTableIndexTypes,
_PivotTableValuesTypes,
Expand Down Expand Up @@ -178,7 +178,7 @@ from pandas.plotting import PlotAccessor
from pandas.plotting._core import _BoxPlotT

_T_MUTABLE_MAPPING_co = TypeVar(
"_T_MUTABLE_MAPPING_co", bound=MutableMapping, covariant=True
"_T_MUTABLE_MAPPING_co", bound=MutableMapping[Any, Any], covariant=True
)

_iLocSetItemKey: TypeAlias = (
Expand Down Expand Up @@ -1378,9 +1378,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
values: _PivotTableValuesTypes = None,
index: _PivotTableIndexTypes = None,
columns: _PivotTableColumnsTypes = None,
aggfunc: (
_PivotAggFunc | Sequence[_PivotAggFunc] | Mapping[Hashable, _PivotAggFunc]
) = "mean",
aggfunc: _PivotAggFuncTypes[Scalar] = "mean",
fill_value: Scalar | None = None,
margins: _bool = False,
dropna: _bool = True,
Expand Down
9 changes: 6 additions & 3 deletions pandas-stubs/core/indexes/accessors.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ from datetime import (
tzinfo as _tzinfo,
)
from typing import (
Any,
Generic,
Literal,
TypeVar,
Expand Down Expand Up @@ -377,7 +378,7 @@ class PeriodProperties(
Series[Timestamp], Series[int], Series[str], DatetimeArray, PeriodArray
],
_DatetimeFieldOps[Series[int]],
_IsLeapYearProperty,
_IsLeapYearProperty[_DTBoolOpsReturnType],
_FreqProperty[BaseOffset],
): ...
class CombinedDatetimelikeProperties(
Expand All @@ -393,7 +394,9 @@ class CombinedDatetimelikeProperties(
Series[Period],
],
_TimedeltaPropertiesNoRounding[Series[int], Series[float]],
_PeriodProperties,
_PeriodProperties[
Series[Timestamp], Series[int], Series[str], DatetimeArray, PeriodArray
],
): ...

@type_check_only
Expand Down Expand Up @@ -458,7 +461,7 @@ class DtDescriptor:
@overload
def __get__(
self, instance: Series[Period], owner: type[Series]
) -> PeriodProperties: ...
) -> PeriodProperties[Any]: ...

@type_check_only
class ArrayDescriptor:
Expand Down
7 changes: 2 additions & 5 deletions pandas-stubs/core/indexes/period.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from collections.abc import Hashable
import datetime
from typing import (
Any,
overload,
)
from typing import overload

import numpy as np
import pandas as pd
Expand All @@ -30,7 +27,7 @@ from pandas._typing import (
class PeriodIndex(DatetimeIndexOpsMixin[pd.Period, np.object_], PeriodIndexFieldOps):
def __new__(
cls,
data: AxesData[Any] | None = None,
data: AxesData | None = None,
freq: Frequency | None = None,
dtype: Dtype | None = None,
copy: bool = False,
Expand Down
4 changes: 2 additions & 2 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
Scalar
| _DataLike
| Mapping[HashableT1, Any]
| BaseGroupBy
| BaseGroupBy[Any]
| NaTType
| NAType
| None
Expand Down Expand Up @@ -1105,7 +1105,7 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
def swaplevel(
self, i: Level = -2, j: Level = -1, copy: _bool = True
) -> Series[S1]: ...
def reorder_levels(self, order: list[Any]) -> Series[S1]: ...
def reorder_levels(self, order: Sequence[int | np.integer]) -> Series[S1]: ...
def explode(self, ignore_index: _bool = ...) -> Series[S1]: ...
def unstack(
self,
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/io/html.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ from pandas._typing import (
def read_html(
io: FilePath | ReadBuffer[str],
*,
match: str | Pattern = ...,
match: str | Pattern[str] = ...,
flavor: HTMLFlavors | Sequence[HTMLFlavors] | None = ...,
header: int | Sequence[int] | None = ...,
index_col: int | Sequence[int] | list[HashableT1] | None = ...,
Expand Down
4 changes: 2 additions & 2 deletions pandas-stubs/io/sql.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ _SQLStatement: TypeAlias = (
str
| sqlalchemy.sql.expression.Selectable
| sqlalchemy.sql.expression.TextClause
| sqlalchemy.sql.Select
| FromStatement
| sqlalchemy.sql.Select[Any]
| FromStatement[Any]
| sqlalchemy.sql.expression.UpdateBase
)

Expand Down
3 changes: 2 additions & 1 deletion pandas-stubs/io/xml.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections.abc import Sequence
from typing import Any

from pandas.core.frame import DataFrame

Expand All @@ -25,7 +26,7 @@ def read_xml(
names: Sequence[str] | None = ...,
dtype: DtypeArg | None = ...,
converters: ConvertersArg | None = ...,
parse_dates: ParseDatesArg | None = ...,
parse_dates: ParseDatesArg[Any, Any] | None = ...,
# encoding can not be None for lxml and StringIO input
encoding: str | None = ...,
parser: XMLParsers = ...,
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/plotting/_core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class _BoxPlotT(NamedTuple):
_SingleColor: TypeAlias = (
str | list[float] | tuple[float, float, float] | tuple[float, float, float, float]
)
_PlotAccessorColor: TypeAlias = str | list[_SingleColor] | dict[HashableT, _SingleColor]
_PlotAccessorColor: TypeAlias = str | list[_SingleColor] | dict[Any, _SingleColor]

# Keep in sync with `DataFrame.boxplot`
@overload
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ include = ["tests", "pandas-stubs"]
enableTypeIgnoreComments = false # use pyright-specific ignores
# disable subset of strict
reportMissingParameterType = false
reportMissingTypeArgument = false
reportUnnecessaryTypeIgnoreComment = true
reportUnknownArgumentType = false
reportUnknownLambdaType = false
Expand Down
2 changes: 1 addition & 1 deletion tests/frame/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ def sum_mean(x: pd.DataFrame) -> float:
):
check(assert_type(df.groupby("col1").apply(lfunc), pd.Series), pd.Series)

def sum_to_list(x: pd.DataFrame) -> list:
def sum_to_list(x: pd.DataFrame) -> list[Any]:
return x.sum().tolist()

with pytest_warns_bounded(
Expand Down
1 change: 1 addition & 0 deletions tests/series/test_properties.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pyright: reportMissingTypeArgument=false
from typing import TYPE_CHECKING

import numpy as np
Expand Down
3 changes: 2 additions & 1 deletion tests/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import numpy as np
import pandas as pd
from pandas.core.arrays.interval import IntervalArray
from typing_extensions import assert_type

from tests import (
Expand Down Expand Up @@ -125,6 +126,6 @@ def test_interval_array_contains() -> None:
df = pd.DataFrame({"A": range(1, 10)})
obj = pd.Interval(1, 4)
ser = pd.Series(obj, index=df.index)
arr = ser.array
arr = check(assert_type(ser.array, IntervalArray), IntervalArray)
check(assert_type(arr.contains(df["A"]), "pd.Series[bool]"), pd.Series, np.bool_)
check(assert_type(arr.contains(3), np_1darray_bool), np_1darray_bool)
13 changes: 5 additions & 8 deletions tests/test_resampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@
from typing import TypeAlias

import numpy as np
import pandas as pd
from pandas import (
DataFrame,
Series,
date_range,
)
from pandas.core.frame import DataFrame
from pandas.core.groupby.generic import (
DataFrameGroupBy,
SeriesGroupBy,
)
from pandas.core.indexes.datetimes import date_range
from pandas.core.resample import DatetimeIndexResampler
from pandas.core.series import Series
from typing_extensions import assert_type

from tests import (
Expand Down Expand Up @@ -396,7 +393,7 @@ def f(val: Series) -> Series:

def test_aggregate_series_combinations() -> None:
def s2series(val: Series) -> Series:
return pd.Series(val)
return Series(val)

def s2scalar(val: Series) -> float:
return float(val.mean())
Expand All @@ -418,7 +415,7 @@ def s2scalar(val: Series) -> float:

def test_aggregate_frame_combinations() -> None:
def df2frame(val: DataFrame) -> DataFrame:
return pd.DataFrame(val)
return DataFrame(val)

def df2series(val: DataFrame) -> Series:
return val.mean()
Expand Down