Skip to content
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

DEPR: fix stacklevel for DataFrame(mgr) deprecation #55591

Merged

Conversation

jorisvandenbossche
Copy link
Member

@jorisvandenbossche jorisvandenbossche commented Oct 19, 2023

Follow-up on #52419. To ensure end users don't see this warning (unless they would be passing a manager themselves), but only libraries see them in their tests.

See #52419 (comment) for context.

@mroeschke mroeschke added Internals Related to non-user accessible pandas implementation Warnings Warnings that appear or should be added to pandas labels Oct 19, 2023
@jbrockmendel
Copy link
Member

FAILED pandas/tests/io/test_orc.py::test_orc_reader_empty - AssertionError: Warning not set with correct stacklevel. File where warning is raised: /Users/runner/work/pandas/pandas/pandas/io/orc.py != /Users/runner/work/pandas/pandas/pandas/tests/io/test_orc.py. Warning message: Passing a BlockManager to DataFrame is deprecated and will raise in a future version. Use public APIs instead.
FAILED pandas/tests/io/test_orc.py::test_orc_reader_basic - AssertionError: Warning not set with correct stacklevel. File where warning is raised: /Users/runner/work/pandas/pandas/pandas/io/orc.py != /Users/runner/work/pandas/pandas/pandas/tests/io/test_orc.py. Warning message: Passing a BlockManager to DataFrame is deprecated and will raise in a future version. Use public APIs instead.
FAILED pandas/tests/io/test_orc.py::test_orc_reader_decimal - AssertionError: Warning not set with correct stacklevel. File where warning is raised: /Users/runner/work/pandas/pandas/pandas/io/orc.py != /Users/runner/work/pandas/pandas/pandas/tests/io/test_orc.py. Warning message: Passing a BlockManager to DataFrame is deprecated and will raise in a future version. Use public APIs instead.
FAILED pandas/tests/io/test_orc.py::test_orc_reader_date_low - AssertionError: Warning not set with correct stacklevel. File where warning is raised: /Users/runner/work/pandas/pandas/pandas/io/orc.py != /Users/runner/work/pandas/pandas/pandas/tests/io/test_orc.py. Warning message: Passing a BlockManager to DataFrame is deprecated and will raise in a future version. Use public APIs instead.
FAILED pandas/tests/io/test_orc.py::test_orc_reader_date_high - AssertionError: Warning not set with correct stacklevel. File where warning is raised: /Users/runner/work/pandas/pandas/pandas/io/orc.py != /Users/runner/work/pandas/pandas/pandas/tests/io/test_orc.py. Warning message: Passing a BlockManager to DataFrame is deprecated and will raise in a future version. Use public APIs instead.
FAILED pandas/tests/io/test_orc.py::test_orc_reader_snappy_compressed - AssertionError: Warning not set with correct stacklevel. File where warning is raised: /Users/runner/work/pandas/pandas/pandas/io/orc.py != /Users/runner/work/pandas/pandas/pandas/tests/io/test_orc.py. Warning message: Passing a BlockManager to DataFrame is deprecated and will raise in a future version. Use public APIs instead.
FAILED pandas/tests/io/test_orc.py::test_orc_roundtrip_file - AssertionError: Warning not set with correct stacklevel. File where warning is raised: /Users/runner/work/pandas/pandas/pandas/io/orc.py != /Users/runner/work/pandas/pandas/pandas/tests/io/test_orc.py. Warning message: Passing a BlockManager to DataFrame is deprecated and will raise in a future version. Use public APIs instead.
FAILED pandas/tests/io/test_orc.py::test_orc_roundtrip_bytesio - AssertionError: Warning not set with correct stacklevel. File where warning is raised: /Users/runner/work/pandas/pandas/pandas/io/orc.py != /Users/runner/work/pandas/pandas/pandas/tests/io/test_orc.py. Warning message: Passing a BlockManager to DataFrame is deprecated and will raise in a future version. Use public APIs instead.
FAILED pandas/tests/io/test_orc.py::test_orc_dtype_backend_pyarrow - AssertionError: Warning not set with correct stacklevel. File where warning is raised: /Users/runner/work/pandas/pandas/pandas/io/orc.py != /Users/runner/work/pandas/pandas/pandas/tests/io/test_orc.py. Warning message: Passing a BlockManager to DataFrame is deprecated and will raise in a future version. Use public APIs instead.
FAILED pandas/tests/io/test_orc.py::test_orc_dtype_backend_numpy_nullable - AssertionError: Warning not set with correct stacklevel. File where warning is raised: /Users/runner/work/pandas/pandas/pandas/io/orc.py != /Users/runner/work/pandas/pandas/pandas/tests/io/test_orc.py. Warning message: Passing a BlockManager to DataFrame is deprecated and will raise in a future version. Use public APIs instead.
FAILED pandas/tests/io/test_orc.py::test_orc_uri_path - AssertionError: Warning not set with correct stacklevel. File where warning is raised: /Users/runner/work/pandas/pandas/pandas/io/orc.py != /Users/runner/work/pandas/pandas/pandas/tests/io/test_orc.py. Warning message: Passing a BlockManager to DataFrame is deprecated and will raise in a future version. Use public APIs instead.

@jorisvandenbossche jorisvandenbossche added this to the 2.2 milestone Oct 27, 2023
Comment on lines -39 to +43
msg = "Passing a BlockManager to DataFrame is deprecated"
with tm.assert_produces_warning(DeprecationWarning, match=msg):
result = table.to_pandas()
result = table.to_pandas()
Copy link
Member Author

Choose a reason for hiding this comment

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

In several of those cases I removed the warning assert, and added a general filterwarnings mark (at the test or top of the file), because 1) there is no need to "test" that the warning is raised in all those cases, and 2) once the PR to fix this on the pyarrow side is merged, all those cases will start failing anyway

@jorisvandenbossche
Copy link
Member Author

As mentioned on the issue, I updated this to use stacklevel=1 for now (to avoid the warnings from pyarrrow's cython in user code). Once there is a release of pyarrow with the fix, we can change that to stacklevel=2.

And the tests are all passing now.

@jorisvandenbossche
Copy link
Member Author

Any other comments here?

@@ -697,7 +697,7 @@ def __init__(
"is deprecated and will raise in a future version. "
"Use public APIs instead.",
DeprecationWarning,
stacklevel=find_stack_level(),
stacklevel=1, # bump to 2 once pyarrow is released with fix
Copy link
Member

@mroeschke mroeschke Nov 7, 2023

Choose a reason for hiding this comment

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

Nit: Could you reference the anticipated pyarrow version that would have this fix (if the fix has already been made in pyarrow)?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's not yet fully sure. At least 15.0.0 I assume, but potentially a 14.0.x release as well. But will add 15.0 then.

Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

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

One small request otherwise LGTM

Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

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

Merge conflict otherwise LGTM

@jorisvandenbossche jorisvandenbossche merged commit 775f716 into pandas-dev:main Nov 9, 2023
33 of 34 checks passed
@jorisvandenbossche jorisvandenbossche deleted the fix-mgr-depr-warnings branch November 9, 2023 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Internals Related to non-user accessible pandas implementation Warnings Warnings that appear or should be added to pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants