Repository navigation
Remove custom pandas assert wrappers and use pandas.testing directly - #2951
Open
DresdenGman wants to merge 2 commits into
Open
DresdenGman wants to merge 2 commits into
DresdenGman wants to merge 2 commits into
Conversation
Remove the assert_series_equal and assert_frame_equal wrappers around pandas.testing asserts and replace all call sites with direct pandas.testing calls carrying explicit tolerances. The wrappers silently rewrote caller tolerances (check_less_precise -> atol=rtol=1e-3, otherwise atol=rtol=1e-5, overriding any atol/rtol the caller passed) and carried dead pandas<1.1 version logic; the minimum supported pandas is 1.5.0. Simplify assert_index_equal to a thin compatibility shim that passes check_freq=False only on pandas >= 3.1.0, where the keyword exists; full removal of that wrapper must wait until pvlib requires pandas >= 3.1.0 (the CI minimum environment pins pandas 1.5.0). Add a regression test pinning the shim's version gate. Tests: 1135 passed (1133 affected-suite tests identical to the pre-change baseline plus 2 new shim tests), 35 skipped, 75 deselected (remote_data), 0 failed. flake8 --diff on the changed lines is clean.
Member
|
this looks useful and is appreciated. however, we require the PR checklist at the head of the PR leading comment. Please add the checklist. |
- test_sodapro.py: drop unused pvlibDeprecationWarning import (F401) - test_location.py: reformat the six clearsky expected-DataFrame constructions to a flake8-clean layout (E126/E202/E203/E131 were pre-existing style issues surfaced by --diff on the touched hunks); all six frames verified numerically identical via assert_frame_equal
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.
assert_*_equalwrappers aroundpandas.testingfunctions #2263docs/sphinx/source/referencefor API changes.docs/sphinx/source/whatsnewfor all changes. Includes link to the GitHub Issue with:issue:`num`or this Pull Request with:pull:`num`. Includes contributor name and/or GitHub username (link with:ghuser:`user`).remote-data) and Milestone are assigned to the Pull Request and linked Issue.Summary
Remove the
assert_series_equalandassert_frame_equalwrappers intests/conftest.pyand usepandas.testingfunctions directly, with explicit tolerances at every call site. Simplifyassert_index_equalto a thin compatibility shim (see below).The wrappers wrapped the three
pandas.testingassert functions with pandas 1.1-era version logic._check_pandas_assert_kwargssilently rewrote caller tolerances —check_less_precise(truthy) becameatol=rtol=1e-3, otherwiseatol=rtol=1e-5— overwriting anyatol/rtolthe caller passed. The pandas < 1.1 branch is dead code (the minimum supported pandas is 1.5.0). Following maintainer AdamRJensen's direction in the issue ("I think we should just get rid of our own wrappers, and use pandas"), the series and frame wrappers are removed entirely.Tolerance translation (behavior-preserving)
atol=1e-5, rtol=1e-5(the wrapper's defaults; pandas' own defaults are 1000× tighter, so bare removal would silently tighten tests).check_less_precise(valuesTrue/2/3/4/5in the suite) →atol=1e-3, rtol=1e-3.atol/rtolkeep the effective values1e-5/1e-5, not the written ones — the wrapper overwrote them. This affects 6 sites:tests/spectrum/test_irradiance.py:45(atol=1e-2),:62(atol=1e-4),:90(rtol=1e-4);tests/test_albedo.py:51,64(atol=1e-5);tests/test_iam.py:461(rtol=1e-6). The full test run passes at 1e-5, confirming these tolerances are genuinely sufficient.Why
assert_index_equalis kept as a shimcheck_freqwas added topandas.testing.assert_index_equalonly in pandas 3.1.0, and the CI minimum environment pins pandas 1.5.0, so passingcheck_freq=Falseunconditionally would raiseTypeErroron older pandas. The wrapper is therefore simplified to a version gate only — it passescheck_freq=Falseon pandas >= 3.1.0 and nothing otherwise — with a comment noting it can be removed once pvlib requires pandas >= 3.1.0. The 17 index call sites use it with explicitatol=1e-5, rtol=1e-5and nocheck_freqkwarg.Other changes
tests/test_conftest.py(which only tested the removed wrappers) with a single regression test pinning the shim's version gate: it monkeypatchespd.__version__to 1.5.0 / 3.1.0 and assertscheck_freqis forwarded only on pandas >= 3.1.0.docs/sphinx/source/whatsnew/v0.16.2.rst.Test report
Affected test files (34 files, 372 call sites), run against the pre-change baseline — identical results, zero regressions:
-m "not remote_data"): 68 passed, 75 deselected, 0 failedflake8
--diffon the changed lines is clean.Closes #2263