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

Conversation

Anupam-USP
Copy link
Contributor

@Anupam-USP Anupam-USP commented May 16, 2022

@Anupam-USP
Copy link
Contributor Author

Can you suggest me some test to write for these?

@MarcoGorelli MarcoGorelli self-requested a review May 16, 2022 22:13
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

this is just an internal refactor, so as long as the current test-suite passes, no new tests should be necessary

Comment on lines 263 to 264
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

@MarcoGorelli
Copy link
Member

currently failing with

ImportError while loading conftest 'D:\a\pandas\pandas\pandas\conftest.py'.
pandas\__init__.py:48: in <module>
    from pandas.core.api import (
pandas\core\api.py:48: in <module>
    from pandas.core.groupby import (
pandas\core\groupby\__init__.py:1: in <module>
    from pandas.core.groupby.generic import (
pandas\core\groupby\generic.py:73: in <module>
    from pandas.core.frame import DataFrame
pandas\core\frame.py:202: in <module>
    from pandas.core.series import Series
pandas\core\series.py:5865: in <module>
    Series._add_numeric_operations()
pandas\core\generic.py:10950: in _add_numeric_operations
    @deprecate_nonkeyword_arguments(
E   TypeError: deprecate_nonkeyword_arguments() got an unexpected keyword argument 'stacklevel'

@Anupam-USP
Copy link
Contributor Author

Hey @MarcoGorelli I tried changing the files and ran conftest.py to check, but getting errors like AttributeError: module 'pandas._testing' has no attribute 'make_rand_series' so not able to check the changes I have made. What can I do?

@MarcoGorelli
Copy link
Member

hey @Anupam-USP - what command did you run that gave you that output?

You might need to re-compile the C extensions (python setup.py build_ext -j 4)

@jreback jreback added the Clean label May 21, 2022
@Anupam-USP
Copy link
Contributor Author

To overcome the aforementioned issue, I have to still declare it as I did previously.

@MarcoGorelli MarcoGorelli self-requested a review May 23, 2022 09:37
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

To overcome

E   TypeError: deprecate_nonkeyword_arguments() got an unexpected keyword argument 'stacklevel'

you should remove calls of deprecate_nonkeyword_arguments where stacklevel is passed

To address the other issue, you probably just need to recompile the C extensions (python setup.py build_ext -j 4). There should be no need to keep stacklevel as an argument to deprecate_nonkeyword_arguments

@@ -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

@jreback
Copy link
Contributor

jreback commented Jun 5, 2022

@Anupam-USP what's new entry not needed as this is not public (i removed it)

@MarcoGorelli
Copy link
Member

couple of test failures, I'll take a look later

=================================== FAILURES ===================================
__________________ test_read_csv_posargs_deprecation[pyarrow] __________________
[gw0] linux -- Python 3.8.13 /usr/share/miniconda/envs/test/bin/python
all_parsers = <pandas.tests.io.parser.conftest.PyArrowParser object at 0x7f33cf300970>
    def test_read_csv_posargs_deprecation(all_parsers):
        # GH 41485
        f = StringIO("a,b\n1,2")
        parser = all_parsers
        msg = (
            "In a future version of pandas all arguments of read_csv "
            "except for the argument 'filepath_or_buffer' will be keyword-only"
        )
        with tm.assert_produces_warning(FutureWarning, match=msg):
>           parser.read_csv(f, " ")
pandas/tests/io/parser/common/test_common_basic.py:810: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/share/miniconda/envs/test/lib/python3.8/contextlib.py:120: in __exit__
    next(self.gen)
pandas/_testing/_warnings.py:135: in _assert_caught_expected_warning
    _assert_raised_with_correct_stacklevel(actual_warning)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
actual_warning = <warnings.WarningMessage object at 0x7f33cd100820>
    def _assert_raised_with_correct_stacklevel(
        actual_warning: warnings.WarningMessage,
    ) -> None:
        from inspect import (
            getframeinfo,
            stack,
        )
        caller = getframeinfo(stack()[4][0])
        msg = (
            "Warning not set with correct stacklevel. "
            f"File where warning is raised: {actual_warning.filename} != "
            f"{caller.filename}. Warning message: {actual_warning.message}"
        )
>       assert actual_warning.filename == caller.filename, msg
E       AssertionError: Warning not set with correct stacklevel. File where warning is raised: /home/runner/work/pandas/pandas/pandas/tests/io/parser/conftest.py != /home/runner/work/pandas/pandas/pandas/tests/io/parser/common/test_common_basic.py. Warning message: In a future version of pandas all arguments of read_csv except for the argument 'filepath_or_buffer' will be keyword-only.
pandas/_testing/_warnings.py:221: AssertionError
_________________ test_read_table_posargs_deprecation[pyarrow] _________________
[gw0] linux -- Python 3.8.13 /usr/share/miniconda/envs/test/bin/python
all_parsers = <pandas.tests.io.parser.conftest.PyArrowParser object at 0x7f33d4eab5e0>
    def test_read_table_posargs_deprecation(all_parsers):
        # https://github.com/pandas-dev/pandas/issues/41485
        data = StringIO("a\tb\n1\t2")
        parser = all_parsers
        msg = (
            "In a future version of pandas all arguments of read_table "
            "except for the argument 'filepath_or_buffer' will be keyword-only"
        )
        with tm.assert_produces_warning(FutureWarning, match=msg):
>           parser.read_table(data, " ")
pandas/tests/io/parser/common/test_common_basic.py:925: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/share/miniconda/envs/test/lib/python3.8/contextlib.py:120: in __exit__
    next(self.gen)
pandas/_testing/_warnings.py:135: in _assert_caught_expected_warning
    _assert_raised_with_correct_stacklevel(actual_warning)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
actual_warning = <warnings.WarningMessage object at 0x7f33d4eab[52](https://github.com/pandas-dev/pandas/runs/6895416344?check_suite_focus=true#step:8:54)0>
    def _assert_raised_with_correct_stacklevel(
        actual_warning: warnings.WarningMessage,
    ) -> None:
        from inspect import (
            getframeinfo,
            stack,
        )
        caller = getframeinfo(stack()[4][0])
        msg = (
            "Warning not set with correct stacklevel. "
            f"File where warning is raised: {actual_warning.filename} != "
            f"{caller.filename}. Warning message: {actual_warning.message}"
        )
>       assert actual_warning.filename == caller.filename, msg
E       AssertionError: Warning not set with correct stacklevel. File where warning is raised: /home/runner/work/pandas/pandas/pandas/tests/io/parser/conftest.py != /home/runner/work/pandas/pandas/pandas/tests/io/parser/common/test_common_basic.py. Warning message: In a future version of pandas all arguments of read_table except for the argument 'filepath_or_buffer' will be keyword-only.
pandas/_testing/_warnings.py:221: AssertionError
=============================== warnings summary ===============================
pandas/tests/io/parser/test_parse_dates.py::test_date_parser_resolution_if_not_ns[pyarrow]
  /home/runner/work/pandas/pandas/pandas/tests/io/parser/conftest.py:29: FutureWarning: 
          Use pd.to_datetime instead.
    return read_csv(*args, **kwargs)
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
------ generated xml file: /home/runner/work/pandas/pandas/test-data.xml -------
---------- coverage: platform linux, python 3.8.13-final-0 -----------
Coverage XML written to file coverage.xml

@MarcoGorelli
Copy link
Member

As noted here #47385 , I think the test failure might be a false-positive. Will try to address that one first

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

Have fixed this up, I think it should be fine now and that the failed job had an unrelated failure (re-running to check)

@MarcoGorelli MarcoGorelli added this to the 1.5 milestone Jun 27, 2022
@mroeschke mroeschke merged commit 32cb5aa into pandas-dev:main Jun 30, 2022
@mroeschke
Copy link
Member

Thanks @Anupam-USP and @MarcoGorelli

yehoshuadimarsky pushed a commit to yehoshuadimarsky/pandas that referenced this pull request Jul 13, 2022
* Stacklevel argument updated pandas-dev#46687

* argument removed

* param added

* fixup

* remove stackevel from read_sas decorator

* add read_table_check_warnings and use it in read_table posargs deprecation test

Co-authored-by: Jeff Reback <[email protected]>
Co-authored-by: Marco Gorelli <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CLN find stacklevel inside deprecate_nonkeyword_arguments
4 participants