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
4 changes: 3 additions & 1 deletion pandas-stubs/_libs/interval.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ VALID_CLOSED: frozenset[str]

_OrderableScalarT = TypeVar("_OrderableScalarT", bound=int | float)
_OrderableTimesT = TypeVar("_OrderableTimesT", bound=Timestamp | Timedelta)
_OrderableT = TypeVar("_OrderableT", bound=int | float | Timestamp | Timedelta)
_OrderableT = TypeVar(
"_OrderableT", bound=int | float | Timestamp | Timedelta, default=Any
)

@type_check_only
class _LengthDescriptor:
Expand Down
15 changes: 9 additions & 6 deletions pandas-stubs/_typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ XMLParsers: TypeAlias = Literal["lxml", "etree"]
HTMLFlavors: TypeAlias = Literal["lxml", "html5lib", "bs4"]

# Interval closed type
IntervalT = TypeVar("IntervalT", bound=Interval)
IntervalT = TypeVar("IntervalT", bound=Interval, default=Interval)
IntervalLeftRight: TypeAlias = Literal["left", "right"]
IntervalClosedType: TypeAlias = IntervalLeftRight | Literal["both", "neither"]

Expand Down Expand Up @@ -959,7 +959,10 @@ np_1darray_dt: TypeAlias = np_1darray[np.datetime64]
np_1darray_td: TypeAlias = np_1darray[np.timedelta64]
np_2darray: TypeAlias = np.ndarray[tuple[int, int], np.dtype[GenericT]]

NDArrayT = TypeVar("NDArrayT", bound=np.ndarray)
if sys.version_info >= (3, 11):
NDArrayT = TypeVar("NDArrayT", bound=np.ndarray)
else:
NDArrayT = TypeVar("NDArrayT", bound=np.ndarray[Any, Any])

DtypeNp = TypeVar("DtypeNp", bound=np.dtype[np.generic])
KeysArgType: TypeAlias = Any
Expand Down Expand Up @@ -1070,7 +1073,7 @@ if TYPE_CHECKING: # noqa: PYI002
| Scalar
| Period
| Interval[int | float | Timestamp | Timedelta]
| tuple,
| tuple[Any, ...],
)
# Use a distinct SeriesByT when using groupby with Series of known dtype.
# Essentially, an intersection between Series S1 TypeVar, and ByT TypeVar
Expand Down Expand Up @@ -1102,7 +1105,7 @@ GroupByObjectNonScalar: TypeAlias = (
| Grouper
| list[Grouper]
)
GroupByObject: TypeAlias = Scalar | Index | GroupByObjectNonScalar | Series
GroupByObject: TypeAlias = Scalar | Index | GroupByObjectNonScalar[_HashableTa] | Series

