autowisp.tests.test_evaluator module

Class Inheritance Diagram

Inheritance diagram of Evaluator, EvaluatorBase, LightCurveEvaluator, SimpleNamespace, TestErrorHandling, TestIterativeRejection, TestNanAggregates, TestRemovedNames

Tests for the symbol table every AutoWISP expression is evaluated in.

Evaluator and LightCurveEvaluator are siblings deriving from EvaluatorBase, and roughly two dozen modules build one. What they offer is therefore worth pinning in one place: the names AutoWISP adds, the names it takes away, and what happens to a bad expression.

class autowisp.tests.test_evaluator.TestErrorHandling(methodName='runTest')[source]

Bases: TestCase

Inheritance diagram of autowisp.tests.test_evaluator.TestErrorHandling

A bad expression raises rather than evaluating to None.

test_permissive_behaviour_remains_available()[source]

Callers that want the old behaviour can still ask for it.

test_raises_by_default_in_both_evaluators()[source]

Asteval’s default returns None, relocating the failure.

class autowisp.tests.test_evaluator.TestIterativeRejection(methodName='runTest')[source]

Bases: TestCase

Inheritance diagram of autowisp.tests.test_evaluator.TestIterativeRejection

The iterative-rejection fits cope with NaN-padded input.

Diagnostics are NaN-padded onto the full image list, so a missing value is the usual case rather than an exception. A NaN in the dependent variable is left out of the fit but still gets a prediction; a NaN in the independent one has nothing to predict at.

_noisy_sine()[source]

Return x, y, and the truth: noisy with outliers and NaNs.

The noise (0.05) comes from RandomState because its stream is frozen, while a Generator’s may change between numpy versions. The outliers are 200 times the noise so that failing to reject them is unmistakable.

setUp()[source]

A straight line with one outlier and some missing values.

test_average_ignores_nan_and_rejects_outlier()[source]

With nanmean, only rejection keeps the outlier out.

test_polynomial_fit()[source]

Predicted where only y is missing, NaN where x is.

test_polynomial_fit_with_too_few_points_is_nan()[source]

Fewer finite points than coefficients gives no fit at all.

Rather than the minimum-norm solution lstsq would return, which would plot as a line through nothing.

test_smoothing_spline()[source]

Predicted where only y is missing, NaN where x is.

test_smoothing_spline_rejects_outliers()[source]

The result does not depend on how loose the initial s is.

It only has to be loose enough for the spline not to bend to the outliers. Over 200 noise seeds, the largest error is at most 0.12, against at least 1.0 without rejection (see the next test).

test_smoothing_spline_without_iterations()[source]

max_iterations=0 is a single fit, rejecting nothing.

Smoothing enough to leave the outliers alone flattens the sine.

test_threshold_pair()[source]

A signed pair rejects above and below separately, in any order.

The outlier above the line (at 4) is rejected; the one below it (at 9) is well within the negative threshold, so it stays and pulls the fit. Two thresholds of the same sign are refused rather than guessed at.

class autowisp.tests.test_evaluator.TestNanAggregates(methodName='runTest')[source]

Bases: TestCase

Inheritance diagram of autowisp.tests.test_evaluator.TestNanAggregates

The NaN-ignoring aggregates are available and are numpy’s.

test_a_missing_numpy_name_would_fail_loudly()[source]

The list is explicit so that numpy dropping one is an error.

test_bound_to_the_numpy_functions()[source]

A name resolving to something else would be worse than absent.

test_data_shadows_an_aggregate_of_the_same_name()[source]

The data is what the user is asking about.

Binding happens before the data is loaded precisely so that this works; the reverse order would make a diagnostic unreachable.

test_present_in_both_evaluators()[source]

Checked in both, since they used to differ.

LightCurveEvaluator defined two of these and Evaluator none, so which aggregates worked depended on which one you were in.

class autowisp.tests.test_evaluator.TestRemovedNames(methodName='runTest')[source]

Bases: TestCase

Inheritance diagram of autowisp.tests.test_evaluator.TestRemovedNames

Names asteval offers that AutoWISP takes away.

test_absent_from_both_evaluators()[source]

Removed on the shared base, so neither can reach them.

test_filesystem_access_raises()[source]

Asteval permits reading files; AutoWISP does not.

Its open already refuses every mode but reading, so this is about reading: expressions travel between installations in export files, and a shared one must not be able to read arbitrary files.

test_printing_raises()[source]

A side effect rather than a value.

test_the_mathematical_names_survive()[source]

The removals must not cost anything anyone would write.

autowisp.tests.test_evaluator._lightcurve_evaluator()[source]

Return a LightCurveEvaluator over a lightcurve with no datasets.

Only elements["dataset"] is consulted during construction, so a stand-in avoids needing a lightcurve file to check the symbol table.