PolynomialTransformer silently overwrites an existing column when a generated monomial name already exists
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- machine-learning
Research direction
Start with src/transformers/other_transformers/polynomial_transformer.jl, especially the column-name construction and merge near lines 97-104. Review test/transformers/other_transformers/polynomial_transformer.jl and the two minimal examples in the issue. Done means existing columns are preserved or a clash raises an informative error, duplicate monomial names identify the conflicting monomials, and regression tests cover both cases.
Written by the indexing model from the issue text.
Description
PolynomialTransformer names each new column by joining the feature names with _ and then merges the result into the input table:
new_features = Tuple(Symbol(join(premon, "_")) for premon in premonomials)
...
return merge(Tables.columntable(X), table_addendum) |> materializer
Nothing checks whether a generated name is already a column of X, so merge just replaces that column with the product. The original data is gone and there's no warning or error. Column names like A_B aren't unusual, and the easiest way to hit this is to run the transformer on a table that already went through a PolynomialTransformer (or the deprecated InteractionTransformer, which has the same merge).
A related problem: since the names are just joined with _, two different monomials can get the same name, e.g. a * b_c and a_b * c both become a_b_c. That case does at least error, but the message comes from the NamedTuple constructor and doesn't say what went wrong.
Minimal example:
using MLJBase, MLJTransforms
# 1. an existing column happens to have a generated name
X = (A = [1.0, 2.0, 3.0], B = [4.0, 5.0, 6.0], A_B = [100.0, 200.0, 300.0])
Xt = transform(machine(PolynomialTransformer(degree=2, features=[:A, :B])), X)
@show keys(Xt)
@show X.A_B Xt.A_B
# 2. two different monomials get the same name
Z = (a = [1.0, 2.0], b_c = [3.0, 4.0], a_b = [5.0, 6.0], c = [7.0, 8.0])
try
transform(machine(PolynomialTransformer(interactions_only=true)), Z)
catch e
showerror(stdout, e); println()
end
Output:
keys(Xt) = (:A, :B, :A_B, :A_A, :B_B)
X.A_B = [100.0, 200.0, 300.0]
Xt.A_B = [4.0, 10.0, 18.0]
duplicate field name in NamedTuple: "a_b_c" is not unique
Expected: the user's A_B column should still be [100.0, 200.0, 300.0] in the output. Either throw an informative ArgumentError naming the clashing column(s), or give the new column a non-clashing name (with a warning). For case 2, an error that says which monomials ended up with the same name.
Actual: A_B is silently replaced by A .* B, and case 2 fails with a generic NamedTuple error.
The current tests in test/transformers/other_transformers/polynomial_transformer.jl only use inputs whose column names can't clash, so this isn't covered.
Versions: MLJTransforms v0.2.4 (dev at d3e3db3), MLJBase v1.15.5, Julia 1.13.4.
- Dominant language
- Julia
- Stars
- 1
- Forks
- 5
- Avg merge
- 6h 44m
- Merged PRs (30d)
- 3
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from JuliaAI/MLJTransforms.jl
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
JuliaAI/MLJTransforms.jl#119 ·
Maintainers usually reply within 1 day
-
UnivariateStandardizer has human_name "single variable discretizer"Possibly taken @ablaom claimed this 2 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 88/100
JuliaAI/MLJTransforms.jl#117 · 1 comment · 1 reaction · 1 assignee ·
Maintainers usually reply within 1 day
-
TargetEncoder: m = :auto uses the inverse of the empirical Bayes ratio and gives NaN for single-row levelsPossibly taken @EssamWisam claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
JuliaAI/MLJTransforms.jl#113 · 1 reaction · 1 assignee ·
Maintainers usually reply within 1 day
-
ContinuousEncoder docstring: wrong `drop_last` default and nonexistent `ordered_factors` optionPossibly taken @ablaom claimed this 5 days ago. Opendocumentation
Difficulty 1/5 Under an hour Newbie friendliness 88/100
JuliaAI/MLJTransforms.jl#109 · 1 comment · 1 reaction · 1 assignee ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
JuliaAI/MLJTransforms.jl#108 · 1 comment ·
Maintainers usually reply within 1 day
All issues in JuliaAI/MLJTransforms.jl
Similar issues
-
Release CorleoneInverse as 0.1.1Possibly taken @ChrisRackauckas-Claude claimed this 1 day ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 78/100
SciML/Corleone.jl#200 · 1 comment ·
Maintainers usually reply within 1 day
-
tagbot-manual
Difficulty 1/5 Under an hour Newbie friendliness 82/100
SciML/MonteCarloIntegration.jl#49 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
jaff-chemistry/jaff#231 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SciML/RecursiveArrayTools.jl#701 ·
-
DPRKN6 docstring: the velocity interpolant is 5th order, not 6thPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 1/5 Under an hour Newbie friendliness 90/100
SciML/OrdinaryDiffEq.jl#5175 ·
Maintainers usually reply within 1 day