Skip to content
Merged
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
12 changes: 1 addition & 11 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
join: AlignJoin = "outer",
axis: Axis | None = None,
level: Level | None = None,
copy: _bool = True,
fill_value: Scalar | NAType | None = ...,
) -> tuple[Self, NDFrameT]: ...
def reindex(
Expand All @@ -889,7 +888,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
columns: Axes | None = ...,
axis: Axis | None = ...,
method: ReindexMethod | None = ...,
copy: bool = True,
level: int | _str = ...,
fill_value: Scalar | None = ...,
limit: int | None = None,
Expand Down Expand Up @@ -1576,7 +1574,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
right_index: _bool = False,
sort: _bool = False,
suffixes: Suffixes = ...,
copy: _bool = True,
indicator: _bool | _str = False,
validate: MergeValidate | None = None,
) -> Self: ...
Expand Down Expand Up @@ -1649,13 +1646,11 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
freq: PeriodFrequency | None = None,
how: ToTimestampHow = ...,
axis: Axis = 0,
copy: _bool = True,
) -> Self: ...
def to_period(
self,
freq: PeriodFrequency | None = None,
axis: Axis = 0,
copy: _bool = True,
) -> Self: ...
def isin(
self, values: Iterable[Any] | Mapping[Hashable, Iterable[Any]] | DataFrame
Expand Down Expand Up @@ -1896,7 +1891,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
def astype(
self,
dtype: AstypeArg | Mapping[Any, Dtype] | Series,
copy: _bool = True,
errors: IgnoreRaise = "raise",
) -> Self: ...
@final
Expand Down Expand Up @@ -2074,7 +2068,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
@final
def head(self, n: int = 5) -> Self: ...
@final
def infer_objects(self, copy: _bool | None = ...) -> Self: ...
def infer_objects(self) -> Self: ...
def interpolate(
self,
method: InterpolateOptions = ...,
Expand Down Expand Up @@ -2256,7 +2250,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
self,
other: DataFrame,
method: FillnaOptions | Literal["nearest"] | None = ...,
copy: _bool = True,
limit: int | None = None,
tolerance: Scalar | AnyArrayLike | Sequence[Scalar] = ...,
) -> Self: ...
Expand Down Expand Up @@ -2550,23 +2543,20 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
before: dt.date | _str | int | None = ...,
after: dt.date | _str | int | None = ...,
axis: Axis | None = ...,
copy: _bool = ...,
) -> Self: ...
@final
def tz_convert(
self,
tz: TimeZones,
axis: Axis = 0,
level: Level | None = None,
copy: _bool = True,
) -> Self: ...
@final
def tz_localize(
self,
tz: TimeZones,
axis: Axis = 0,
level: Level | None = None,
copy: _bool = True,
ambiguous: TimeAmbiguous = "raise",
nonexistent: TimeNonexistent = "raise",
) -> Self: ...
Expand Down
31 changes: 3 additions & 28 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1090,9 +1090,7 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
def nsmallest(
self, n: int = 5, keep: NsmallestNlargestKeep = "first"
) -> Series[S1]: ...
def swaplevel(
self, i: Level = -2, j: Level = -1, copy: _bool = True
) -> Series[S1]: ...
def swaplevel(self, i: Level = -2, j: Level = -1) -> Series[S1]: ...
def reorder_levels(self, order: Sequence[int | np.integer]) -> Series[S1]: ...
def explode(self, ignore_index: _bool = ...) -> Series[S1]: ...
def unstack(
Expand Down Expand Up @@ -1207,7 +1205,6 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
index: Callable[[Any], Label],
*,
axis: Axis | None = ...,
copy: bool = ...,
inplace: Literal[True],
level: Level | None = ...,
errors: IgnoreRaise = ...,
Expand All @@ -1218,7 +1215,6 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
index: Mapping[Any, Label],
*,
axis: Axis | None = ...,
copy: bool = ...,
inplace: Literal[True],
level: Level | None = ...,
errors: IgnoreRaise = ...,
Expand All @@ -1229,7 +1225,6 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
index: Scalar | tuple[Hashable, ...] | None = None,
*,
axis: Axis | None = ...,
copy: bool = ...,
inplace: Literal[True],
level: Level | None = ...,
errors: IgnoreRaise = ...,
Expand All @@ -1240,7 +1235,6 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
index: Renamer | Scalar | tuple[Hashable, ...] | None = ...,
*,
axis: Axis | None = ...,
copy: bool = ...,
inplace: Literal[False] = False,
level: Level | None = ...,
errors: IgnoreRaise = ...,
Expand All @@ -1250,7 +1244,6 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
self,
other: Series[S1],
method: FillnaOptions | Literal["nearest"] | None = None,
copy: _bool = True,
limit: int | None = None,
tolerance: Scalar | AnyArrayLike | Sequence[Scalar] | None = None,
) -> Self: ...
Expand Down Expand Up @@ -1318,11 +1311,8 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
self,
freq: PeriodFrequency | None = None,
how: ToTimestampHow = "start",
copy: _bool = True,
) -> Series[S1]: ...
def to_period(
self, freq: PeriodFrequency | None = None, copy: _bool = True
) -> DataFrame: ...
def to_period(self, freq: PeriodFrequency | None = None) -> DataFrame: ...
@property
def str(
self,
Expand Down Expand Up @@ -1374,7 +1364,6 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
self,
index: Axes | None = None,
method: ReindexMethod | None = None,
copy: bool = True,
level: int | _str | None = None,
fill_value: Scalar | None = None,
limit: int | None = None,
Expand Down Expand Up @@ -1406,76 +1395,66 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
def astype(
self,
dtype: BooleanDtypeArg,
copy: _bool = ...,
errors: IgnoreRaise = ...,
) -> Series[bool]: ...
@overload
def astype(
self,
dtype: IntDtypeArg | UIntDtypeArg,
copy: _bool = ...,
errors: IgnoreRaise = ...,
) -> Series[int]: ...
@overload
def astype(
self,
dtype: StrDtypeArg,
copy: _bool = ...,
errors: IgnoreRaise = ...,
) -> Series[_str]: ...
@overload
def astype(
self,
dtype: BytesDtypeArg,
copy: _bool = ...,
errors: IgnoreRaise = ...,
) -> Series[bytes]: ...
@overload
def astype(
self,
dtype: FloatDtypeArg,
copy: _bool = ...,
errors: IgnoreRaise = ...,
) -> Series[float]: ...
@overload
def astype(
self,
dtype: ComplexDtypeArg,
copy: _bool = ...,
errors: IgnoreRaise = ...,
) -> Series[complex]: ...
@overload
def astype(
self,
dtype: TimedeltaDtypeArg | PandasAstypeTimedeltaDtypeArg,
copy: _bool = ...,
errors: IgnoreRaise = ...,
) -> Series[Timedelta]: ...
@overload
def astype(
self,
dtype: TimestampDtypeArg | PandasAstypeTimestampDtypeArg,
copy: _bool = ...,
errors: IgnoreRaise = ...,
) -> Series[Timestamp]: ...
@overload
def astype(
self,
dtype: CategoryDtypeArg,
copy: _bool = ...,
errors: IgnoreRaise = ...,
) -> Series[CategoricalDtype]: ...
@overload
def astype(
self,
dtype: ObjectDtypeArg | VoidDtypeArg | ExtensionDtype | DtypeObj,
copy: _bool = ...,
errors: IgnoreRaise = ...,
) -> Series: ...
@final
def copy(self, deep: _bool = True) -> Series[S1]: ...
@final
def infer_objects(self, copy: _bool = True) -> Series[S1]: ...
def infer_objects(self) -> Series[S1]: ...
def ffill(
self,
*,
Expand Down Expand Up @@ -1649,23 +1628,20 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
before: date | _str | int | None = ...,
after: date | _str | int | None = ...,
axis: AxisIndex | None = 0,
copy: _bool = ...,
) -> Series[S1]: ...
@final
def tz_convert(
self,
tz: TimeZones,
axis: AxisIndex = 0,
level: Level | None = None,
copy: _bool = True,
) -> Series[S1]: ...
@final
def tz_localize(
self,
tz: TimeZones,
axis: AxisIndex = 0,
level: Level | None = None,
copy: _bool = True,
ambiguous: TimeAmbiguous = "raise",
nonexistent: _str = "raise",
) -> Series[S1]: ...
Expand Down Expand Up @@ -4628,7 +4604,6 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
labels: AxesData,
*,
axis: Axis = 0,
copy: _bool | NoDefault = ...,
) -> Self: ...
@final
def xs( # pyright: ignore[reportIncompatibleMethodOverride] # pyrefly: ignore[bad-override] # ty: ignore[invalid-method-override]
Expand Down
41 changes: 41 additions & 0 deletions tests/frame/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1934,6 +1934,10 @@ def test_types_merge() -> None:
columns = ["col1", "col2"]
check(assert_type(df.merge(df2, on=columns), pd.DataFrame), pd.DataFrame)

if TYPE_CHECKING_INVALID_USAGE:
# copy argument is deprecated from 3.0
_0 = df.merge(df2, copy=True) # type: ignore[call-arg] # pyright: ignore[reportCallIssue,reportUnknownVariableType]

# https://github.com/microsoft/python-type-stubs/issues/60
df1 = pd.DataFrame([["a", 1], ["b", 2]], columns=["let", "num"]).set_index("let")
s2 = df1["num"]
Expand Down Expand Up @@ -3128,6 +3132,10 @@ def test_frame_reindex() -> None:
pd.DataFrame,
)

