Skip to content

Commit 7ad48ca

Browse files
CLN: GH1654 deprecated copy argument (#1663)
* GH1654 Clean out deprecated copy argument * Remove deprecated test_frame_copy_deprecated function Removed deprecated test for DataFrame copy argument. * GH1654 Clean out deprecated copy argument
1 parent 7eb49da commit 7ad48ca

File tree

4 files changed

+80
-39
lines changed

4 files changed

+80
-39
lines changed

pandas-stubs/core/frame.pyi

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
878878
join: AlignJoin = "outer",
879879
axis: Axis | None = None,
880880
level: Level | None = None,
881-
copy: _bool = True,
882881
fill_value: Scalar | NAType | None = ...,
883882
) -> tuple[Self, NDFrameT]: ...
884883
def reindex(
@@ -889,7 +888,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
889888
columns: Axes | None = ...,
890889
axis: Axis | None = ...,
891890
method: ReindexMethod | None = ...,
892-
copy: bool = True,
893891
level: int | _str = ...,
894892
fill_value: Scalar | None = ...,
895893
limit: int | None = None,
@@ -1576,7 +1574,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
15761574
right_index: _bool = False,
15771575
sort: _bool = False,
15781576
suffixes: Suffixes = ...,
1579-
copy: _bool = True,
15801577
indicator: _bool | _str = False,
15811578
validate: MergeValidate | None = None,
15821579
) -> Self: ...
@@ -1649,13 +1646,11 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
16491646
freq: PeriodFrequency | None = None,
16501647
how: ToTimestampHow = ...,
16511648
axis: Axis = 0,
1652-
copy: _bool = True,
16531649
) -> Self: ...
16541650
def to_period(
16551651
self,
16561652
freq: PeriodFrequency | None = None,
16571653
axis: Axis = 0,
1658-
copy: _bool = True,
16591654
) -> Self: ...
16601655
def isin(
16611656
self, values: Iterable[Any] | Mapping[Hashable, Iterable[Any]] | DataFrame
@@ -1896,7 +1891,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
18961891
def astype(
18971892
self,
18981893
dtype: AstypeArg | Mapping[Any, Dtype] | Series,
1899-
copy: _bool = True,
19001894
errors: IgnoreRaise = "raise",
19011895
) -> Self: ...
19021896
@final
@@ -2074,7 +2068,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
20742068
@final
20752069
def head(self, n: int = 5) -> Self: ...
20762070
@final
2077-
def infer_objects(self, copy: _bool | None = ...) -> Self: ...
2071+
def infer_objects(self) -> Self: ...
20782072
def interpolate(
20792073
self,
20802074
method: InterpolateOptions = ...,
@@ -2256,7 +2250,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
22562250
self,
22572251
other: DataFrame,
22582252
method: FillnaOptions | Literal["nearest"] | None = ...,
2259-
copy: _bool = True,
22602253
limit: int | None = None,
22612254
tolerance: Scalar | AnyArrayLike | Sequence[Scalar] = ...,
22622255
) -> Self: ...
@@ -2550,23 +2543,20 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
25502543
before: dt.date | _str | int | None = ...,
25512544
after: dt.date | _str | int | None = ...,
25522545
axis: Axis | None = ...,
2553-
copy: _bool = ...,
25542546
) -> Self: ...
25552547
@final
25562548
def tz_convert(
25572549
self,
25582550
tz: TimeZones,
25592551
axis: Axis = 0,
25602552
level: Level | None = None,
2561-
copy: _bool = True,
25622553
) -> Self: ...
25632554
@final
25642555
def tz_localize(
25652556
self,
25662557
tz: TimeZones,
25672558
axis: Axis = 0,
25682559
level: Level | None = None,
2569-
copy: _bool = True,
25702560
ambiguous: TimeAmbiguous = "raise",
25712561
nonexistent: TimeNonexistent = "raise",
25722562
) -> Self: ...

