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

Use FutureWarning instead of DeprecationWarning. #692

Merged
merged 14 commits into from
Mar 12, 2022

Conversation

Onkar627
Copy link
Contributor

@Onkar627 Onkar627 commented Feb 26, 2022

Description

Fixes issues as described by @vyasr in Issue #687 as we tend to change the DeprecationWarning to FutureWarning instead.

Motivation and Context

The main motivation of this change is basically that warnings of the deprecated features are visible to the users as in current scenarios of Deprecated warnings python hides these by default.

Types of Changes

  • Documentation update
  • Bug fix
  • New feature
  • Breaking change1

1The change breaks (or has the potential to break) existing functionality.

Checklist:

If necessary:

  • I have updated the API documentation as part of the package doc-strings.
  • I have created a separate pull request to update the framework documentation on signac-docs and linked it here.
  • I have updated the changelog and added all related issue and pull request numbers for future reference (if applicable). See example below.

@Onkar627 Onkar627 requested review from a team as code owners February 26, 2022 05:57
@Onkar627 Onkar627 requested review from mikemhenry and lyrivera and removed request for a team February 26, 2022 05:57
@codecov
Copy link

codecov bot commented Feb 26, 2022

Codecov Report

Merging #692 (234c34e) into master (a5937cb) will not change coverage.
The diff coverage is n/a.

❗ Current head 234c34e differs from pull request most recent head d51ec0c. Consider uploading reports for the commit d51ec0c to get more accurate results

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #692   +/-   ##
=======================================
  Coverage   78.54%   78.54%           
=======================================
  Files          65       65           
  Lines        7141     7141           
  Branches     1565     1565           
=======================================
  Hits         5609     5609           
  Misses       1228     1228           
  Partials      304      304           
Impacted Files Coverage Δ
signac/contrib/indexing.py 70.95% <ø> (ø)

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 a5937cb...d51ec0c. Read the comment docs.

Copy link
Member

@bdice bdice left a comment

Choose a reason for hiding this comment

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

Hi @Onkar627, thank you for the pull request! It looks like the changes in this PR are good, but incomplete. I have a few requests for this PR before merging - please review my comment on #691 for some basic steps needed for all pull requests (description, title, checklist),

Additionally, this PR should update a few other DeprecationWarnings that were missed. These can be found in signac/synced_collections/backends/collection_json.py and signac/synced_collections/buffers/file_buffered_collection.py. I have included direct links below.

Finally, we may need to update the warning filters in tests/test_project.py and tests/test_job.py. These may need to hide FutureWarning instead of DeprecationWarning. You can check the pytest output to see what warnings are raised.

warnings.filterwarnings("ignore", category=DeprecationWarning, module="signac")

warnings.filterwarnings("ignore", category=DeprecationWarning, module="signac")

@@ -1188,7 +1188,7 @@ def __init__(
warnings.warn(
"Passing in an options dictionary to ConfigObj() is "
"deprecated. Use **options instead.",
DeprecationWarning,
FutureWarning,
Copy link
Member

Choose a reason for hiding this comment

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

This file is vendored (copied from an upstream project) so we usually avoid changing it. We have control over how this object is created in the library and it's not a part of user-facing code, so I suggest reverting this change.

Suggested change
FutureWarning,
DeprecationWarning,

@lyrivera
Copy link

Not sure what to review without a description.

@bdice bdice changed the title Additional changes Use FutureWarning instead of DeprecationWarning. Mar 1, 2022
@vyasr
Copy link
Contributor

vyasr commented Mar 5, 2022

@Onkar627 when you address the reviews could you also fill out the PR template? You can see the sections: 1) a description of your changes; 2) an explanation of why you are making these changes (the motivation); and 3) filling out the checklist.

@Onkar627
Copy link
Contributor Author

Onkar627 commented Mar 5, 2022

@Onkar627 when you address the reviews could you also fill out the PR template? You can see the sections: 1) a description of your changes; 2) an explanation of why you are making these changes (the motivation); and 3) filling out the checklist.

Yes sure, As I changed it for other pull request will do the same for this as well.

@Onkar627
Copy link
Contributor Author

Onkar627 commented Mar 8, 2022

@bdice , @lyrivera I have updated the PR, kindly review and please ping if any changes are required.

@bdice
Copy link
Member

bdice commented Mar 9, 2022

@Onkar627 There are some tests failing. See logs here for linux-python-38.

The underlying cause is that we are using a pytest feature pytest.deprecated_call to catch DeprecationWarning, but that does not catch FutureWarning. We need to replace some code in the places where tests are failing to use pytest.warns instead. For example, this line should be changed in tests/test_synced_collections/test_json_buffered_collection.py:

- with pytest.deprecated_call(match="Use of.+as key is deprecated"):
+ with pytest.warns(FutureWarning, match="Use of.+as key is deprecated"):

Comment on lines 366 to 367
warnings.warn(
DeprecationWarning(
FutureWarning(
Copy link
Member

@bdice bdice Mar 9, 2022

Choose a reason for hiding this comment

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

Hmm, something was wrong here in the old code. Can you switch this to call warnings.warn(message, FutureWarning) instead of warnings.warn(FutureWarning(message))? The function isn't being used correctly.

https://docs.python.org/3/library/warnings.html#warnings.warn

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, sure.

Copy link
Collaborator

@mikemhenry mikemhenry left a comment

Choose a reason for hiding this comment

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

Tests are failing,


    def test_keys_non_str_valid_type(self, synced_collection, testdata):
        for key in (0, None, True):
            with pytest.deprecated_call(match="Use of.+as key is deprecated"):
>               synced_collection[key] = testdata
E               Failed: DID NOT WARN. No warnings of type (<class 'DeprecationWarning'>, <class 'PendingDeprecationWarning'>) were emitted. The list of emitted warnings is: [FutureWarning('Use of int as key is deprecated and will be removed in version 2.0.')].

So they need to be updated

@Onkar627
Copy link
Contributor Author

@Onkar627 There are some tests failing. See logs here for linux-python-38.

The underlying cause is that we are using a pytest feature pytest.deprecated_call to catch DeprecationWarning, but that does not catch FutureWarning. We need to replace some code in the places where tests are failing to use pytest.warns instead. For example, this line should be changed in tests/test_synced_collections/test_json_buffered_collection.py:

- with pytest.deprecated_call(match="Use of.+as key is deprecated"):
+ with pytest.warns(FutureWarning, match="Use of.+as key is deprecated"):

Should I also change every deprecated call feature to warn like for example in tests/conftest.py:

def deprecated_in_version(version_string):
   if version.parse(version_string) <= version.parse(signac.__version__):
- with pytest.deprecated_call():
+ with pytest.warns(FutureWarning):

@bdice

…() instead.. It was only used once and is no longer needed.
Copy link
Member

@bdice bdice left a comment

Choose a reason for hiding this comment

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

Thanks @Onkar627! I pushed a commit to address your question about conftest.py, that was a good observation. That function deprecated_in_version was outdated and only used once, so I removed it. I'm going to merge this PR so that I can do some related follow-up work.

@bdice bdice merged commit 045925c into glotzerlab:master Mar 12, 2022
@b-butler b-butler added this to the v1.8.0 milestone Sep 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants