@@ -4251,12 +4251,24 @@ def _is_view(self) -> bool:
4251
4251
"""Return boolean indicating if self is view of another array"""
4252
4252
return self ._mgr .is_view
4253
4253
4254
+ @staticmethod
4255
+ def _check_copy_deprecation (copy ):
4256
+ if copy is not lib .no_default :
4257
+ warnings .warn (
4258
+ "The copy keyword is deprecated and will be removed in a future "
4259
+ "version. Copy-on-Write is active in pandas since 3.0 which utilizes "
4260
+ "a lazy copy mechanism that defers copies until necessary. Use "
4261
+ ".copy() to make an eager copy if necessary." ,
4262
+ DeprecationWarning ,
4263
+ stacklevel = find_stack_level (),
4264
+ )
4265
+
4254
4266
@final
4255
4267
def reindex_like (
4256
4268
self ,
4257
4269
other ,
4258
4270
method : Literal ["backfill" , "bfill" , "pad" , "ffill" , "nearest" ] | None = None ,
4259
- copy : bool | None = None ,
4271
+ copy : bool | lib . NoDefault = lib . no_default ,
4260
4272
limit : int | None = None ,
4261
4273
tolerance = None ,
4262
4274
) -> Self :
@@ -4284,7 +4296,7 @@ def reindex_like(
4284
4296
* backfill / bfill: use next valid observation to fill gap
4285
4297
* nearest: use nearest valid observations to fill gap.
4286
4298
4287
- copy : bool, default True
4299
+ copy : bool, default False
4288
4300
Return a new object, even if the passed indexes are the same.
4289
4301
4290
4302
.. note::
@@ -4298,6 +4310,8 @@ def reindex_like(
4298
4310
4299
4311
You can already get the future behavior and improvements through
4300
4312
enabling copy on write ``pd.options.mode.copy_on_write = True``
4313
+
4314
+ .. deprecated:: 3.0.0
4301
4315
limit : int, default None
4302
4316
Maximum number of consecutive labels to fill for inexact matches.
4303
4317
tolerance : optional
@@ -4366,6 +4380,7 @@ def reindex_like(
4366
4380
2014-02-14 NaN NaN NaN
4367
4381
2014-02-15 35.1 NaN medium
4368
4382
"""
4383
+ self ._check_copy_deprecation (copy )
4369
4384
d = other ._construct_axes_dict (
4370
4385
axes = self ._AXIS_ORDERS ,
4371
4386
method = method ,
@@ -5011,7 +5026,7 @@ def reindex(
5011
5026
columns = None ,
5012
5027
axis : Axis | None = None ,
5013
5028
method : ReindexMethod | None = None ,
5014
- copy : bool | None = None ,
5029
+ copy : bool | lib . NoDefault = lib . no_default ,
5015
5030
level : Level | None = None ,
5016
5031
fill_value : Scalar | None = np .nan ,
5017
5032
limit : int | None = None ,
@@ -5038,7 +5053,7 @@ def reindex(
5038
5053
* backfill / bfill: Use next valid observation to fill gap.
5039
5054
* nearest: Use nearest valid observations to fill gap.
5040
5055
5041
- copy : bool, default True
5056
+ copy : bool, default False
5042
5057
Return a new object, even if the passed indexes are the same.
5043
5058
5044
5059
.. note::
@@ -5052,6 +5067,8 @@ def reindex(
5052
5067
5053
5068
You can already get the future behavior and improvements through
5054
5069
enabling copy on write ``pd.options.mode.copy_on_write = True``
5070
+
5071
+ .. deprecated:: 3.0.0
5055
5072
level : int or name
5056
5073
Broadcast across a level, matching Index values on the
5057
5074
passed MultiIndex level.
@@ -5229,6 +5246,7 @@ def reindex(
5229
5246
"""
5230
5247
# TODO: Decide if we care about having different examples for different
5231
5248
# kinds
5249
+ self ._check_copy_deprecation (copy )
5232
5250
5233
5251
if index is not None and columns is not None and labels is not None :
5234
5252
raise TypeError ("Cannot specify all of 'labels', 'index', 'columns'." )
@@ -6136,7 +6154,10 @@ def dtypes(self):
6136
6154
6137
6155
@final
6138
6156
def astype (
6139
- self , dtype , copy : bool | None = None , errors : IgnoreRaise = "raise"
6157
+ self ,
6158
+ dtype ,
6159
+ copy : bool | lib .NoDefault = lib .no_default ,
6160
+ errors : IgnoreRaise = "raise" ,
6140
6161
) -> Self :
6141
6162
"""
6142
6163
Cast a pandas object to a specified dtype ``dtype``.
@@ -6149,7 +6170,7 @@ def astype(
6149
6170
mapping, e.g. {col: dtype, ...}, where col is a column label and dtype is
6150
6171
a numpy.dtype or Python type to cast one or more of the DataFrame's
6151
6172
columns to column-specific types.
6152
- copy : bool, default True
6173
+ copy : bool, default False
6153
6174
Return a copy when ``copy=True`` (be very careful setting
6154
6175
``copy=False`` as changes to values then may propagate to other
6155
6176
pandas objects).
@@ -6165,6 +6186,8 @@ def astype(
6165
6186
6166
6187
You can already get the future behavior and improvements through
6167
6188
enabling copy on write ``pd.options.mode.copy_on_write = True``
6189
+
6190
+ .. deprecated:: 3.0.0
6168
6191
errors : {'raise', 'ignore'}, default 'raise'
6169
6192
Control raising of exceptions on invalid data for provided dtype.
6170
6193
@@ -6254,6 +6277,7 @@ def astype(
6254
6277
2 2020-01-03
6255
6278
dtype: datetime64[ns]
6256
6279
"""
6280
+ self ._check_copy_deprecation (copy )
6257
6281
if is_dict_like (dtype ):
6258
6282
if self .ndim == 1 : # i.e. Series
6259
6283
if len (dtype ) > 1 or self .name not in dtype :
@@ -6481,7 +6505,7 @@ def __deepcopy__(self, memo=None) -> Self:
6481
6505
return self .copy (deep = True )
6482
6506
6483
6507
@final
6484
- def infer_objects (self , copy : bool | None = None ) -> Self :
6508
+ def infer_objects (self , copy : bool | lib . NoDefault = lib . no_default ) -> Self :
6485
6509
"""
6486
6510
Attempt to infer better dtypes for object columns.
6487
6511
@@ -6492,7 +6516,7 @@ def infer_objects(self, copy: bool | None = None) -> Self:
6492
6516
6493
6517
Parameters
6494
6518
----------
6495
- copy : bool, default True
6519
+ copy : bool, default False
6496
6520
Whether to make a copy for non-object or non-inferable columns
6497
6521
or Series.
6498
6522
@@ -6508,6 +6532,8 @@ def infer_objects(self, copy: bool | None = None) -> Self:
6508
6532
You can already get the future behavior and improvements through
6509
6533
enabling copy on write ``pd.options.mode.copy_on_write = True``
6510
6534
6535
+ .. deprecated:: 3.0.0
6536
+
6511
6537
Returns
6512
6538
-------
6513
6539
same type as input object
@@ -6537,6 +6563,7 @@ def infer_objects(self, copy: bool | None = None) -> Self:
6537
6563
A int64
6538
6564
dtype: object
6539
6565
"""
6566
+ self ._check_copy_deprecation (copy )
6540
6567
new_mgr = self ._mgr .convert ()
6541
6568
res = self ._constructor_from_mgr (new_mgr , axes = new_mgr .axes )
6542
6569
return res .__finalize__ (self , method = "infer_objects" )
@@ -9404,7 +9431,7 @@ def align(
9404
9431
join : AlignJoin = "outer" ,
9405
9432
axis : Axis | None = None ,
9406
9433
level : Level | None = None ,
9407
- copy : bool | None = None ,
9434
+ copy : bool | lib . NoDefault = lib . no_default ,
9408
9435
fill_value : Hashable | None = None ,
9409
9436
) -> tuple [Self , NDFrameT ]:
9410
9437
"""
@@ -9429,7 +9456,7 @@ def align(
9429
9456
level : int or level name, default None
9430
9457
Broadcast across a level, matching Index values on the
9431
9458
passed MultiIndex level.
9432
- copy : bool, default True
9459
+ copy : bool, default False
9433
9460
Always returns new objects. If copy=False and no reindexing is
9434
9461
required then original objects are returned.
9435
9462
@@ -9444,6 +9471,8 @@ def align(
9444
9471
9445
9472
You can already get the future behavior and improvements through
9446
9473
enabling copy on write ``pd.options.mode.copy_on_write = True``
9474
+
9475
+ .. deprecated:: 3.0.0
9447
9476
fill_value : scalar, default np.nan
9448
9477
Value to use for missing values. Defaults to NaN, but can be any
9449
9478
"compatible" value.
@@ -9518,6 +9547,8 @@ def align(
9518
9547
3 60.0 70.0 80.0 90.0 NaN
9519
9548
4 600.0 700.0 800.0 900.0 NaN
9520
9549
"""
9550
+ self ._check_copy_deprecation (copy )
9551
+
9521
9552
_right : DataFrame | Series
9522
9553
if axis is not None :
9523
9554
axis = self ._get_axis_number (axis )
@@ -10336,7 +10367,7 @@ def truncate(
10336
10367
before = None ,
10337
10368
after = None ,
10338
10369
axis : Axis | None = None ,
10339
- copy : bool | None = None ,
10370
+ copy : bool | lib . NoDefault = lib . no_default ,
10340
10371
) -> Self :
10341
10372
"""
10342
10373
Truncate a Series or DataFrame before and after some index value.
@@ -10353,7 +10384,7 @@ def truncate(
10353
10384
axis : {0 or 'index', 1 or 'columns'}, optional
10354
10385
Axis to truncate. Truncates the index (rows) by default.
10355
10386
For `Series` this parameter is unused and defaults to 0.
10356
- copy : bool, default is True ,
10387
+ copy : bool, default is False ,
10357
10388
Return a copy of the truncated section.
10358
10389
10359
10390
.. note::
@@ -10368,6 +10399,8 @@ def truncate(
10368
10399
You can already get the future behavior and improvements through
10369
10400
enabling copy on write ``pd.options.mode.copy_on_write = True``
10370
10401
10402
+ .. deprecated:: 3.0.0
10403
+
10371
10404
Returns
10372
10405
-------
10373
10406
type of caller
@@ -10473,6 +10506,8 @@ def truncate(
10473
10506
2016-01-10 23:59:58 1
10474
10507
2016-01-10 23:59:59 1
10475
10508
"""
10509
+ self ._check_copy_deprecation (copy )
10510
+
10476
10511
if axis is None :
10477
10512
axis = 0
10478
10513
axis = self ._get_axis_number (axis )
@@ -10511,7 +10546,11 @@ def truncate(
10511
10546
@final
10512
10547
@doc (klass = _shared_doc_kwargs ["klass" ])
10513
10548
def tz_convert (
10514
- self , tz , axis : Axis = 0 , level = None , copy : bool | None = None
10549
+ self ,
10550
+ tz ,
10551
+ axis : Axis = 0 ,
10552
+ level = None ,
10553
+ copy : bool | lib .NoDefault = lib .no_default ,
10515
10554
) -> Self :
10516
10555
"""
10517
10556
Convert tz-aware axis to target time zone.
@@ -10526,7 +10565,7 @@ def tz_convert(
10526
10565
level : int, str, default None
10527
10566
If axis is a MultiIndex, convert a specific level. Otherwise
10528
10567
must be None.
10529
- copy : bool, default True
10568
+ copy : bool, default False
10530
10569
Also make a copy of the underlying data.
10531
10570
10532
10571
.. note::
@@ -10541,6 +10580,8 @@ def tz_convert(
10541
10580
You can already get the future behavior and improvements through
10542
10581
enabling copy on write ``pd.options.mode.copy_on_write = True``
10543
10582
10583
+ .. deprecated:: 3.0.0
10584
+
10544
10585
Returns
10545
10586
-------
10546
10587
{klass}
@@ -10570,6 +10611,7 @@ def tz_convert(
10570
10611
2018-09-14 23:30:00 1
10571
10612
dtype: int64
10572
10613
"""
10614
+ self ._check_copy_deprecation (copy )
10573
10615
axis = self ._get_axis_number (axis )
10574
10616
ax = self ._get_axis (axis )
10575
10617
@@ -10607,7 +10649,7 @@ def tz_localize(
10607
10649
tz ,
10608
10650
axis : Axis = 0 ,
10609
10651
level = None ,
10610
- copy : bool | None = None ,
10652
+ copy : bool | lib . NoDefault = lib . no_default ,
10611
10653
ambiguous : TimeAmbiguous = "raise" ,
10612
10654
nonexistent : TimeNonexistent = "raise" ,
10613
10655
) -> Self :
@@ -10627,7 +10669,7 @@ def tz_localize(
10627
10669
level : int, str, default None
10628
10670
If axis ia a MultiIndex, localize a specific level. Otherwise
10629
10671
must be None.
10630
- copy : bool, default True
10672
+ copy : bool, default False
10631
10673
Also make a copy of the underlying data.
10632
10674
10633
10675
.. note::
@@ -10641,6 +10683,8 @@ def tz_localize(
10641
10683
10642
10684
You can already get the future behavior and improvements through
10643
10685
enabling copy on write ``pd.options.mode.copy_on_write = True``
10686
+
10687
+ .. deprecated:: 3.0.0
10644
10688
ambiguous : 'infer', bool, bool-ndarray, 'NaT', default 'raise'
10645
10689
When clocks moved backward due to DST, ambiguous times may arise.
10646
10690
For example in Central European Time (UTC+01), when going from
@@ -10766,6 +10810,7 @@ def tz_localize(
10766
10810
2015-03-29 03:30:00+02:00 1
10767
10811
dtype: int64
10768
10812
"""
10813
+ self ._check_copy_deprecation (copy )
10769
10814
nonexistent_options = ("raise" , "NaT" , "shift_forward" , "shift_backward" )
10770
10815
if nonexistent not in nonexistent_options and not isinstance (
10771
10816
nonexistent , dt .timedelta
@@ -11720,7 +11765,7 @@ def _inplace_method(self, other, op) -> Self:
11720
11765
11721
11766
# this makes sure that we are aligned like the input
11722
11767
# we are updating inplace
11723
- self ._update_inplace (result .reindex_like (self , copy = False ))
11768
+ self ._update_inplace (result .reindex_like (self ))
11724
11769
return self
11725
11770
11726
11771
@final
0 commit comments