if TYPE_CHECKING_INVALID_USAGE:
# copy argument is deprecated from 3.0
_0 = df.reindex([2, 1, 0], copy=True) # type: ignore[call-arg] # pyright: ignore[reportCallIssue,reportUnknownVariableType]


def test_frame_reindex_like() -> None:
# GH 84
Expand All @@ -3146,6 +3154,10 @@ def test_frame_reindex_like() -> None:
pd.DataFrame,
)

if TYPE_CHECKING_INVALID_USAGE:
# copy argument is deprecated from 3.0
_0 = df.reindex_like(other, copy=True) # type: ignore[call-arg] # pyright: ignore[reportCallIssue,reportUnknownVariableType]


def test_not_hashable() -> None:
# GH 113
Expand Down Expand Up @@ -3592,6 +3604,10 @@ def test_astype() -> None:
df = pd.DataFrame({"x": [1.0, 2.0, 3.0], "y": [4.0, 5, 6]})
check(assert_type(df.astype(int), pd.DataFrame), pd.DataFrame)

if TYPE_CHECKING_INVALID_USAGE:
# copy argument is deprecated from 3.0
_0 = s.astype(int, copy=True) # type: ignore[call-arg] # pyright: ignore[reportCallIssue,reportUnknownVariableType]


def test_xs_frame_new() -> None:
d = {
Expand Down Expand Up @@ -3659,6 +3675,10 @@ def test_align() -> None:
check(assert_type(aligned_df0, pd.DataFrame), pd.DataFrame)
check(assert_type(aligned_df1, pd.DataFrame), pd.DataFrame)

if TYPE_CHECKING_INVALID_USAGE:
# copy argument is deprecated from 3.0
_0 = df0.align(df1, copy=True) # type: ignore[call-arg] # pyright: ignore[reportCallIssue,reportUnknownVariableType]


def test_to_dict_index() -> None:
df = pd.DataFrame({"a": [1, 2], "b": [9, 10]})
Expand Down Expand Up @@ -4208,6 +4228,27 @@ def test_frame_delitem() -> None:
del df["B"]


def test_frame_copy_deprecated() -> None:
"""Test that copy argument is deprecated from 3.0 for various DataFrame methods."""
df = pd.DataFrame({"a": [1, 2, 3]})

if TYPE_CHECKING_INVALID_USAGE:
# truncate
_0 = df.truncate(copy=True) # type: ignore[call-arg] # pyright: ignore[reportCallIssue,reportUnknownVariableType]
# tz_convert
_1 = df.tz_convert("UTC", copy=True) # type: ignore[call-arg] # pyright: ignore[reportCallIssue,reportUnknownVariableType]
# tz_localize
_2 = df.tz_localize("UTC", copy=True) # type: ignore[call-arg] # pyright: ignore[reportCallIssue,reportUnknownVariableType]
# infer_objects
_3 = df.infer_objects(copy=True) # type: ignore[call-arg] # pyright: ignore[reportCallIssue,reportUnknownVariableType]
# set_axis
_4 = df.set_axis([1, 2, 3], copy=True) # type: ignore[call-arg] # pyright: ignore[reportCallIssue,reportUnknownVariableType]
# to_period
_5 = df.to_period(copy=True) # type: ignore[call-arg] # pyright: ignore[reportCallIssue,reportUnknownVariableType]
# to_timestamp
_6 = df.to_timestamp(copy=True) # type: ignore[call-arg] # pyright: ignore[reportCallIssue,reportUnknownVariableType]


def test_rolling_first() -> None:
"""Test DataFrame.rolling.first method."""
df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6], "C": [7, 8, 9]})
Expand Down
Loading