Skip to content
Draft
38 changes: 38 additions & 0 deletions pandas-stubs/_libs/arrays.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from collections.abc import Sequence
from typing import Any

import numpy as np
from typing_extensions import Self

from pandas._typing import (
AnyArrayLikeInt,
AxisInt,
DtypeObj,
Shape,
)

class NDArrayBacked:
_dtype: DtypeObj
_ndarray: np.ndarray
def __setstate__(self, state: Any) -> None: ...
def __len__(self) -> int: ...
@property
def shape(self) -> Shape: ...
@property
def ndim(self) -> int: ...
@property
def size(self) -> int: ...
@property
def nbytes(self) -> int: ...
def copy(self, order=...) -> Self: ...
def delete(self, loc, axis=...) -> Self: ...
def swapaxes(self, axis1, axis2) -> Self: ...
def repeat(
self,
repeats: int | Sequence[int] | AnyArrayLikeInt,
axis: AxisInt | None = None,
) -> Self: ...
def reshape(self, *args: Any, **kwargs: Any) -> Self: ...
def ravel(self, order=...) -> Self: ...
@property
def T(self) -> Self: ...
243 changes: 131 additions & 112 deletions pandas-stubs/_typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ Dtype: TypeAlias = ExtensionDtype | NpDtype
# m
# datetime64

