Skip to content

fix: leave caller inputs untouched and evaluate predictions in floating point - #1417

Merged
MilesCranmer merged 3 commits into
astroautomata:masterfrom
M-Colley:fix/input-handling
Oct 8, 2026
Merged

MilesCranmer merged 3 commits into
astroautomata:masterfrom
M-Colley:fix/input-handling

Conversation

@M-Colley

@M-Colley M-Colley commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Don't modify the caller's DataFrame. When column names contained spaces, fit renamed the columns of the user's own DataFrame in place. predict, and the type-spec prediction path, overwrote the columns of a DataFrame with default integer labels (e.g. pd.DataFrame(array)) with feature_names_in_. All three now rename a shallow copy.
  • Evaluate predictions in floating point. predict evaluated the expression with NumPy on integer and boolean arrays as given, while the search always uses floats. Integers could overflow (cube(x0) at x0 = 3_000_000 returned 8.55e18 instead of 2.7e19), unsigned integers wrapped around (x0 - x1 on uint8 1 and 2 gave 255), and booleans used logical arithmetic. Integer and boolean inputs are now cast to float64.
  • (n, 1) weights. Targets of shape (n, 1) were flattened but weights of the same shape were not, so fit(X, y, weights=w) failed an assertion. Such weights are now flattened too.

Tests

  • test_predict_replaces_spaces_in_dataframe_columns now also checks that the caller's columns are unchanged after fit.
  • test_predict_leaves_caller_dataframe_untouched
  • test_predict_with_integer_inputs_does_not_overflow
  • test_column_vector_targets_and_weights
  • TestTypeSpecs.test_prediction_data_validation checks that the caller's columns are unchanged.

All fail on master and pass here.

M-Colley and others added 2 commits October 8, 2026 19:23
…ng point

- `fit` renamed the columns of the caller's DataFrame in place when they
  contained spaces, and `predict` overwrote the columns of a DataFrame
  with default integer labels (e.g. `pd.DataFrame(array)`) with
  `feature_names_in_`. Both now rename a shallow copy, as scikit-learn
  estimators must not modify their inputs.

- `predict` evaluated the lambdified SymPy expression on integer arrays
  as given, so integer inputs silently overflowed (e.g. `cube(x0)` at
  `x0 = 3_000_000` returned 8.55e18 instead of 2.7e19), and differed from
  the floating-point evaluation used during the search. Integer and
  boolean inputs are now cast to float64.

- Column-vector targets `y` of shape (n, 1) are flattened, but weights
  of the same shape were not, so `fit(X, y, weights=w)` with matching
  (n, 1) arrays failed a bare `assert`. Flatten such weights as well,
  and raise a descriptive `ValueError` when the shapes do not match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…float

fit and predict (including the TypeSpec path) renamed columns on the caller's DataFrame; they now rename a shallow copy. predict casts integer and boolean inputs to float64 in the NumPy path, matching fit. Weights of shape (n, 1) are flattened together with y.

Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
MilesCranmer
MilesCranmer previously approved these changes Oct 8, 2026

@MilesCranmer MilesCranmer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Real bug, thanks

Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
@codecov

codecov Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@MilesCranmer
MilesCranmer merged commit 1823414 into astroautomata:master Oct 8, 2026
48 checks passed
@M-Colley
M-Colley deleted the fix/input-handling branch October 9, 2026 07:44
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.

3 participants