Skip to content

Commit a6d64d1

Browse files
committed
Merge remote-tracking branch 'upstream/master' into deprecate-nonkeyword-args-clip
2 parents b4dec9e + a246270 commit a6d64d1

38 files changed

+325
-65
lines changed

doc/source/whatsnew/v1.3.0.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,9 @@ Deprecations
648648
- Deprecated setting :attr:`Categorical._codes`, create a new :class:`Categorical` with the desired codes instead (:issue:`40606`)
649649
- Deprecated behavior of :meth:`DatetimeIndex.union` with mixed timezones; in a future version both will be cast to UTC instead of object dtype (:issue:`39328`)
650650
- Deprecated using ``usecols`` with out of bounds indices for ``read_csv`` with ``engine="c"`` (:issue:`25623`)
651-
- Deprecated passing arguments (other than ``"lower"`` and ``"upper"``) as positional in :meth:`DataFrame.clip` and :meth:`Series.clip` (:issue:`41485`)
651+
- Deprecated passing arguments as positional in (:issue:`41485`) :
652+
- :meth:`DataFrame.clip` and :meth:`Series.clip` (other than ``"lower"`` and ``"upper"``)
653+
- :meth:`DataFrame.interpolate` (other than ``"method"``) and :meth:`Series.interpolate`
652654

653655
.. ---------------------------------------------------------------------------
654656

pandas/core/arrays/datetimelike.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,9 @@ def _validate_shift_value(self, fill_value):
599599
"will raise in a future version, pass "
600600
f"{self._scalar_type.__name__} instead.",
601601
FutureWarning,
602-
stacklevel=8,
602+
# There is no way to hard-code the level since this might be
603+
# reached directly or called from the Index or Block method
604+
stacklevel=find_stack_level(),
603605
)
604606
fill_value = new_fill
605607

pandas/core/arrays/datetimes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,7 @@ def to_perioddelta(self, freq) -> TimedeltaArray:
11751175
"future version. "
11761176
"Use `dtindex - dtindex.to_period(freq).to_timestamp()` instead",
11771177
FutureWarning,
1178+
# stacklevel chosen to be correct for when called from DatetimeIndex
11781179
stacklevel=3,
11791180
)
11801181
from pandas.core.arrays.timedeltas import TimedeltaArray

pandas/core/frame.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,6 +1764,7 @@ def to_dict(self, orient: str = "dict", into=dict):
17641764
"will be used in a future version. Use one of the above "
17651765
"to silence this warning.",
17661766
FutureWarning,
1767+
stacklevel=2,
17671768
)
17681769

17691770
if orient.startswith("d"):
@@ -10647,6 +10648,29 @@ def clip(
1064710648
) -> DataFrame | None:
1064810649
return super().clip(lower, upper, axis, inplace, *args, **kwargs)
1064910650

10651+
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "method"])
10652+
def interpolate(
10653+
self: DataFrame,
10654+
method: str = "linear",
10655+
axis: Axis = 0,
10656+
limit: int | None = None,
10657+
inplace: bool = False,
10658+
limit_direction: str | None = None,
10659+
limit_area: str | None = None,
10660+
downcast: str | None = None,
10661+
**kwargs,
10662+
) -> DataFrame | None:
10663+
return super().interpolate(
10664+
method,
10665+
axis,
10666+
limit,
10667+
inplace,
10668+
limit_direction,
10669+
limit_area,
10670+
downcast,
10671+
**kwargs,
10672+
)
10673+
1065010674

1065110675
DataFrame._add_numeric_operations()
1065210676

pandas/core/generic.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,13 +481,19 @@ def _data(self):
481481
@property
482482
def _AXIS_NUMBERS(self) -> dict[str, int]:
483483
""".. deprecated:: 1.1.0"""
484-
warnings.warn("_AXIS_NUMBERS has been deprecated.", FutureWarning, stacklevel=3)
484+
level = self.ndim + 1
485+
warnings.warn(
486+
"_AXIS_NUMBERS has been deprecated.", FutureWarning, stacklevel=level
487+
)
485488
return {"index": 0}
486489

