Fix pandas SettingWithCopyWarning, which really shouldn't be ignored.#2447
Merged
rapids-bot[bot] merged 1 commit intorapidsai:branch-22.08from Jul 27, 2022
Merged
Conversation
See: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy This implementation requires column names to be strings, which is hopefully fine (but could be changed).
rlratzel
approved these changes
Jul 26, 2022
eriknw
commented
Jul 26, 2022
Comment on lines
+121
to
+135
| @pytest.fixture(scope="function", autouse=True) | ||
| def raise_on_pandas_warning(): | ||
| """Raise when pandas gives SettingWithCopyWarning warning""" | ||
| # Perhaps we should put this in pytest.ini, pyproject.toml, or conftest.py | ||
| import warnings | ||
|
|
||
| filters = list(warnings.filters) | ||
| warnings.filterwarnings( | ||
| "error", | ||
| category=pd.core.common.SettingWithCopyWarning | ||
| ) | ||
| yield | ||
| warnings.filters = filters | ||
|
|
||
|
|
Contributor
Author
There was a problem hiding this comment.
pytest does some weird things with warnings between each test, but this fixture works and is only applied to this file (and I don't know if we need to reset the filters). If we want to make this warning raise everywhere, there are better ways to achieve it.
Without this fixture, a way to make pytest raise on this warning is:
pytest -Werror::pandas.core.common.SettingWithCopyWarning cugraph/cugraph/tests/test_property_graph.py
Codecov Report
@@ Coverage Diff @@
## branch-22.08 #2447 +/- ##
===============================================
Coverage ? 61.27%
===============================================
Files ? 106
Lines ? 5400
Branches ? 0
===============================================
Hits ? 3309
Misses ? 2091
Partials ? 0 Continue to review full report at Codecov.
|
Member
|
@gpucibot merge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
This implementation requires column names to be strings, which is hopefully fine (but could be changed).
The downside is that this sometimes copies data when unnecessary. It's pretty hard to know when objects are views or not when using public APIS. Pandas objects have a
._is_viewattribute that tell us this. I don't know about cugraph, or if this is even an issue in cugraph.CC @rlratzel