pandas-stubs/core/series.pyi

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,9 +1090,7 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
10901090
def nsmallest(
10911091
self, n: int = 5, keep: NsmallestNlargestKeep = "first"
10921092
) -> Series[S1]: ...
1093-
def swaplevel(
1094-
self, i: Level = -2, j: Level = -1, copy: _bool = True
1095-
) -> Series[S1]: ...
1093+
def swaplevel(self, i: Level = -2, j: Level = -1) -> Series[S1]: ...
10961094
def reorder_levels(self, order: Sequence[int | np.integer]) -> Series[S1]: ...
10971095
def explode(self, ignore_index: _bool = ...) -> Series[S1]: ...
10981096
def unstack(
@@ -1207,7 +1205,6 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
12071205
index: Callable[[Any], Label],
12081206
*,
12091207
axis: Axis | None = ...,
1210-
copy: bool = ...,
12111208
inplace: Literal[True],
12121209
level: Level | None = ...,
12131210
errors: IgnoreRaise = ...,
@@ -1218,7 +1215,6 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
12181215
index: Mapping[Any, Label],
12191216
*,
12201217
axis: Axis | None = ...,
1221-
copy: bool = ...,
12221218
inplace: Literal[True],
12231219
level: Level | None = ...,
12241220
errors: IgnoreRaise = ...,
@@ -1229,7 +1225,6 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
12291225
index: Scalar | tuple[Hashable, ...] | None = None,
12301226
*,
12311227
axis: Axis | None = ...,
1232-
copy: bool = ...,
12331228
inplace: Literal[True],
12341229
level: Level | None = ...,
12351230
errors: IgnoreRaise = ...,
@@ -1240,7 +1235,6 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
12401235
index: Renamer | Scalar | tuple[Hashable, ...] | None = ...,
12411236
*,
12421237
axis: Axis | None = ...,
1243-
copy: bool = ...,
12441238
inplace: Literal[False] = False,
12451239
level: Level | None = ...,
12461240
errors: IgnoreRaise = ...,
@@ -1250,7 +1244,6 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
12501244
self,
12511245
other: Series[S1],
12521246
method: FillnaOptions | Literal["nearest"] | None = None,
1253-
copy: _bool = True,
12541247
limit: int | None = None,
12551248
tolerance: Scalar | AnyArrayLike | Sequence[Scalar] | None = None,
12561249
) -> Self: ...
@@ -1318,11 +1311,8 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
13181311
self,
13191312
freq: PeriodFrequency | None = None,
13201313
how: ToTimestampHow = "start",
1321-
copy: _bool = True,
13221314
) -> Series[S1]: ...
1323-
def to_period(
1324-
self, freq: PeriodFrequency | None = None, copy: _bool = True
1325-
) -> DataFrame: ...
1315+
def to_period(self, freq: PeriodFrequency | None = None) -> DataFrame: ...
13261316
@property
13271317
def str(
13281318
self,
@@ -1374,7 +1364,6 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
13741364
self,
13751365
index: Axes | None = None,
13761366
method: ReindexMethod | None = None,
1377-
copy: bool = True,
13781367
level: int | _str | None = None,
13791368
fill_value: Scalar | None = None,
13801369
limit: int | None = None,
@@ -1406,76 +1395,66 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
14061395
def astype(
14071396
self,
14081397
dtype: BooleanDtypeArg,
1409-
copy: _bool = ...,
14101398
errors: IgnoreRaise = ...,
14111399
) -> Series[bool]: ...
14121400
@overload
14131401
def astype(
14141402
self,
14151403
dtype: IntDtypeArg | UIntDtypeArg,
1416-
copy: _bool = ...,
14171404
errors: IgnoreRaise = ...,
14181405
) -> Series[int]: ...
14191406
@overload
14201407
def astype(
14211408
self,
14221409
dtype: StrDtypeArg,
1423-
copy: _bool = ...,
14241410
errors: IgnoreRaise = ...,
14251411
) -> Series[_str]: ...
14261412
@overload
14271413
def astype(
14281414
self,
14291415
dtype: BytesDtypeArg,
1430-
copy: _bool = ...,
14311416
errors: IgnoreRaise = ...,
14321417
) -> Series[bytes]: ...
14331418
@overload
14341419
def astype(
14351420
self,
14361421
dtype: FloatDtypeArg,
1437-
copy: _bool = ...,
14381422
errors: IgnoreRaise = ...,
14391423
) -> Series[float]: ...
14401424
@overload
14411425
def astype(
14421426
self,
14431427
dtype: ComplexDtypeArg,
1444-
copy: _bool = ...,
14451428
errors: IgnoreRaise = ...,
14461429
) -> Series[complex]: ...
14471430
@overload
14481431
def astype(
14491432
self,
14501433
dtype: TimedeltaDtypeArg | PandasAstypeTimedeltaDtypeArg,
1451-
copy: _bool = ...,
14521434
errors: IgnoreRaise = ...,
14531435
) -> Series[Timedelta]: ...
14541436
@overload
14551437
def astype(
14561438
self,
14571439
dtype: TimestampDtypeArg | PandasAstypeTimestampDtypeArg,
1458-
copy: _bool = ...,
14591440
errors: IgnoreRaise = ...,
14601441
) -> Series[Timestamp]: ...
14611442
@overload
14621443
def astype(
14631444
self,
14641445
dtype: CategoryDtypeArg,
1465-
copy: _bool = ...,
14661446
errors: IgnoreRaise = ...,
14671447
) -> Series[CategoricalDtype]: ...
14681448
@overload
14691449
def astype(
14701450
self,
14711451
dtype: ObjectDtypeArg | VoidDtypeArg | ExtensionDtype | DtypeObj,
1472-
copy: _bool = ...,
14731452
errors: IgnoreRaise = ...,
14741453
) -> Series: ...
14751454
@final
14761455
def copy(self, deep: _bool = True) -> Series[S1]: ...
14771456
@final
1478-
def infer_objects(self, copy: _bool = True) -> Series[S1]: ...
1457+
def infer_objects(self) -> Series[S1]: ...
14791458
def ffill(
14801459
self,
14811460
*,
@@ -1649,23 +1628,20 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
16491628
before: date | _str | int | None = ...,
16501629
after: date | _str | int | None = ...,
16511630
axis: AxisIndex | None = 0,
1652-
copy: _bool = ...,
16531631
) -> Series[S1]: ...
16541632
@final
16551633
def tz_convert(
16561634
self,
16571635
tz: TimeZones,
16581636
axis: AxisIndex = 0,
16591637
level: Level | None = None,
1660-
copy: _bool = True,
16611638
) -> Series[S1]: ...
16621639
@final
16631640
def tz_localize(
16641641
self,
16651642
tz: TimeZones,
16661643
axis: AxisIndex = 0,
16671644
level: Level | None = None,
1668-
copy: _bool = True,
16691645
ambiguous: TimeAmbiguous = "raise",
16701646
nonexistent: _str = "raise",
16711647
) -> Series[S1]: ...
@@ -4628,7 +4604,6 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
46284604
labels: AxesData,
46294605
*,
46304606
axis: Axis = 0,
4631-
copy: _bool | NoDefault = ...,
46324607
) -> Self: ...
46334608
@final
46344609
def xs( # pyright: ignore[reportIncompatibleMethodOverride] # pyrefly: ignore[bad-override] # ty: ignore[invalid-method-override]

tests/frame/test_frame.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,6 +1934,10 @@ def test_types_merge() -> None:
19341934
columns = ["col1", "col2"]
19351935
check(assert_type(df.merge(df2, on=columns), pd.DataFrame), pd.DataFrame)
19361936

1937+
if TYPE_CHECKING_INVALID_USAGE:
1938+
# copy argument is deprecated from 3.0
1939+
_0 = df.merge(df2, copy=True) # type: ignore[call-arg] # pyright: ignore[reportCallIssue,reportUnknownVariableType]
1940+
19371941
# https://github.com/microsoft/python-type-stubs/issues/60
19381942
df1 = pd.DataFrame([["a", 1], ["b", 2]], columns=["let", "num"]).set_index("let")
19391943
s2 = df1["num"]
@@ -3128,6 +3132,10 @@ def test_frame_reindex() -> None:
31283132
pd.DataFrame,
31293133
)
31303134

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