487490
@property
488491
def _AXIS_NAMES(self) -> dict[int, str]:
489492
""".. deprecated:: 1.1.0"""
490-
warnings.warn("_AXIS_NAMES has been deprecated.", FutureWarning, stacklevel=3)
493+
level = self.ndim + 1
494+
warnings.warn(
495+
"_AXIS_NAMES has been deprecated.", FutureWarning, stacklevel=level
496+
)
491497
return {0: "index"}
492498

493499
@final
@@ -6696,7 +6702,6 @@ def replace(
66966702
else:
66976703
return result.__finalize__(self, method="replace")
66986704

6699-
@final
67006705
def interpolate(
67016706
self: FrameOrSeries,
67026707
method: str = "linear",

pandas/core/indexes/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3691,7 +3691,7 @@ def is_int(v):
36913691
"and will raise TypeError in a future version. "
36923692
"Use .loc with labels or .iloc with positions instead.",
36933693
FutureWarning,
3694-
stacklevel=6,
3694+
stacklevel=5,
36953695
)
36963696
indexer = key
36973697
else:

pandas/core/indexes/datetimes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
cache_readonly,
4141
doc,
4242
)
43+
from pandas.util._exceptions import find_stack_level
4344

4445
from pandas.core.dtypes.common import (
4546
DT64NS_DTYPE,
@@ -660,7 +661,7 @@ def _deprecate_mismatched_indexing(self, key) -> None:
660661
"raise KeyError in a future version. "
661662
"Use a timezone-aware object instead."
662663
)
663-
warnings.warn(msg, FutureWarning, stacklevel=5)
664+
warnings.warn(msg, FutureWarning, stacklevel=find_stack_level())
664665

665666
def get_loc(self, key, method=None, tolerance=None):
666667
"""

pandas/core/reshape/merge.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,8 @@ def __init__(
673673
f"in a future version. ({left.columns.nlevels} levels on the left,"
674674
f"{right.columns.nlevels} on the right)"
675675
)
676+
# stacklevel chosen to be correct when this is reached via pd.merge
677+
# (and not DataFrame.join)
676678
warnings.warn(msg, FutureWarning, stacklevel=3)
677679

678680
self._validate_specification()

pandas/core/series.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5271,6 +5271,29 @@ def clip(
52715271
) -> Series | None:
52725272
return super().clip(lower, upper, axis, inplace, *args, **kwargs)
52735273

5274+
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "method"])
5275+
def interpolate(
5276+
self: Series,
5277+
method: str = "linear",
5278+
axis: Axis = 0,
5279+
limit: int | None = None,
5280+
inplace: bool = False,
5281+
limit_direction: str | None = None,
5282+
limit_area: str | None = None,
5283+
downcast: str | None = None,
5284+
**kwargs,
5285+
) -> Series | None:
5286+
return super().interpolate(
5287+
method,
5288+
axis,
5289+
limit,
5290+
inplace,
5291+
limit_direction,
5292+
limit_area,
5293+
downcast,
5294+
**kwargs,
5295+
)
5296+
52745297
# ----------------------------------------------------------------------
52755298
# Add index
52765299
_AXIS_ORDERS = ["index"]

pandas/tests/arrays/test_datetimelike.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,8 @@ def test_shift_fill_int_deprecated(self):
561561
data = np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9
562562
arr = self.array_cls(data, freq="D")
563563

564-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
564+
msg = "Passing <class 'int'> to shift"
565+
with tm.assert_produces_warning(FutureWarning, match=msg):
565566
result = arr.shift(1, fill_value=1)
566567

567568
expected = arr.copy()
@@ -783,10 +784,13 @@ def test_to_perioddelta(self, datetime_index, freqstr):
783784
dti = datetime_index
784785
arr = DatetimeArray(dti)
785786

786-
with tm.assert_produces_warning(FutureWarning):
787+
msg = "to_perioddelta is deprecated and will be removed"
788+
with tm.assert_produces_warning(FutureWarning, match=msg):
787789
# Deprecation GH#34853
788790
expected = dti.to_perioddelta(freq=freqstr)
789-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
791+
with tm.assert_produces_warning(
792+
FutureWarning, match=msg, check_stacklevel=False
793+
):
790794
# stacklevel is chosen to be "correct" for DatetimeIndex, not
791795
# DatetimeArray
792796
result = arr.to_perioddelta(freq=freqstr)

0 commit comments

Comments
 (0)