StataDateFormat: TypeAlias = Literal[
"tc",
Expand All @@ -1125,9 +1128,9 @@ StataDateFormat: TypeAlias = Literal[
# `DataFrame.replace` also accepts mappings of these.
ReplaceValue: TypeAlias = (
Scalar
| Pattern
| Pattern[Any]
| NAType
| Sequence[Scalar | Pattern]
| Sequence[Scalar | Pattern[Any]]
| Mapping[HashableT, ScalarT]
| Series
| None
Expand Down
10 changes: 8 additions & 2 deletions pandas-stubs/core/arrays/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ from collections.abc import (
Iterator,
Sequence,
)
import sys
from typing import (
Any,
Literal,
Expand Down Expand Up @@ -55,8 +56,13 @@ class ExtensionArray:
def ndim(self) -> int: ...
@property
def nbytes(self) -> int: ...
@overload
def astype(self, dtype: np.dtype, copy: bool = True) -> np_1darray: ...
if sys.version_info >= (3, 11):
@overload
def astype(self, dtype: np.dtype, copy: bool = True) -> np_1darray: ...
else:
@overload
def astype(self, dtype: np.dtype[Any], copy: bool = True) -> np_1darray: ...

@overload
def astype(self, dtype: ExtensionDtype, copy: bool = True) -> ExtensionArray: ...
@overload
Expand Down
11 changes: 9 additions & 2 deletions pandas-stubs/core/arrays/datetimes.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from datetime import tzinfo as _tzinfo
import sys
from typing import Any

import numpy as np
from pandas.core.arrays.datetimelike import (
Expand All @@ -19,8 +21,13 @@ class DatetimeArray(DatetimeLikeArrayMixin, TimelikeOps, DatelikeOps):
__array_priority__: int = ...
def __init__(self, values, dtype=..., freq=..., copy: bool = ...) -> None: ...
# ignore in dtype() is from the pandas source
@property
def dtype(self) -> np.dtype | DatetimeTZDtype: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
if sys.version_info >= (3, 11):
@property
def dtype(self) -> np.dtype | DatetimeTZDtype: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
else:
@property
def dtype(self) -> np.dtype[Any] | DatetimeTZDtype: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]

@property
def tz(self): ...
@tz.setter
Expand Down
12 changes: 10 additions & 2 deletions pandas-stubs/core/arrays/numpy_.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import sys
from typing import Any

import numpy as np
from numpy.lib.mixins import NDArrayOperatorsMixin
from pandas.core.arrays.base import (
Expand All @@ -8,8 +11,13 @@ from pandas.core.arrays.base import (
from pandas.core.dtypes.dtypes import ExtensionDtype

class PandasDtype(ExtensionDtype):
@property
def numpy_dtype(self) -> np.dtype: ...
if sys.version_info >= (3, 11):
@property
def numpy_dtype(self) -> np.dtype: ...
else:
@property
def numpy_dtype(self) -> np.dtype[Any]: ...

@property
def itemsize(self) -> int: ...

Expand Down
9 changes: 7 additions & 2 deletions pandas-stubs/core/computation/ops.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from typing import Any

import numpy as np
Expand Down Expand Up @@ -75,8 +76,12 @@ class UnaryOp(Op):
func = ...
def __init__(self, op: str, operand) -> None: ...
def __call__(self, env): ...
@property
def return_type(self) -> np.dtype: ...
if sys.version_info >= (3, 11):
@property
def return_type(self) -> np.dtype: ...
else:
@property
def return_type(self) -> np.dtype[Any]: ...

class MathCall(Op):
func = ...
Expand Down
28 changes: 21 additions & 7 deletions pandas-stubs/core/construction.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from collections.abc import Sequence
from typing import overload
import sys
from typing import (
Any,
overload,
)

import numpy as np
from pandas.core.arrays.base import ExtensionArray
Expand Down Expand Up @@ -40,9 +44,19 @@ def array(
dtype: PandasFloatDtypeArg | None = None,
copy: bool = True,
) -> FloatingArray: ...
@overload
def array(
data: Sequence[object],
dtype: str | np.dtype | ExtensionDtype | None = None,
copy: bool = True,
) -> ExtensionArray: ...

if sys.version_info >= (3, 11):
@overload
def array(
data: Sequence[object],
dtype: str | np.dtype | ExtensionDtype | None = None,
copy: bool = True,
) -> ExtensionArray: ...

else:
@overload
def array(
data: Sequence[object],
dtype: str | np.dtype[Any] | ExtensionDtype | None = None,
copy: bool = True,
) -> ExtensionArray: ...
9 changes: 7 additions & 2 deletions pandas-stubs/core/dtypes/dtypes.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime as dt
import sys
from typing import (
Any,
Literal,
Expand Down Expand Up @@ -59,5 +60,9 @@ class PeriodDtype(PandasExtensionDtype):

class IntervalDtype(PandasExtensionDtype):
def __init__(self, subtype: str | npt.DTypeLike | None = ...) -> None: ...
@property
def subtype(self) -> np.dtype | None: ...
if sys.version_info >= (3, 11):
@property
def subtype(self) -> np.dtype | None: ...
else:
@property
def subtype(self) -> np.dtype[Any] | None: ...
Loading
Loading