# PyArrow boolean type and its string alias
PyArrowBooleanDtypeArg: TypeAlias = Literal["bool[pyarrow]", "boolean[pyarrow]"]
BooleanDtypeArg: TypeAlias = (
# Builtin bool type and its string alias
type[bool] # noqa: PYI030
Expand All @@ -235,9 +237,12 @@ BooleanDtypeArg: TypeAlias = (
# https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.bool_
| type[np.bool_]
| Literal["?", "b1", "bool_"]
# PyArrow boolean type and its string alias
| Literal["bool[pyarrow]", "boolean[pyarrow]"]
| PyArrowBooleanDtypeArg
)
# PyArrow integer types and their string aliases
PyArrowIntDtypeArg: TypeAlias = Literal[
"int8[pyarrow]", "int16[pyarrow]", "int32[pyarrow]", "int64[pyarrow]"
]
IntDtypeArg: TypeAlias = (
# Builtin integer type and its string alias
type[int] # noqa: PYI030
Expand Down Expand Up @@ -267,9 +272,12 @@ IntDtypeArg: TypeAlias = (
# https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.intp
| type[np.intp] # signed pointer (=`intptr_t`, platform dependent)
| Literal["p", "intp"]
# PyArrow integer types and their string aliases
| Literal["int8[pyarrow]", "int16[pyarrow]", "int32[pyarrow]", "int64[pyarrow]"]
| PyArrowIntDtypeArg
)
# PyArrow unsigned integer types and their string aliases
PyArrowUIntDtypeArg: TypeAlias = Literal[
"uint8[pyarrow]", "uint16[pyarrow]", "uint32[pyarrow]", "uint64[pyarrow]"
]
UIntDtypeArg: TypeAlias = (
# Pandas nullable unsigned integer types and their string aliases
pd.UInt8Dtype # noqa: PYI030
Expand All @@ -296,9 +304,16 @@ UIntDtypeArg: TypeAlias = (
# https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.uintp
| type[np.uintp] # unsigned pointer (=`uintptr_t`, platform dependent)
| Literal["P", "uintp"]
# PyArrow unsigned integer types and their string aliases
| Literal["uint8[pyarrow]", "uint16[pyarrow]", "uint32[pyarrow]", "uint64[pyarrow]"]
| PyArrowUIntDtypeArg
)
# PyArrow floating point types and their string aliases
PyArrowFloatDtypeArg: TypeAlias = Literal[
"float[pyarrow]",
"double[pyarrow]",
"float16[pyarrow]",
"float32[pyarrow]",
"float64[pyarrow]",
]
FloatDtypeArg: TypeAlias = (
# Builtin float type and its string alias
type[float] # noqa: PYI030
Expand All @@ -321,14 +336,7 @@ FloatDtypeArg: TypeAlias = (
# https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.longdouble
| type[np.longdouble]
| Literal["g", "f16", "float128", "longdouble", "longfloat"]
# PyArrow floating point types and their string aliases
| Literal[
"float[pyarrow]",
"double[pyarrow]",
"float16[pyarrow]",
"float32[pyarrow]",
"float64[pyarrow]",
]
| PyArrowFloatDtypeArg
)
ComplexDtypeArg: TypeAlias = (
# Builtin complex type and its string alias
Expand All @@ -353,112 +361,123 @@ ComplexDtypeArg: TypeAlias = (
"longcomplex",
]
)
# Refer to https://numpy.org/doc/stable/reference/arrays.datetime.html#datetime-units
TimedeltaDtypeArg: TypeAlias = Literal[
"timedelta64[Y]",
"timedelta64[M]",
"timedelta64[W]",
"timedelta64[D]",
"timedelta64[h]",
"timedelta64[m]",
"timedelta64[s]",
"timedelta64[ms]",
"timedelta64[us]",
"timedelta64[μs]",
"timedelta64[ns]",
"timedelta64[ps]",
"timedelta64[fs]",
"timedelta64[as]",
# numpy type codes
"m8[Y]",
"m8[M]",
"m8[W]",
"m8[D]",
"m8[h]",
"m8[m]",
"m8[s]",
"m8[ms]",
"m8[us]",
"m8[μs]",
"m8[ns]",
"m8[ps]",
"m8[fs]",
"m8[as]",
# little endian
"<m8[Y]",
"<m8[M]",
"<m8[W]",
"<m8[D]",
"<m8[h]",
"<m8[m]",
"<m8[s]",
"<m8[ms]",
"<m8[us]",
"<m8[μs]",
"<m8[ns]",
"<m8[ps]",
"<m8[fs]",
"<m8[as]",
# PyArrow duration type and its string alias
# PyArrow duration type and its string alias
PyArrowTimedeltaDtypeArg: TypeAlias = Literal[
"duration[s][pyarrow]",
"duration[ms][pyarrow]",
"duration[us][pyarrow]",
"duration[ns][pyarrow]",
]
TimestampDtypeArg: TypeAlias = Literal[
"datetime64[Y]",
"datetime64[M]",
"datetime64[W]",
"datetime64[D]",
"datetime64[h]",
"datetime64[m]",
"datetime64[s]",
"datetime64[ms]",
"datetime64[us]",
"datetime64[μs]",
"datetime64[ns]",
"datetime64[ps]",
"datetime64[fs]",
"datetime64[as]",
# numpy type codes
"M8[Y]",
"M8[M]",
"M8[W]",
"M8[D]",
"M8[h]",
"M8[m]",
"M8[s]",
"M8[ms]",
"M8[us]",
"M8[μs]",
"M8[ns]",
"M8[ps]",
"M8[fs]",
"M8[as]",
# little endian
"<M8[Y]",
"<M8[M]",
"<M8[W]",
"<M8[D]",
"<M8[h]",
"<M8[m]",
"<M8[s]",
"<M8[ms]",
"<M8[us]",
"<M8[μs]",
"<M8[ns]",
"<M8[ps]",
"<M8[fs]",
"<M8[as]",
# PyArrow timestamp type and its string alias
# Refer to https://numpy.org/doc/stable/reference/arrays.datetime.html#datetime-units
TimedeltaDtypeArg: TypeAlias = (
Literal[
"timedelta64[Y]",
"timedelta64[M]",
"timedelta64[W]",
"timedelta64[D]",
"timedelta64[h]",
"timedelta64[m]",
"timedelta64[s]",
"timedelta64[ms]",
"timedelta64[us]",
"timedelta64[μs]",
"timedelta64[ns]",
"timedelta64[ps]",
"timedelta64[fs]",
"timedelta64[as]",
# numpy type codes
"m8[Y]",
"m8[M]",
"m8[W]",
"m8[D]",
"m8[h]",
"m8[m]",
"m8[s]",
"m8[ms]",
"m8[us]",
"m8[μs]",
"m8[ns]",
"m8[ps]",
"m8[fs]",
"m8[as]",
# little endian
"<m8[Y]",
"<m8[M]",
"<m8[W]",
"<m8[D]",
"<m8[h]",
"<m8[m]",
"<m8[s]",
"<m8[ms]",
"<m8[us]",
"<m8[μs]",
"<m8[ns]",
"<m8[ps]",
"<m8[fs]",
"<m8[as]",
]
| PyArrowTimedeltaDtypeArg
)
# PyArrow timestamp type and its string alias
PyArrowTimestampDtypeArg: TypeAlias = Literal[
"date32[pyarrow]",
"date64[pyarrow]",
"timestamp[s][pyarrow]",
"timestamp[ms][pyarrow]",
"timestamp[us][pyarrow]",
"timestamp[ns][pyarrow]",
]

TimestampDtypeArg: TypeAlias = (
Literal[
"datetime64[Y]",
"datetime64[M]",
"datetime64[W]",
"datetime64[D]",
"datetime64[h]",
"datetime64[m]",
"datetime64[s]",
"datetime64[ms]",
"datetime64[us]",
"datetime64[μs]",
"datetime64[ns]",
"datetime64[ps]",
"datetime64[fs]",
"datetime64[as]",
# numpy type codes
"M8[Y]",
"M8[M]",
"M8[W]",
"M8[D]",
"M8[h]",
"M8[m]",
"M8[s]",
"M8[ms]",
"M8[us]",
"M8[μs]",
"M8[ns]",
"M8[ps]",
"M8[fs]",
"M8[as]",
# little endian
"<M8[Y]",
"<M8[M]",
"<M8[W]",
"<M8[D]",
"<M8[h]",
"<M8[m]",
"<M8[s]",
"<M8[ms]",
"<M8[us]",
"<M8[μs]",
"<M8[ns]",
"<M8[ps]",
"<M8[fs]",
"<M8[as]",
]
| PyArrowTimestampDtypeArg
)
# PyArrow string type and its string alias
PyArrowStrDtypeArg: TypeAlias = Literal["string[pyarrow]"]
StrDtypeArg: TypeAlias = (
# Builtin str type and its string alias
type[str] # noqa: PYI030
Expand All @@ -470,9 +489,10 @@ StrDtypeArg: TypeAlias = (
# https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.str_
| type[np.str_]
| Literal["U", "str_", "str0", "unicode", "unicode_"]
# PyArrow string type and its string alias
| Literal["string[pyarrow]"]
| PyArrowStrDtypeArg
)
# PyArrow binary type and its string alias
PyArrowBytesDtypeArg: TypeAlias = Literal["binary[pyarrow]"]
BytesDtypeArg: TypeAlias = (
# Builtin bytes type and its string alias
type[bytes] # noqa: PYI030
Expand All @@ -481,8 +501,7 @@ BytesDtypeArg: TypeAlias = (
# https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.bytes_
| type[np.bytes_]
| Literal["S", "bytes_", "bytes0", "string_"]
# PyArrow binary type and its string alias
| Literal["binary[pyarrow]"]
| PyArrowBytesDtypeArg
)
CategoryDtypeArg: TypeAlias = CategoricalDtype | Literal["category"]

Expand Down
39 changes: 29 additions & 10 deletions pandas-stubs/arrays/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
from pandas.core.arrays import (
BooleanArray as BooleanArray,
Categorical as Categorical,
DatetimeArray as DatetimeArray,
IntegerArray as IntegerArray,
IntervalArray as IntervalArray,
PandasArray as PandasArray,
PeriodArray as PeriodArray,
SparseArray as SparseArray,
StringArray as StringArray,
TimedeltaArray as TimedeltaArray,
ArrowExtensionArray,
ArrowStringArray,
BooleanArray,
Categorical,
DatetimeArray,
FloatingArray,
IntegerArray,
IntervalArray,
NumpyExtensionArray,
PeriodArray,
SparseArray,
StringArray,
TimedeltaArray,
)

__all__ = [
"ArrowExtensionArray",
"ArrowStringArray",
"BooleanArray",
"Categorical",
"DatetimeArray",
"FloatingArray",
"IntegerArray",
"IntervalArray",
"NumpyExtensionArray",
"PeriodArray",
"SparseArray",
"StringArray",
"TimedeltaArray",
]
Loading