Repository navigation
fix: leave caller inputs untouched and evaluate predictions in floating point - #1417
Merged
Merged
Conversation
…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>
Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
MilesCranmer
approved these changes
Oct 8, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
MilesCranmer
approved these changes
Oct 8, 2026
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.
Summary
fitrenamed 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)) withfeature_names_in_. All three now rename a shallow copy.predictevaluated the expression with NumPy on integer and boolean arrays as given, while the search always uses floats. Integers could overflow (cube(x0)atx0 = 3_000_000returned 8.55e18 instead of 2.7e19), unsigned integers wrapped around (x0 - x1onuint81 and 2 gave 255), and booleans used logical arithmetic. Integer and boolean inputs are now cast to float64.fit(X, y, weights=w)failed an assertion. Such weights are now flattened too.Tests
test_predict_replaces_spaces_in_dataframe_columnsnow also checks that the caller's columns are unchanged afterfit.test_predict_leaves_caller_dataframe_untouchedtest_predict_with_integer_inputs_does_not_overflowtest_column_vector_targets_and_weightsTestTypeSpecs.test_prediction_data_validationchecks that the caller's columns are unchanged.All fail on master and pass here.