31323140
def test_frame_reindex_like() -> None:
31333141
# GH 84
@@ -3146,6 +3154,10 @@ def test_frame_reindex_like() -> None:
31463154
pd.DataFrame,
31473155
)
31483156

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

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

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

35963612
def test_xs_frame_new() -> None:
35973613
d = {
@@ -3659,6 +3675,10 @@ def test_align() -> None:
36593675
check(assert_type(aligned_df0, pd.DataFrame), pd.DataFrame)
36603676
check(assert_type(aligned_df1, pd.DataFrame), pd.DataFrame)
36613677

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

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

42104230

4231+
def test_frame_copy_deprecated() -> None:
4232+
"""Test that copy argument is deprecated from 3.0 for various DataFrame methods."""
4233+
df = pd.DataFrame({"a": [1, 2, 3]})
4234+
4235+
if TYPE_CHECKING_INVALID_USAGE:
4236+
# truncate
4237+
_0 = df.truncate(copy=True) # type: ignore[call-arg] # pyright: ignore[reportCallIssue,reportUnknownVariableType]
4238+
# tz_convert
4239+
_1 = df.tz_convert("UTC", copy=True) # type: ignore[call-arg] # pyright: ignore[reportCallIssue,reportUnknownVariableType]
4240+
# tz_localize
4241+
_2 = df.tz_localize("UTC", copy=True) # type: ignore[call-arg] # pyright: ignore[reportCallIssue,reportUnknownVariableType]
4242+
# infer_objects
4243+
_3 = df.infer_objects(copy=True) # type: ignore[call-arg] # pyright: ignore[reportCallIssue,reportUnknownVariableType]
4244+
# set_axis
4245+
_4 = df.set_axis([1, 2, 3], copy=True) # type: ignore[call-arg] # pyright: ignore[reportCallIssue,reportUnknownVariableType]
4246+
# to_period
4247+
_5 = df.to_period(copy=True) # type: ignore[call-arg] # pyright: ignore[reportCallIssue,reportUnknownVariableType]
4248+
# to_timestamp
4249+
_6 = df.to_timestamp(copy=True) # type: ignore[call-arg] # pyright: ignore[reportCallIssue,reportUnknownVariableType]
4250+
4251+
42114252
def test_rolling_first() -> None:
42124253
"""Test DataFrame.rolling.first method."""
42134254
df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6], "C": [7, 8, 9]})

0 commit comments

Comments
 (0)