Skip to content

Commit 271cf8d

Browse files
Merge branch 'main' of github.com:loicdiridollou/pandas-stubs into gh1173_query
2 parents 36bc58e + cbb6723 commit 271cf8d

26 files changed

+840
-202
lines changed

pandas-stubs/_typing.pyi

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ from pandas.core.generic import NDFrame
3131
from pandas.core.groupby.grouper import Grouper
3232
from pandas.core.indexes.base import Index
3333
from pandas.core.series import Series
34+
from pandas.core.tools.datetimes import FulldatetimeDict
3435
from typing_extensions import (
3536
ParamSpec,
3637
TypeAlias,
@@ -73,22 +74,6 @@ DatetimeDictArg: TypeAlias = (
7374
)
7475
DictConvertible: TypeAlias = FulldatetimeDict | DataFrame
7576

76-
class YearMonthDayDict(TypedDict, total=True):
77-
year: DatetimeDictArg
78-
month: DatetimeDictArg
79-
day: DatetimeDictArg
80-
81-
class FulldatetimeDict(YearMonthDayDict, total=False):
82-
hour: DatetimeDictArg
83-
hours: DatetimeDictArg
84-
minute: DatetimeDictArg
85-
minutes: DatetimeDictArg
86-
second: DatetimeDictArg
87-
seconds: DatetimeDictArg
88-
ms: DatetimeDictArg
89-
us: DatetimeDictArg
90-
ns: DatetimeDictArg
91-
9277
CorrelationMethod: TypeAlias = (
9378
Literal["pearson", "kendall", "spearman"]
9479
| Callable[[np.ndarray, np.ndarray], float]
@@ -518,7 +503,9 @@ IndexIterScalar: TypeAlias = (
518503
| Timestamp
519504
| Timedelta
520505
)
521-
Scalar: TypeAlias = IndexIterScalar | complex
506+
Scalar: TypeAlias = (
507+
IndexIterScalar | complex | np.integer | np.floating | np.complexfloating
508+
)
522509
ScalarT = TypeVar("ScalarT", bound=Scalar)
523510
# Refine the definitions below in 3.9 to use the specialized type.
524511
np_ndarray_int64: TypeAlias = npt.NDArray[np.int64]
@@ -624,7 +611,7 @@ CompressionOptions: TypeAlias = (
624611
FormattersType: TypeAlias = (
625612
list[Callable] | tuple[Callable, ...] | Mapping[str | int, Callable]
626613
)
627-
FloatFormatType: TypeAlias = str | Callable | EngFormatter
614+
FloatFormatType: TypeAlias = str | Callable[[float], str] | EngFormatter
628615
# converters
629616
ConvertersArg: TypeAlias = dict[Hashable, Callable[[Dtype], Dtype]]
630617

pandas-stubs/core/frame.pyi

Lines changed: 94 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ from typing import (
1818
overload,
1919
)
2020

21-
from _typing import TimeZones
21+
from _typing import (
22+
FloatFormatType,
23+
TimeZones,
24+
)
2225
from matplotlib.axes import Axes as PlotAxes
2326
import numpy as np
2427
from pandas import (
@@ -67,6 +70,7 @@ from pandas._libs.lib import NoDefault
6770
from pandas._libs.missing import NAType
6871
from pandas._libs.tslibs import BaseOffset
6972
from pandas._libs.tslibs.nattype import NaTType
73+
from pandas._libs.tslibs.offsets import DateOffset
7074
from pandas._typing import (
7175
S1,
7276
AggFuncTypeBase,
@@ -87,7 +91,6 @@ from pandas._typing import (
8791
FilePath,
8892
FillnaOptions,
8993
FormattersType,
90-
Frequency,
9194
GroupByObjectNonScalar,
9295
HashableT,
9396
HashableT1,
@@ -173,7 +176,16 @@ class _iLocIndexerFrame(_iLocIndexer, Generic[_T]):
173176
| tuple[IndexType, IndexType]
174177
| tuple[int, IndexType]
175178
),
176-
value: Scalar | Series | DataFrame | np.ndarray | NAType | NaTType | None,
179+
value: (
180+
Scalar
181+
| Series
182+
| DataFrame
183+
| np.ndarray
184+
| NAType
185+
| NaTType
186+
| Mapping[Hashable, Scalar | NAType | NaTType]
187+
| None
188+
),
177189
) -> None: ...
178190

179191
class _LocIndexerFrame(_LocIndexer, Generic[_T]):
@@ -236,13 +248,23 @@ class _LocIndexerFrame(_LocIndexer, Generic[_T]):
236248
idx: (
237249
MaskType | StrLike | _IndexSliceTuple | list[ScalarT] | IndexingInt | slice
238250
),
239-
value: Scalar | NAType | NaTType | ArrayLike | Series | DataFrame | list | None,
251+
value: (
252+
Scalar
253+
| NAType
254+
| NaTType
255+
| ArrayLike
256+
| Series
257+
| DataFrame
258+
| list
259+
| Mapping[Hashable, Scalar | NAType | NaTType]
260+
| None
261+
),
240262
) -> None: ...
241263
@overload
242264
def __setitem__(
243265
self,
244266
idx: tuple[_IndexSliceTuple, Hashable],
245-
value: Scalar | NAType | NaTType | ArrayLike | Series | list | None,
267+
value: Scalar | NAType | NaTType | ArrayLike | Series | list | dict | None,
246268
) -> None: ...
247269

248270
# With mypy 1.14.1 and python 3.12, the second overload needs a type-ignore statement
@@ -844,10 +866,10 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
844866
) -> Self: ...
845867
def shift(
846868
self,
847-
periods: int = ...,
848-
freq: Frequency | dt.timedelta | None = ...,
869+
periods: int | Sequence[int] = ...,
870+
freq: DateOffset | dt.timedelta | _str | None = ...,
849871
axis: Axis = ...,
850-
fill_value: Hashable | None = ...,
872+
fill_value: Scalar | NAType | None = ...,
851873
) -> Self: ...
852874
@overload
853875
def set_index(
@@ -1749,23 +1771,73 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
17491771
@overload
17501772
def clip(
17511773
self,
1752-
lower: float | AnyArrayLike | None = ...,
1753-
upper: float | AnyArrayLike | None = ...,
1774+
lower: float | None = ...,
1775+
upper: float | None = ...,
17541776
*,
17551777
axis: Axis | None = ...,
1756-
inplace: Literal[True],
1778+
inplace: Literal[False] = ...,
17571779
**kwargs: Any,
1758-
) -> None: ...
1780+
) -> Self: ...
17591781
@overload
17601782
def clip(
17611783
self,
1762-
lower: float | AnyArrayLike | None = ...,
1763-
upper: float | AnyArrayLike | None = ...,
1784+
lower: AnyArrayLike = ...,
1785+
upper: AnyArrayLike | None = ...,
17641786
*,
1765-
axis: Axis | None = ...,
1787+
axis: Axis = ...,
1788+
inplace: Literal[False] = ...,
1789+
**kwargs: Any,
1790+
) -> Self: ...
1791+
@overload
1792+
def clip(
1793+
self,
1794+
lower: AnyArrayLike | None = ...,
1795+
upper: AnyArrayLike = ...,
1796+
*,
1797+
axis: Axis = ...,
17661798
inplace: Literal[False] = ...,
17671799
**kwargs: Any,
17681800
) -> Self: ...
1801+
@overload
1802+
def clip( # pyright: ignore[reportOverlappingOverload]
1803+
self,
1804+
lower: None = ...,
1805+
upper: None = ...,
1806+
*,
1807+
axis: Axis | None = ...,
1808+
inplace: Literal[True],
1809+
**kwargs: Any,
1810+
) -> Self: ...
1811+
@overload
1812+
def clip(
1813+
self,
1814+
lower: float | None = ...,
1815+
upper: float | None = ...,
1816+
*,
1817+
axis: Axis | None = ...,
1818+
inplace: Literal[True],
1819+
**kwargs: Any,
1820+
) -> None: ...
1821+
@overload
1822+
def clip(
1823+
self,
1824+
lower: AnyArrayLike = ...,
1825+
upper: AnyArrayLike | None = ...,
1826+
*,
1827+
axis: Axis = ...,
1828+
inplace: Literal[True],
1829+
**kwargs: Any,
1830+
) -> None: ...
1831+
@overload
1832+
def clip(
1833+
self,
1834+
lower: AnyArrayLike | None = ...,
1835+
upper: AnyArrayLike = ...,
1836+
*,
1837+
axis: Axis = ...,
1838+
inplace: Literal[True],
1839+
**kwargs: Any,
1840+
) -> None: ...
17691841
def copy(self, deep: _bool = ...) -> Self: ...
17701842
def cummax(
17711843
self, axis: Axis | None = ..., skipna: _bool = ..., *args: Any, **kwargs: Any
@@ -2003,9 +2075,10 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
20032075
self,
20042076
periods: int = ...,
20052077
fill_method: None = ...,
2006-
limit: int | None = ...,
2007-
freq=...,
2008-
**kwargs: Any, # TODO: make more precise https://github.com/pandas-dev/pandas-stubs/issues/1169
2078+
freq: DateOffset | dt.timedelta | _str | None = ...,
2079+
*,
2080+
axis: Axis = ...,
2081+
fill_value: Scalar | NAType | None = ...,
20092082
) -> Self: ...
20102083
def pop(self, item: _str) -> Series: ...
20112084
def pow(
@@ -2204,7 +2277,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
22042277
numeric_only: _bool = ...,
22052278
**kwargs: Any,
22062279
) -> Series: ...
2207-
def squeeze(self, axis: Axis | None = ...): ...
2280+
def squeeze(self, axis: Axis | None = ...) -> DataFrame | Series | Scalar: ...
22082281
def std(
22092282
self,
22102283
axis: Axis = ...,
@@ -2240,12 +2313,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
22402313
def swapaxes(self, axis1: Axis, axis2: Axis, copy: _bool = ...) -> Self: ...
22412314
def tail(self, n: int = ...) -> Self: ...
22422315
def take(self, indices: list, axis: Axis = ..., **kwargs: Any) -> Self: ...
2243-
def to_clipboard(
2244-
self,
2245-
excel: _bool = ...,
2246-
sep: _str | None = ...,
2247-
**kwargs: Any, # TODO: make more precise https://github.com/pandas-dev/pandas-stubs/issues/1174
2248-
) -> None: ...
22492316
@overload
22502317
def to_json(
22512318
self,
@@ -2330,7 +2397,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
23302397
index: _bool = ...,
23312398
na_rep: _str = ...,
23322399
formatters: FormattersType | None = ...,
2333-
float_format: Callable[[float], str] | None = ...,
2400+
float_format: FloatFormatType | None = ...,
23342401
sparsify: _bool | None = ...,
23352402
index_names: _bool = ...,
23362403
justify: _str | None = ...,
@@ -2353,7 +2420,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
23532420
index: _bool = ...,
23542421
na_rep: _str = ...,
23552422
formatters: FormattersType | None = ...,
2356-
float_format: Callable[[float], str] | None = ...,
2423+
float_format: FloatFormatType | None = ...,
23572424
sparsify: _bool | None = ...,
23582425
index_names: _bool = ...,
23592426
justify: _str | None = ...,

pandas-stubs/core/generic.pyi

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,29 @@ class NDFrame(indexing.IndexingMixin):
179179
storage_options: StorageOptions = ...,
180180
) -> None: ...
181181
def to_clipboard(
182-
self, excel: _bool = ..., sep: _str | None = ..., **kwargs
182+
self,
183+
excel: _bool = ...,
184+
sep: _str | None = ...,
185+
*,
186+
na_rep: _str = ...,
187+
float_format: _str | Callable[[object], _str] | None = ...,
188+
columns: list[HashableT1] | None = ...,
189+
header: _bool | list[_str] = ...,
190+
index: _bool = ...,
191+
index_label: Literal[False] | _str | list[HashableT2] | None = ...,
192+
mode: FileWriteMode = ...,
193+
encoding: _str | None = ...,
194+
compression: CompressionOptions = ...,
195+
quoting: CSVQuoting = ...,
196+
quotechar: _str = ...,
197+
lineterminator: _str | None = ...,
198+
chunksize: int | None = ...,
199+
date_format: _str | None = ...,
200+
doublequote: _bool = ...,
201+
escapechar: _str | None = ...,
202+
decimal: _str = ...,
203+
errors: _str = ...,
204+
storage_options: StorageOptions = ...,
183205
) -> None: ...
184206
@overload
185207
def to_latex(

0 commit comments

Comments
 (0)