-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[MAINT]: Decorator to warn about changed parameter names & allow for deprecation period #2237
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
kandersolar
merged 21 commits into
pvlib:main
from
echedey-ls:renamed-param-deprecation-deco
Oct 15, 2024
Merged
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
ec24a16
Add renamed_kwarg_warning decorator
echedey-ls 0ed8898
Example at solarposition.hour_angle()
echedey-ls bade670
another day, another test
echedey-ls f5e46ef
Flake8 strikes again
echedey-ls 1fdecb2
Fix no warning test
echedey-ls 65e144b
Add test to remember removing the deprecation decorator
echedey-ls fd0974f
test-driven-development for the win: unchanged remain properties
echedey-ls 1eb44a5
Update docs
echedey-ls f58209f
Update fail_on_pvlib_version test comment
echedey-ls 58c0191
Rename&deprecate solarposition.sun_rise_set_transit_spa
echedey-ls 9921ad7
flake8
echedey-ls 30e3c65
flake8 no more
echedey-ls 2a8b56d
date -> time in solarposition.sun_rise_set_transit_spa
echedey-ls 455e9ad
Change to ..versionchanged, same format.
echedey-ls e779f79
Apply suggestions from Adam
echedey-ls 981f394
Apply Adam review x2
echedey-ls 25bcf02
Update solarposition.py
echedey-ls a8f8576
Update solarposition.py
echedey-ls c185834
Revert solarposition and test_solarposition changes
echedey-ls 308e5f6
Had to use main instead of master xd
echedey-ls 3cd34f3
:sob:
echedey-ls File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" | ||
Test the _deprecation module. | ||
""" | ||
|
||
import pytest | ||
|
||
from pvlib import _deprecation | ||
|
||
import warnings | ||
|
||
|
||
@pytest.fixture | ||
def renamed_kwarg_func(): | ||
"""Returns a function decorated by renamed_kwarg_warning. | ||
This function is called 'func' and has a docstring equal to 'docstring'. | ||
""" | ||
|
||
@_deprecation.renamed_kwarg_warning( | ||
"0.1.0", "old_kwarg", "new_kwarg", "0.2.0" | ||
) | ||
def func(new_kwarg): | ||
"""docstring""" | ||
return new_kwarg | ||
|
||
return func | ||
|
||
|
||
def test_renamed_kwarg_warning(renamed_kwarg_func): | ||
# assert decorated function name and docstring are unchanged | ||
assert renamed_kwarg_func.__name__ == "func" | ||
assert renamed_kwarg_func.__doc__ == "docstring" | ||
|
||
# assert no warning is raised when using the new kwarg | ||
with warnings.catch_warnings(): | ||
warnings.simplefilter("error") | ||
assert renamed_kwarg_func(new_kwarg=1) == 1 # as keyword argument | ||
assert renamed_kwarg_func(1) == 1 # as positional argument | ||
|
||
# assert a warning is raised when using the old kwarg | ||
with pytest.warns(Warning, match="Parameter 'old_kwarg' has been renamed"): | ||
assert renamed_kwarg_func(old_kwarg=1) == 1 | ||
|
||
# assert an error is raised when using both the old and new kwarg | ||
with pytest.raises(ValueError, match="they refer to the same parameter."): | ||
echedey-ls marked this conversation as resolved.
Show resolved
Hide resolved
|
||
renamed_kwarg_func(old_kwarg=1, new_kwarg=2) | ||
|
||
# assert when not providing any of them | ||
with pytest.raises( | ||
TypeError, match="missing 1 required positional argument" | ||
): | ||
renamed_kwarg_func() |
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
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.
Uh oh!
There was an error while loading. Please reload this page.