Repository navigation
Conversation
The docs promise a typed error when NaN reaches a finite-only method,
but only NumericBinningTransformer raised PretabDataError. PLE, Fourier,
periodic encoding, RFF and Nystroem left the check to scikit-learn's
check_array, which raises a plain ValueError("Input contains NaN.")
without the estimator or column; infinite values did the same for every
method.
A shared reject_non_finite helper in pretab.core.validation now raises
PretabDataError (a ValueError) naming the estimator and the affected
columns: always for infinite values, and for NaN when the estimator does
not allow it. validate_2d_allow_nan and PLETransformer use it.
Fixes #171
This branch has not been deployed
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.
Fixes #171.
The docs promise a typed error when NaN reaches a finite-only representation. Only
NumericBinningTransformerraised one. PLE (the default numerical method), Fourier, periodic encoding, RFF and Nyström raised scikit-learn's plainValueError("Input contains NaN."), and infinite values did the same for every representation.Root cause
validate_2d_allow_nan(pretab/core/validation.py) andPLETransformer.fit/transformdelegated the finiteness check tocheck_array(ensure_all_finite=...), which raises a builtinValueErrorwithout the estimator or the column.Fix
New
reject_non_finite(X, *, allow_nan, estimator)inpretab/core/validation.pyraisesPretabDataError:allow_nanis False.The message names the estimator and the affected columns, by
feature_names_in_when the estimator has them, otherwise by position. For NaN it also points to imputation.validate_2d_allow_nannow callscheck_array(..., ensure_all_finite=False)followed byreject_non_finite. This covers everyBasePreTabTransformer, including the NaN-propagating splines and feature maps for infinite values.PLETransformer.fitandtransformcall the helper the same way.PretabDataErrorsubclassesValueError, so code that catchesValueErrorkeeps working.Behaviour changes
PretabDataError, for examplePLETransformer received missing values (NaN) in column(s) ['hour'], but it needs finite input: .... Before, it raised a plainValueError.PretabDataError ... received infinite values in column(s) [...]for these representations and for the splines and feature maps.Documentation
validate_2d_allow_nandocstring and the newreject_non_finitedocstring (NumPy format).docs/core_concepts/missing_values.md: the typed error is aPretabDataErrornaming the columns, and infinite values raise it for every method.docs/representations/choosing_a_method.md("NaN into a finite-only method: raises a typed error") now holds as written.Tests
In
tests/integration/test_edge_case_contract.py:test_missing_values_into_a_finite_only_method_raise_a_typed_error(six finite-only representations, atfitandtransform): the column is named. Fails onmainexcept for binning (a guard), passes here.test_infinite_values_raise_a_typed_error_naming_the_column(every family): fails onmainexcept for binning, passes here.test_preprocessor_without_imputation_raises_a_typed_error_for_ple: fails onmain, passes here.ValueErrormatching"NaN"for PLE and Fourier still pass.Reproduction
The script from #171 on this branch:
Checks
just test: 4703 passed, 59 skipped, 7 xfailed; coverage 95.72% (gate 90%).scripts/quickstart.pypasses.just docs: strict build succeeds.just check: all pre-commit and pre-push hooks pass (file hygiene, ruff format, ruff lint, prettier, pyright with 0 errors).pretab.core.validation.pretab.encoding.numerical.pleimports it from core, which the architecture's dependency direction allows.Merge notes
main.pretab/encoding/numerical/ple.py(get_feature_names_out, a different method), and fix(preprocessor): reject input without columns at fit #166 and fix(preprocessor): report unknown columns when labels mix int and str #170 edit other parts of the edge-case tests and exceptions. Git merges this branch cleanly with every open per-issue branch (fix(binning): reject edges the soft encoding cannot use #150 to fix(preprocessor): report unknown columns when labels mix int and str #170).