Skip to content

Commit ace58ea

Browse files
authored
Add defaults for parameters (#1293)
* add defaults for parameters * add more defaults * fix type errors * add more defaults * fix deprecated function * apply defaults from source code * address some comments and fix mypy * remove fill_value from tests * address some comments * address more comments * address more comments * fix broken tests * remove top level to_pickle * restore DateTimeIndex methods * change isoformat and add type ignore * address comments * fix freq param in DataFrame.shift and Series.shift * fix add, radd, truediv, rtruediv
1 parent 51d30a9 commit ace58ea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1282
-1242
lines changed

pandas-stubs/__init__.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ from pandas.io.api import (
119119
read_stata as read_stata,
120120
read_table as read_table,
121121
read_xml as read_xml,
122-
to_pickle as to_pickle,
123122
)
124123
from pandas.io.json._normalize import json_normalize as json_normalize
125124
from pandas.tseries import offsets as offsets

pandas-stubs/_libs/lib.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ class _NoDefault(Enum):
1616
no_default: Final = _NoDefault.no_default
1717
_NoDefaultDoNotUse: TypeAlias = Literal[_NoDefault.no_default] # noqa: PYI047
1818

19-
def infer_dtype(value: object, skipna: bool = ...) -> str: ...
19+
def infer_dtype(value: object, skipna: bool = True) -> str: ...
2020
def is_iterator(obj: object) -> bool: ...
2121
def is_scalar(val: object) -> bool: ...
22-
def is_list_like(obj: object, allow_sets: bool = ...) -> bool: ...
22+
def is_list_like(obj: object, allow_sets: bool = True) -> bool: ...
2323
def is_complex(val: object) -> TypeGuard[complex]: ...
2424
def is_bool(val: object) -> TypeGuard[bool | np.bool_]: ...
2525
def is_integer(val: object) -> TypeGuard[int | np.integer]: ...

pandas-stubs/_libs/tslibs/nattype.pyi

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,34 +74,34 @@ class NaTType:
7474
def weekday(self) -> float: ...
7575
def isoweekday(self) -> float: ...
7676
def total_seconds(self) -> float: ...
77-
def today(self, tz: _tzinfo | str | None = ...) -> NaTType: ...
78-
def now(self, tz: _tzinfo | str | None = ...) -> NaTType: ...
77+
def today(self, tz: _tzinfo | str | None = None) -> NaTType: ...
78+
def now(self, tz: _tzinfo | str | None = None) -> NaTType: ...
7979
def to_pydatetime(self) -> NaTType: ...
8080
def date(self) -> NaTType: ...
8181
def round(
8282
self,
8383
freq: Frequency,
84-
ambiguous: bool | Literal["raise"] | NaTType = ...,
85-
nonexistent: TimestampNonexistent = ...,
84+
ambiguous: bool | Literal["raise"] | NaTType = "raise",
85+
nonexistent: TimestampNonexistent = "raise",
8686
) -> NaTType: ...
8787
def floor(
8888
self,
8989
freq: Frequency,
90-
ambiguous: bool | Literal["raise"] | NaTType = ...,
91-
nonexistent: TimestampNonexistent = ...,
90+
ambiguous: bool | Literal["raise"] | NaTType = "raise",
91+
nonexistent: TimestampNonexistent = "raise",
9292
) -> NaTType: ...
9393
def ceil(
9494
self,
9595
freq: Frequency,
96-
ambiguous: bool | Literal["raise"] | NaTType = ...,
97-
nonexistent: TimestampNonexistent = ...,
96+
ambiguous: bool | Literal["raise"] | NaTType = "raise",
97+
nonexistent: TimestampNonexistent = "raise",
9898
) -> NaTType: ...
9999
def tz_convert(self) -> NaTType: ...
100100
def tz_localize(
101101
self,
102102
tz: _tzinfo | str | None,
103-
ambiguous: bool | Literal["raise"] | NaTType = ...,
104-
nonexistent: TimestampNonexistent = ...,
103+
ambiguous: bool | Literal["raise"] | NaTType = "raise",
104+
nonexistent: TimestampNonexistent = "raise",
105105
) -> NaTType: ...
106106
def replace(
107107
self,
@@ -154,4 +154,4 @@ class NaTType:
154154
__ge__: _NatComparison
155155
@property
156156
def unit(self) -> TimeUnit: ...
157-
def as_unit(self, unit: TimeUnit, round_ok: bool = ...) -> Self: ...
157+
def as_unit(self, unit: TimeUnit, round_ok: bool = True) -> Self: ...

pandas-stubs/_libs/tslibs/period.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,12 @@ class Period(PeriodMixin):
197197
def day_of_year(self) -> int: ...
198198
@property
199199
def day_of_week(self) -> int: ...
200-
def asfreq(self, freq: str | BaseOffset, how: _PeriodFreqHow = ...) -> Period: ...
200+
def asfreq(self, freq: str | BaseOffset, how: _PeriodFreqHow = "end") -> Period: ...
201201
@classmethod
202202
def now(cls, freq: str | BaseOffset = ...) -> Period: ...
203203
def strftime(self, fmt: str) -> str: ...
204204
def to_timestamp(
205205
self,
206206
freq: str | BaseOffset | None = ...,
207-
how: _PeriodToTimestampHow = ...,
207+
how: _PeriodToTimestampHow = "S",
208208
) -> Timestamp: ...

pandas-stubs/_libs/tslibs/timedeltas.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,4 +388,4 @@ class Timedelta(timedelta):
388388
def view(self, dtype: npt.DTypeLike = ...) -> object: ...
389389
@property
390390
def unit(self) -> TimeUnit: ...
391-
def as_unit(self, unit: TimeUnit, round_ok: bool = ...) -> Self: ...
391+
def as_unit(self, unit: TimeUnit, round_ok: bool = True) -> Self: ...

pandas-stubs/_libs/tslibs/timestamps.pyi

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,15 @@ class Timestamp(datetime, SupportsIndex):
115115
@classmethod
116116
def utcfromtimestamp(cls, ts: float) -> Self: ...
117117
@classmethod
118-
def today(cls, tz: _tzinfo | str | None = ...) -> Self: ...
118+
def today(cls, tz: _tzinfo | str | None = None) -> Self: ...
119119
@classmethod
120120
def fromordinal(
121121
cls,
122122
ordinal: int,
123123
tz: _tzinfo | str | None = ...,
124124
) -> Self: ...
125125
@classmethod
126-
def now(cls, tz: _tzinfo | str | None = ...) -> Self: ...
126+
def now(cls, tz: _tzinfo | str | None = None) -> Self: ...
127127
@classmethod
128128
def utcnow(cls) -> Self: ...
129129
# error: Signature of "combine" incompatible with supertype "datetime"
@@ -157,7 +157,19 @@ class Timestamp(datetime, SupportsIndex):
157157
) -> Timestamp: ...
158158
def astimezone(self, tz: _tzinfo | None = ...) -> Self: ...
159159
def ctime(self) -> str: ...
160-
def isoformat(self, sep: str = ..., timespec: str = ...) -> str: ...
160+
def isoformat( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
161+
self,
162+
sep: str = "T",
163+
timespec: Literal[
164+
"auto",
165+
"hours",
166+
"minutes",
167+
"seconds",
168+
"milliseconds",
169+
"microseconds",
170+
"nanoseconds",
171+
] = "auto",
172+
) -> str: ...
161173
@classmethod
162174
def strptime(cls, date_string: Never, format: Never) -> Never: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
163175
def utcoffset(self) -> timedelta | None: ...
@@ -276,31 +288,31 @@ class Timestamp(datetime, SupportsIndex):
276288
def tz_localize(
277289
self,
278290
tz: TimeZones,
279-
ambiguous: _Ambiguous = ...,
280-
nonexistent: TimestampNonexistent = ...,
291+
ambiguous: _Ambiguous = "raise",
292+
nonexistent: TimestampNonexistent = "raise",
281293
) -> Self: ...
282294
def normalize(self) -> Self: ...
283295
# TODO: round/floor/ceil could return NaT?
284296
def round(
285297
self,
286298
freq: str,
287-
ambiguous: _Ambiguous = ...,
288-
nonexistent: TimestampNonexistent = ...,
299+
ambiguous: _Ambiguous = "raise",
300+
nonexistent: TimestampNonexistent = "raise",
289301
) -> Self: ...
290302
def floor(
291303
self,
292304
freq: str,
293-
ambiguous: _Ambiguous = ...,
294-
nonexistent: TimestampNonexistent = ...,
305+
ambiguous: _Ambiguous = "raise",
306+
nonexistent: TimestampNonexistent = "raise",
295307
) -> Self: ...
296308
def ceil(
297309
self,
298310
freq: str,
299-
ambiguous: _Ambiguous = ...,
300-
nonexistent: TimestampNonexistent = ...,
311+
ambiguous: _Ambiguous = "raise",
312+
nonexistent: TimestampNonexistent = "raise",
301313
) -> Self: ...
302-
def day_name(self, locale: str | None = ...) -> str: ...
303-
def month_name(self, locale: str | None = ...) -> str: ...
314+
def day_name(self, locale: str | None = None) -> str: ...
315+
def month_name(self, locale: str | None = None) -> str: ...
304316
@property
305317
def day_of_week(self) -> int: ...
306318
@property
@@ -322,6 +334,6 @@ class Timestamp(datetime, SupportsIndex):
322334
def daysinmonth(self) -> int: ...
323335
@property
324336
def unit(self) -> TimeUnit: ...
325-
def as_unit(self, unit: TimeUnit, round_ok: bool = ...) -> Self: ...
337+
def as_unit(self, unit: TimeUnit, round_ok: bool = True) -> Self: ...
326338
# To support slicing
327339
def __index__(self) -> int: ...

pandas-stubs/_testing/__init__.pyi

Lines changed: 59 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ from collections.abc import (
55
)
66
from contextlib import contextmanager
77
from typing import (
8-
Any,
98
Literal,
109
overload,
1110
)
@@ -36,29 +35,29 @@ from pandas._typing import (
3635
def assert_almost_equal(
3736
left: T,
3837
right: T,
39-
check_dtype: bool | Literal["equiv"] = ...,
40-
rtol: float = ...,
41-
atol: float = ...,
38+
check_dtype: bool | Literal["equiv"] = "equiv",
39+
rtol: float = 1e-5,
40+
atol: float = 1e-8,
4241
**kwargs,
4342
) -> None: ...
44-
def assert_dict_equal(left: dict, right: dict, compare_keys: bool = ...) -> None: ...
43+
def assert_dict_equal(left: dict, right: dict, compare_keys: bool = True) -> None: ...
4544
def assert_index_equal(
4645
left: Index,
4746
right: Index,
48-
exact: bool | Literal["equiv"] = ...,
49-
check_names: bool = ...,
50-
check_exact: bool = ...,
51-
check_categorical: bool = ...,
52-
check_order: bool = ...,
53-
rtol: float = ...,
54-
atol: float = ...,
55-
obj: str = ...,
47+
exact: bool | Literal["equiv"] = "equiv",
48+
check_names: bool = True,
49+
check_exact: bool = True,
50+
check_categorical: bool = True,
51+
check_order: bool = True,
52+
rtol: float = 1e-5,
53+
atol: float = 1e-8,
54+
obj: str = "Index",
5655
) -> None: ...
5756
def assert_class_equal(
58-
left: T, right: T, exact: bool | Literal["equiv"] = ..., obj: str = ...
57+
left: T, right: T, exact: bool | Literal["equiv"] = True, obj: str = "Input"
5958
) -> None: ...
6059
def assert_attr_equal(
61-
attr: str, left: object, right: object, obj: str = ...
60+
attr: str, left: object, right: object, obj: str = "Attributes"
6261
) -> None: ...
6362
def assert_is_valid_plot_return_object(
6463
objs: Series | np.ndarray | Artist | tuple | dict,
@@ -67,44 +66,50 @@ def assert_is_sorted(seq: AnyArrayLike) -> None: ...
6766
def assert_categorical_equal(
6867
left: Categorical,
6968
right: Categorical,
70-
check_dtype: bool = ...,
71-
check_category_order: bool = ...,
72-
obj: str = ...,
69+
check_dtype: bool = True,
70+
check_category_order: bool = True,
71+
obj: str = "Categorical",
7372
) -> None: ...
7473
def assert_interval_array_equal(
7574
left: IntervalArray,
7675
right: IntervalArray,
77-
exact: bool | Literal["equiv"] = ...,
78-
obj: str = ...,
76+
exact: bool | Literal["equiv"] = "equiv",
77+
obj: str = "IntervalArray",
7978
) -> None: ...
8079
def assert_period_array_equal(
81-
left: PeriodArray, right: PeriodArray, obj: str = ...
80+
left: PeriodArray, right: PeriodArray, obj: str = "PeriodArray"
8281
) -> None: ...
8382
def assert_datetime_array_equal(
84-
left: DatetimeArray, right: DatetimeArray, check_freq: bool = ...
83+
left: DatetimeArray,
84+
right: DatetimeArray,
85+
obj: str = "DatetimeArray",
86+
check_freq: bool = True,
8587
) -> None: ...
8688
def assert_timedelta_array_equal(
87-
left: TimedeltaArray, right: TimedeltaArray, check_freq: bool = ...
89+
left: TimedeltaArray,
90+
right: TimedeltaArray,
91+
obj: str = "TimedeltaArray",
92+
check_freq: bool = True,
8893
) -> None: ...
8994
def assert_numpy_array_equal(
9095
left,
9196
right,
92-
strict_nan: bool = ...,
93-
check_dtype: bool | Literal["equiv"] = ...,
94-
err_msg: str | None = ...,
95-
check_same: Literal["copy", "same"] | None = ...,
96-
obj: str = ...,
97-
index_values: Index | np.ndarray | None = ...,
97+
strict_nan: bool = False,
98+
check_dtype: bool | Literal["equiv"] = True,
99+
err_msg: str | None = None,
100+
check_same: Literal["copy", "same"] | None = None,
101+
obj: str = "numpy array",
102+
index_values: Index | np.ndarray | None = None,
98103
) -> None: ...
99104
def assert_extension_array_equal(
100105
left: ExtensionArray,
101106
right: ExtensionArray,
102-
check_dtype: bool | Literal["equiv"] = ...,
103-
index_values: Index | np.ndarray | None = ...,
104-
check_exact: bool = ...,
105-
rtol: float = ...,
106-
atol: float = ...,
107-
obj: str = ...,
107+
check_dtype: bool | Literal["equiv"] = True,
108+
index_values: Index | np.ndarray | None = None,
109+
check_exact: bool = False,
110+
rtol: float = 1e-5,
111+
atol: float = 1e-8,
112+
obj: str = "ExtensionArray",
108113
) -> None: ...
109114
@overload
110115
def assert_series_equal(
@@ -151,21 +156,21 @@ def assert_series_equal(
151156
def assert_frame_equal(
152157
left: DataFrame,
153158
right: DataFrame,
154-
check_dtype: bool | Literal["equiv"] = ...,
155-
check_index_type: bool | Literal["equiv"] = ...,
156-
check_column_type: bool | Literal["equiv"] = ...,
157-
check_frame_type: bool = ...,
158-
check_names: bool = ...,
159-
by_blocks: bool = ...,
160-
check_exact: bool = ...,
161-
check_datetimelike_compat: bool = ...,
162-
check_categorical: bool = ...,
163-
check_like: bool = ...,
164-
check_freq: bool = ...,
165-
check_flags: bool = ...,
166-
rtol: float = ...,
167-
atol: float = ...,
168-
obj: str = ...,
159+
check_dtype: bool | Literal["equiv"] = True,
160+
check_index_type: bool | Literal["equiv"] = "equiv",
161+
check_column_type: bool | Literal["equiv"] = "equiv",
162+
check_frame_type: bool = True,
163+
check_names: bool = True,
164+
by_blocks: bool = False,
165+
check_exact: bool = False,
166+
check_datetimelike_compat: bool = False,
167+
check_categorical: bool = True,
168+
check_like: bool = False,
169+
check_freq: bool = True,
170+
check_flags: bool = True,
171+
rtol: float = 1e-5,
172+
atol: float = 1e-8,
173+
obj: str = "DataFrame",
169174
) -> None: ...
170175
def assert_equal(left, right, **kwargs) -> None: ...
171176
def assert_sp_array_equal(left: SparseArray, right: SparseArray) -> None: ...
@@ -178,12 +183,10 @@ def assert_produces_warning(
178183
) = ...,
179184
filter_level: Literal[
180185
"error", "ignore", "always", "default", "module", "once"
181-
] = ...,
182-
check_stacklevel: bool = ...,
183-
raise_on_extra_warnings: bool = ...,
186+
] = "always",
187+
check_stacklevel: bool = True,
188+
raise_on_extra_warnings: bool = True,
184189
match: str | None = None,
185190
) -> Generator[list[warnings.WarningMessage], None, None]: ...
186191
@contextmanager
187-
def ensure_clean(
188-
filename: str | None = ..., return_filelike: bool = ..., **kwargs: Any
189-
) -> Generator[str, None, None]: ...
192+
def ensure_clean(filename: str | None = None) -> Generator[str, None, None]: ...

pandas-stubs/core/algorithms.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ def factorize(
6464
) -> tuple[np.ndarray, Categorical]: ...
6565
def value_counts(
6666
values: AnyArrayLike | list | tuple,
67-
sort: bool = ...,
68-
ascending: bool = ...,
69-
normalize: bool = ...,
70-
bins: int | None = ...,
71-
dropna: bool = ...,
67+
sort: bool = True,
68+
ascending: bool = False,
69+
normalize: bool = False,
70+
bins: int | None = None,
71+
dropna: bool = True,
7272
) -> Series: ...
7373
def take(
7474
arr,

0 commit comments

Comments
 (0)