Skip to content

Stacklevel argument updated #46687 #47035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 30, 2022
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ Other Deprecations
- Deprecated the ``closed`` argument in :meth:`interval_range` in favor of ``inclusive`` argument; In a future version passing ``closed`` will raise (:issue:`40245`)
- Deprecated the methods :meth:`DataFrame.mad`, :meth:`Series.mad`, and the corresponding groupby methods (:issue:`11787`)
- Deprecated positional arguments to :meth:`Index.join` except for ``other``, use keyword-only arguments instead of positional arguments (:issue:`46518`)
- Deprecated passing arguments as positional in :meth:`stacklevel` (:issue:`46687`)

.. ---------------------------------------------------------------------------
.. _whatsnew_150.performance:
Expand Down
12 changes: 3 additions & 9 deletions pandas/io/parsers/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,9 +828,7 @@ def read_csv(
...


@deprecate_nonkeyword_arguments(
version=None, allowed_args=["filepath_or_buffer"], stacklevel=3
)
@deprecate_nonkeyword_arguments(version=None, allowed_args=["filepath_or_buffer"])
@Appender(
_doc_read_csv_and_table.format(
func_name="read_csv",
Expand Down Expand Up @@ -1167,9 +1165,7 @@ def read_table(
...


@deprecate_nonkeyword_arguments(
version=None, allowed_args=["filepath_or_buffer"], stacklevel=3
)
@deprecate_nonkeyword_arguments(version=None, allowed_args=["filepath_or_buffer"])
@Appender(
_doc_read_csv_and_table.format(
func_name="read_table",
Expand Down Expand Up @@ -1266,9 +1262,7 @@ def read_table(
return _read(filepath_or_buffer, kwds)


@deprecate_nonkeyword_arguments(
version=None, allowed_args=["filepath_or_buffer"], stacklevel=2
)
@deprecate_nonkeyword_arguments(version=None, allowed_args=["filepath_or_buffer"])
def read_fwf(
filepath_or_buffer: FilePath | ReadCsvBuffer[bytes] | ReadCsvBuffer[str],
colspecs: Sequence[tuple[int, int]] | str | None = "infer",
Expand Down
6 changes: 4 additions & 2 deletions pandas/util/_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from pandas._libs.properties import cache_readonly # noqa:F401
from pandas._typing import F
from pandas.util._exceptions import find_stack_level


def deprecate(
Expand Down Expand Up @@ -260,7 +261,7 @@ def future_version_msg(version: str | None) -> str:
def deprecate_nonkeyword_arguments(
version: str | None,
allowed_args: list[str] | None = None,
stacklevel: int = 2,
stacklevel: int = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you're defining it below (L308), you don't need it as argument any more, do you?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I will remove it. Also should I check other files for definition of stacklevel and change them?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should remove it from the docstring as well

name: str | None = None,
) -> Callable[[F], F]:
"""
Expand All @@ -280,7 +281,7 @@ def deprecate_nonkeyword_arguments(
defaults to list of all arguments not having the
default value.

stacklevel : int, default=2
stacklevel : int
The stack level for warnings.warn

name : str, optional
Expand All @@ -304,6 +305,7 @@ def decorate(func):
f"{future_version_msg(version)} all arguments of "
f"{name or func.__qualname__}{{arguments}} will be keyword-only."
)
stacklevel = find_stack_level()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in L317, you should just set

stacklevel=find_stack_level()

rather than assigning it here


@wraps(func)
def wrapper(*args, **kwargs):
Expand Down