Skip to content

Commit 642957e

Browse files
committed
Stacklevel argument updated pandas-dev#46687
1 parent 6f33c46 commit 642957e

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

doc/source/whatsnew/v1.5.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ Other Deprecations
553553
- Deprecated the ``closed`` argument in :meth:`interval_range` in favor of ``inclusive`` argument; In a future version passing ``closed`` will raise (:issue:`40245`)
554554
- Deprecated the methods :meth:`DataFrame.mad`, :meth:`Series.mad`, and the corresponding groupby methods (:issue:`11787`)
555555
- Deprecated positional arguments to :meth:`Index.join` except for ``other``, use keyword-only arguments instead of positional arguments (:issue:`46518`)
556+
- Deprecated passing arguments as positional in :meth:`stacklevel` (:issue:`46687`)
556557

557558
.. ---------------------------------------------------------------------------
558559
.. _whatsnew_150.performance:

pandas/io/parsers/readers.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -828,9 +828,7 @@ def read_csv(
828828
...
829829

830830

831-
@deprecate_nonkeyword_arguments(
832-
version=None, allowed_args=["filepath_or_buffer"], stacklevel=3
833-
)
831+
@deprecate_nonkeyword_arguments(version=None, allowed_args=["filepath_or_buffer"])
834832
@Appender(
835833
_doc_read_csv_and_table.format(
836834
func_name="read_csv",
@@ -1167,9 +1165,7 @@ def read_table(
11671165
...
11681166

11691167

1170-
@deprecate_nonkeyword_arguments(
1171-
version=None, allowed_args=["filepath_or_buffer"], stacklevel=3
1172-
)
1168+
@deprecate_nonkeyword_arguments(version=None, allowed_args=["filepath_or_buffer"])
11731169
@Appender(
11741170
_doc_read_csv_and_table.format(
11751171
func_name="read_table",
@@ -1266,9 +1262,7 @@ def read_table(
12661262
return _read(filepath_or_buffer, kwds)
12671263

12681264

1269-
@deprecate_nonkeyword_arguments(
1270-
version=None, allowed_args=["filepath_or_buffer"], stacklevel=2
1271-
)
1265+
@deprecate_nonkeyword_arguments(version=None, allowed_args=["filepath_or_buffer"])
12721266
def read_fwf(
12731267
filepath_or_buffer: FilePath | ReadCsvBuffer[bytes] | ReadCsvBuffer[str],
12741268
colspecs: Sequence[tuple[int, int]] | str | None = "infer",

pandas/util/_decorators.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from pandas._libs.properties import cache_readonly # noqa:F401
1515
from pandas._typing import F
16+
from pandas.util._exceptions import find_stack_level
1617

1718

1819
def deprecate(
@@ -260,7 +261,7 @@ def future_version_msg(version: str | None) -> str:
260261
def deprecate_nonkeyword_arguments(
261262
version: str | None,
262263
allowed_args: list[str] | None = None,
263-
stacklevel: int = 2,
264+
stacklevel: int = None,
264265
name: str | None = None,
265266
) -> Callable[[F], F]:
266267
"""
@@ -280,7 +281,7 @@ def deprecate_nonkeyword_arguments(
280281
defaults to list of all arguments not having the
281282
default value.
282283
283-
stacklevel : int, default=2
284+
stacklevel : int
284285
The stack level for warnings.warn
285286
286287
name : str, optional
@@ -304,6 +305,7 @@ def decorate(func):
304305
f"{future_version_msg(version)} all arguments of "
305306
f"{name or func.__qualname__}{{arguments}} will be keyword-only."
306307
)
308+
stacklevel = find_stack_level()
307309

308310
@wraps(func)
309311
def wrapper(*args, **kwargs):

0 commit comments

Comments
 (0)