Skip to content

inverse of NamedTuple transformations from different ordering/superset #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tpapp opened this issue Sep 7, 2022 · 2 comments
Closed

Comments

@tpapp
Copy link
Owner

tpapp commented Sep 7, 2022

Currrently inverse for NamedTuple aggregators does not accept different orderings or supersets. Eg

julia> using TransformVariables
    
julia> t = as((a = asℝ, b = asℝ));

julia> inverse(t, (a = 1.0, b = 2.0))
2-element Vector{Float64}:
 1.0
 2.0

julia> inverse(t, (b = 1.0, a = 2.0))
ERROR: ArgumentError: keys(transformations) == keys(y) must hold. Got
keys(transformations) => (:a, :b)
keys(y) => (:b, :a)

julia> inverse(t, (a = 1.0, b = 2.0, c = 3.0))
ERROR: ArgumentError: keys(transformations) == keys(y) must hold. Got
keys(transformations) => (:a, :b)
keys(y) => (:a, :b, :c)

This is OK, but the user should be provided with a method to "regularize" NamedTuples (eg user input may mix up ordering).

@devmotion
Copy link
Collaborator

IMO this was fixed by #120. On the master branch, the example above gives

julia> using TransformVariables

julia> t = as((a = asℝ, b = asℝ));

julia> inverse(t, (a = 1.0, b = 2.0))
2-element Vector{Float64}:
 1.0
 2.0

julia> inverse(t, (b = 1.0, a = 2.0))
2-element Vector{Float64}:
 2.0
 1.0

julia> inverse(t, (a = 1.0, b = 2.0, c = 3.0))

ERROR: ArgumentError: _same_set_of_names(transformations, y) must hold. Got
transformations => (a = asℝ, b = asℝ)
y => (a = 1.0, b = 2.0, c = 3.0)
Stacktrace:
 [1] throw_check_error(info::Any)
   @ ArgCheck ~/.julia/packages/ArgCheck/D1ZFJ/src/checks.jl:280
 [2] inverse_eltype(tt::TransformVariables.TransformTuple{…}, y::@NamedTuple{})
   @ TransformVariables ~/.julia/packages/TransformVariables/F49Oe/src/aggregation.jl:394
 [3] inverse(t::TransformVariables.TransformTuple{@NamedTuple{…}}, y::@NamedTuple{a::Float64, b::Float64, c::Float64})
   @ TransformVariables ~/.julia/packages/TransformVariables/F49Oe/src/generic.jl:284
 [4] top-level scope
   @ REPL[7]:1
Some type information was truncated. Use `show(err)` to see complete types.

@tpapp
Copy link
Owner Author

tpapp commented Feb 12, 2025

Thanks, forgot to close.

@tpapp tpapp closed this as completed Feb 12, 2025
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

No branches or pull requests

2 participants