Skip to content

Commit cb6208b

Browse files
GH1317 Add more defaults (#1555)
* GH1317 Add more defaults * GH1317 Add more defaults * GH1317 Add more defaults * Apply suggestions from code review Co-authored-by: Yi-Fan Wang <[email protected]> --------- Co-authored-by: Yi-Fan Wang <[email protected]>
1 parent 7238827 commit cb6208b

File tree

10 files changed

+244
-242
lines changed

10 files changed

+244
-242
lines changed

pandas-stubs/_testing/__init__.pyi

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ from pandas.arrays import (
2626
)
2727
from pandas.core.arrays.base import ExtensionArray
2828

29+
from pandas._libs.lib import _NoDefaultDoNotUse
2930
from pandas._typing import (
3031
AnyArrayLike,
3132
T,
@@ -101,19 +102,19 @@ def assert_extension_array_equal(
101102
def assert_series_equal(
102103
left: Series,
103104
right: Series,
104-
check_dtype: bool | Literal["equiv"] = ...,
105-
check_index_type: bool | Literal["equiv"] = ...,
106-
check_series_type: bool = ...,
107-
check_names: bool = ...,
108-
check_exact: bool = ...,
109-
check_datetimelike_compat: bool = ...,
110-
check_categorical: bool = ...,
111-
check_category_order: bool = ...,
112-
check_freq: bool = ...,
113-
check_flags: bool = ...,
114-
rtol: float = ...,
115-
atol: float = ...,
116-
obj: str = ...,
105+
check_dtype: bool | Literal["equiv"] = True,
106+
check_index_type: bool | Literal["equiv"] = "equiv",
107+
check_series_type: bool = True,
108+
check_names: bool = True,
109+
check_exact: bool | _NoDefaultDoNotUse = ...,
110+
check_datetimelike_compat: bool = False,
111+
check_categorical: bool = True,
112+
check_category_order: bool = True,
113+
check_freq: bool = True,
114+
check_flags: bool = True,
115+
rtol: float | _NoDefaultDoNotUse = ...,
116+
atol: float | _NoDefaultDoNotUse = ...,
117+
obj: str = "Series",
117118
*,
118119
check_index: Literal[False],
119120
check_like: Literal[False] = False,
@@ -122,22 +123,22 @@ def assert_series_equal(
122123
def assert_series_equal(
123124
left: Series,
124125
right: Series,
125-
check_dtype: bool | Literal["equiv"] = ...,
126-
check_index_type: bool | Literal["equiv"] = ...,
127-
check_series_type: bool = ...,
128-
check_names: bool = ...,
129-
check_exact: bool = ...,
130-
check_datetimelike_compat: bool = ...,
131-
check_categorical: bool = ...,
132-
check_category_order: bool = ...,
133-
check_freq: bool = ...,
134-
check_flags: bool = ...,
135-
rtol: float = ...,
136-
atol: float = ...,
137-
obj: str = ...,
126+
check_dtype: bool | Literal["equiv"] = True,
127+
check_index_type: bool | Literal["equiv"] = "equiv",
128+
check_series_type: bool = True,
129+
check_names: bool = True,
130+
check_exact: bool | _NoDefaultDoNotUse = ...,
131+
check_datetimelike_compat: bool = False,
132+
check_categorical: bool = True,
133+
check_category_order: bool = True,
134+
check_freq: bool = True,
135+
check_flags: bool = True,
136+
rtol: float | _NoDefaultDoNotUse = ...,
137+
atol: float | _NoDefaultDoNotUse = ...,
138+
obj: str = "Series",
138139
*,
139140
check_index: Literal[True] = True,
140-
check_like: bool = ...,
141+
check_like: bool = False,
141142
) -> None: ...
142143
def assert_frame_equal(
143144
left: DataFrame,

pandas-stubs/core/algorithms.pyi

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,23 @@ def unique(values: T_EXTENSION_ARRAY) -> T_EXTENSION_ARRAY: ...
6969
@overload
7070
def factorize(
7171
values: npt.NDArray[GenericT],
72-
sort: bool = ...,
73-
use_na_sentinel: bool = ...,
74-
size_hint: int | None = ...,
72+
sort: bool = False,
73+
use_na_sentinel: bool = True,
74+
size_hint: int | None = None,
7575
) -> tuple[np_1darray_int64, np_1darray[GenericT]]: ...
7676
@overload
7777
def factorize(
7878
values: Index | Series,
79-
sort: bool = ...,
80-
use_na_sentinel: bool = ...,
81-
size_hint: int | None = ...,
79+
sort: bool = False,
80+
use_na_sentinel: bool = True,
81+
size_hint: int | None = None,
8282
) -> tuple[np_1darray_int64, Index]: ...
8383
@overload
8484
def factorize(
8585
values: Categorical,
86-
sort: bool = ...,
87-
use_na_sentinel: bool = ...,
88-
size_hint: int | None = ...,
86+
sort: bool = False,
87+
use_na_sentinel: bool = True,
88+
size_hint: int | None = None,
8989
) -> tuple[np_1darray_int64, Categorical]: ...
9090
def take(
9191
arr: np_ndarray[Any] | ExtensionArray | Index | Series,

pandas-stubs/core/computation/eval.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ from pandas._typing import (
2121
def eval(
2222
expr: str | BinOp,
2323
parser: Literal["pandas", "python"] = "pandas",
24-
engine: Literal["python", "numexpr"] | None = ...,
24+
engine: Literal["python", "numexpr"] | None = None,
2525
local_dict: dict[str, Any] | None = None,
2626
global_dict: dict[str, Any] | None = None,
2727
resolvers: MutableSequence[Mapping[Any, Any]] | None = ...,

pandas-stubs/core/groupby/generic.pyi

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -324,48 +324,48 @@ class DataFrameGroupBy(GroupBy[DataFrame], Generic[ByT, _TT]):
324324
def boxplot(
325325
self,
326326
subplots: Literal[True] = True,
327-
column: IndexLabel | None = ...,
328-
fontsize: float | str | None = ...,
329-
rot: float = ...,
330-
grid: bool = ...,
331-
ax: PlotAxes | None = ...,
332-
figsize: tuple[float, float] | None = ...,
333-
layout: tuple[int, int] | None = ...,
334-
sharex: bool = ...,
335-
sharey: bool = ...,
336-
backend: str | None = ...,
327+
column: IndexLabel | None = None,
328+
fontsize: float | str | None = None,
329+
rot: float = 0,
330+
grid: bool = True,
331+
ax: PlotAxes | None = None,
332+
figsize: tuple[float, float] | None = None,
333+
layout: tuple[int, int] | None = None,
334+
sharex: bool = False,
335+
sharey: bool = True,
336+
backend: str | None = None,
337337
**kwargs: Any,
338338
) -> Series: ... # Series[PlotAxes] but this is not allowed
339339
@overload
340340
def boxplot(
341341
self,
342342
subplots: Literal[False],
343-
column: IndexLabel | None = ...,
344-
fontsize: float | str | None = ...,
345-
rot: float = ...,
346-
grid: bool = ...,
347-
ax: PlotAxes | None = ...,
348-
figsize: tuple[float, float] | None = ...,
349-
layout: tuple[int, int] | None = ...,
350-
sharex: bool = ...,
351-
sharey: bool = ...,
352-
backend: str | None = ...,
343+
column: IndexLabel | None = None,
344+
fontsize: float | str | None = None,
345+
rot: float = 0,
346+
grid: bool = True,
347+
ax: PlotAxes | None = None,
348+
figsize: tuple[float, float] | None = None,
349+
layout: tuple[int, int] | None = None,
350+
sharex: bool = False,
351+
sharey: bool = True,
352+
backend: str | None = None,
353353
**kwargs: Any,
354354
) -> PlotAxes: ...
355355
@overload
356356
def boxplot(
357357
self,
358358
subplots: bool,
359-
column: IndexLabel | None = ...,
360-
fontsize: float | str | None = ...,
361-
rot: float = ...,
362-
grid: bool = ...,
363-
ax: PlotAxes | None = ...,
364-
figsize: tuple[float, float] | None = ...,
365-
layout: tuple[int, int] | None = ...,
366-
sharex: bool = ...,
367-
sharey: bool = ...,
368-
backend: str | None = ...,
359+
column: IndexLabel | None = None,
360+
fontsize: float | str | None = None,
361+
rot: float = 0,
362+
grid: bool = True,
363+
ax: PlotAxes | None = None,
364+
figsize: tuple[float, float] | None = None,
365+
layout: tuple[int, int] | None = None,
366+
sharex: bool = False,
367+
sharey: bool = True,
368+
backend: str | None = None,
369369
**kwargs: Any,
370370
) -> PlotAxes | Series: ... # Series[PlotAxes]
371371
@overload

pandas-stubs/core/indexes/datetimes.pyi

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ from datetime import (
1111
import sys
1212
from typing import (
1313
Any,
14+
Literal,
1415
final,
1516
overload,
1617
)
1718

1819
import numpy as np
20+
import pandas as pd
1921
from pandas.core.frame import DataFrame
2022
from pandas.core.indexes.accessors import DatetimeIndexProperties
2123
from pandas.core.indexes.base import Index
@@ -31,13 +33,13 @@ from pandas._libs.tslibs.timestamps import Timestamp
3133
from pandas._typing import (
3234
AxesData,
3335
DateAndDatetimeLike,
34-
Dtype,
3536
Frequency,
3637
IntervalClosedType,
3738
TimeUnit,
3839
TimeZones,
3940
np_1darray_intp,
4041
np_ndarray,
42+
np_ndarray_bool,
4143
np_ndarray_dt,
4244
np_ndarray_td,
4345
)
@@ -54,12 +56,12 @@ class DatetimeIndex(
5456
data: AxesData,
5557
freq: Frequency = ...,
5658
tz: TimeZones = ...,
57-
ambiguous: str = ...,
58-
dayfirst: bool = ...,
59-
yearfirst: bool = ...,
60-
dtype: Dtype = ...,
61-
copy: bool = ...,
62-
name: Hashable = ...,
59+
ambiguous: Literal["infer", "NaT", "raise"] | np_ndarray_bool = "raise",
60+
dayfirst: bool = False,
61+
yearfirst: bool = False,
62+
dtype: np.dtype[np.datetime64] | pd.DatetimeTZDtype | str | None = None,
63+
copy: bool = False,
64+
name: Hashable = None,
6365
) -> Self: ...
6466

6567
# various ignores needed for mypy, as we do want to restrict what can be used in
@@ -123,7 +125,7 @@ def date_range(
123125
freq: Frequency | timedelta | None = None,
124126
tz: TimeZones = None,
125127
normalize: bool = False,
126-
name: Hashable | None = None,
128+
name: Hashable = None,
127129
inclusive: IntervalClosedType = "both",
128130
unit: TimeUnit | None = None,
129131
) -> DatetimeIndex: ...
@@ -134,7 +136,7 @@ def date_range(
134136
periods: int,
135137
tz: TimeZones = None,
136138
normalize: bool = False,
137-
name: Hashable | None = None,
139+
name: Hashable = None,
138140
inclusive: IntervalClosedType = "both",
139141
unit: TimeUnit | None = None,
140142
) -> DatetimeIndex: ...
@@ -146,7 +148,7 @@ def date_range(
146148
freq: Frequency | timedelta | None = None,
147149
tz: TimeZones = None,
148150
normalize: bool = False,
149-
name: Hashable | None = None,
151+
name: Hashable = None,
150152
inclusive: IntervalClosedType = "both",
151153
unit: TimeUnit | None = None,
152154
) -> DatetimeIndex: ...
@@ -158,34 +160,34 @@ def date_range(
158160
freq: Frequency | timedelta | None = None,
159161
tz: TimeZones = None,
160162
normalize: bool = False,
161-
name: Hashable | None = None,
163+
name: Hashable = None,
162164
inclusive: IntervalClosedType = "both",
163165
unit: TimeUnit | None = None,
164166
) -> DatetimeIndex: ...
165167
@overload
166168
def bdate_range(
167-
start: str | DateAndDatetimeLike | None = ...,
168-
end: str | DateAndDatetimeLike | None = ...,
169-
periods: int | None = ...,
170-
freq: Frequency | timedelta = ...,
171-
tz: TimeZones = ...,
172-
normalize: bool = ...,
173-
name: Hashable | None = ...,
174-
weekmask: str | None = ...,
169+
start: str | DateAndDatetimeLike | None = None,
170+
end: str | DateAndDatetimeLike | None = None,
171+
periods: int | None = None,
172+
freq: Frequency | timedelta = "B",
173+
tz: TimeZones = None,
174+
normalize: bool = False,
175+
name: Hashable = None,
176+
weekmask: str | None = None,
175177
holidays: None = None,
176-
inclusive: IntervalClosedType = ...,
178+
inclusive: IntervalClosedType = "both",
177179
) -> DatetimeIndex: ...
178180
@overload
179181
def bdate_range(
180-
start: str | DateAndDatetimeLike | None = ...,
181-
end: str | DateAndDatetimeLike | None = ...,
182-
periods: int | None = ...,
182+
start: str | DateAndDatetimeLike | None = None,
183+
end: str | DateAndDatetimeLike | None = None,
184+
periods: int | None = None,
183185
*,
184186
freq: Frequency | timedelta,
185-
tz: TimeZones = ...,
186-
normalize: bool = ...,
187-
name: Hashable | None = ...,
188-
weekmask: str | None = ...,
187+
tz: TimeZones = None,
188+
normalize: bool = False,
189+
name: Hashable = None,
190+
weekmask: str | None = None,
189191
holidays: Sequence[str | DateAndDatetimeLike],
190-
inclusive: IntervalClosedType = ...,
192+
inclusive: IntervalClosedType = "both",
191193
) -> DatetimeIndex: ...

pandas-stubs/core/reshape/merge.pyi

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,42 +38,42 @@ def merge(
3838
def merge_ordered(
3939
left: DataFrame,
4040
right: DataFrame,
41-
on: Label | list[HashableT] | None = ...,
42-
left_on: Label | list[HashableT] | None = ...,
43-
right_on: Label | list[HashableT] | None = ...,
44-
left_by: Label | list[HashableT] | None = ...,
45-
right_by: Label | list[HashableT] | None = ...,
46-
fill_method: Literal["ffill"] | None = ...,
47-
suffixes: Suffixes = ...,
48-
how: JoinHow = ...,
41+
on: Label | list[HashableT] | None = None,
42+
left_on: Label | list[HashableT] | None = None,
43+
right_on: Label | list[HashableT] | None = None,
44+
left_by: Label | list[HashableT] | None = None,
45+
right_by: Label | list[HashableT] | None = None,
46+
fill_method: Literal["ffill"] | None = None,
47+
suffixes: Suffixes = ("_x", "_y"),
48+
how: JoinHow = "outer",
4949
) -> DataFrame: ...
5050
@overload
5151
def merge_ordered(
5252
left: Series,
5353
right: DataFrame | Series,
54-
on: Label | list[HashableT] | None = ...,
55-
left_on: Label | list[HashableT] | None = ...,
56-
right_on: Label | list[HashableT] | None = ...,
54+
on: Label | list[HashableT] | None = None,
55+
left_on: Label | list[HashableT] | None = None,
56+
right_on: Label | list[HashableT] | None = None,
5757
left_by: None = None,
5858
right_by: None = None,
59-
fill_method: Literal["ffill"] | None = ...,
59+
fill_method: Literal["ffill"] | None = None,
6060
suffixes: (
6161
list[str | None] | tuple[str, str] | tuple[None, str] | tuple[str, None]
62-
) = ...,
63-
how: JoinHow = ...,
62+
) = ("_x", "_y"),
63+
how: JoinHow = "outer",
6464
) -> DataFrame: ...
6565
@overload
6666
def merge_ordered(
6767
left: DataFrame | Series,
6868
right: Series,
69-
on: Label | list[HashableT] | None = ...,
70-
left_on: Label | list[HashableT] | None = ...,
71-
right_on: Label | list[HashableT] | None = ...,
69+
on: Label | list[HashableT] | None = None,
70+
left_on: Label | list[HashableT] | None = None,
71+
right_on: Label | list[HashableT] | None = None,
7272
left_by: None = None,
7373
right_by: None = None,
74-
fill_method: Literal["ffill"] | None = ...,
75-
suffixes: Suffixes = ...,
76-
how: JoinHow = ...,
74+
fill_method: Literal["ffill"] | None = None,
75+
suffixes: Suffixes = ("_x", "_y"),
76+
how: JoinHow = "outer",
7777
) -> DataFrame: ...
7878
def merge_asof(
7979
left: DataFrame | Series,
@@ -86,7 +86,7 @@ def merge_asof(
8686
by: Label | list[HashableT] | None = None,
8787
left_by: Label | list[HashableT] | None = None,
8888
right_by: Label | list[HashableT] | None = None,
89-
suffixes: Suffixes = ...,
89+
suffixes: Suffixes = ("_x", "_y"),
9090
tolerance: int | timedelta | Timedelta | None = None,
9191
allow_exact_matches: bool = True,
9292
direction: Literal["backward", "forward", "nearest"] = "backward",

0 commit comments

Comments
 (0)