Skip to content

Commit

Permalink
TST: explicitly select method for P_expected (go away Ruff!)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhomeier committed Oct 14, 2024
1 parent 2c9ef89 commit 9c0365a
Showing 1 changed file with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
from astropy.tests.helper import assert_quantity_allclose
from astropy.time import Time, TimeDelta
from astropy.timeseries.periodograms.lombscargle import LombScargle
from astropy.timeseries.periodograms.lombscargle.implementations.utils import SCIPY_LT_1_15
from astropy.timeseries.periodograms.lombscargle.implementations.main import (
validate_method,
)
from astropy.timeseries.periodograms.lombscargle.implementations.utils import (
SCIPY_LT_1_15,
)

ALL_METHODS = LombScargle.available_methods
ALL_METHODS_NO_AUTO = [method for method in ALL_METHODS if method != "auto"]
Expand Down Expand Up @@ -101,11 +106,15 @@ def test_all_methods(
fit_mean=fit_mean,
normalization=normalization,
)
# Reference defaults to "scipy" in most cases
if method == "scipy":
P_expected = ls.power(frequency, method="cython")
else:
P_expected = ls.power(frequency)
# Use default method for reference unless it is identical to method tested
# (can be either "scipy" or "cython").
reference = validate_method("auto", dy, fit_mean, 1, frequency, True)
if reference == method:
if method == "scipy":
reference = "cython"
else:
reference = "slow"
P_expected = ls.power(frequency, method=reference)

# don't use the fft approximation here; we'll test this elsewhere
if method in FAST_METHODS:
Expand All @@ -120,7 +129,7 @@ def test_all_methods(
else:
assert not hasattr(P_method, "unit")

assert_quantity_allclose(P_method, P_expected)
assert_quantity_allclose(P_method, P_expected, rtol=1e-10)


@pytest.mark.parametrize("method", ALL_METHODS_NO_AUTO)
Expand Down

0 comments on commit 9c0365a

Please sign in to comment.