Skip to content

Fix pandas SettingWithCopyWarning, which really shouldn't be ignored.#2447

Merged
rapids-bot[bot] merged 1 commit intorapidsai:branch-22.08from
eriknw:fix_setting_with_copy_warning
Jul 27, 2022
Merged

Fix pandas SettingWithCopyWarning, which really shouldn't be ignored.#2447
rapids-bot[bot] merged 1 commit intorapidsai:branch-22.08from
eriknw:fix_setting_with_copy_warning

Conversation

@eriknw
Copy link
Contributor

@eriknw eriknw commented Jul 26, 2022

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_view attribute that tell us this. I don't know about cugraph, or if this is even an issue in cugraph.

CC @rlratzel

@eriknw eriknw requested a review from a team as a code owner July 26, 2022 21:26
@rlratzel rlratzel added bug Something isn't working non-breaking Non-breaking change labels Jul 26, 2022
@rlratzel rlratzel added this to the 22.08 milestone 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


Copy link
Contributor Author

Choose a reason for hiding this comment

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

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-commenter
Copy link

codecov-commenter commented Jul 26, 2022

Codecov Report

❗ No coverage uploaded for pull request base (branch-22.08@2c50989). Click here to learn what that means.
The diff coverage is n/a.

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

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2c50989...652ecc6. Read the comment docs.

@BradReesWork
Copy link
Member

@gpucibot merge

@rapids-bot rapids-bot bot merged commit d925926 into rapidsai:branch-22.08 Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants