Skip to content
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

@select and friends do not support all Base.Callables #132

Open
haberdashPI opened this issue Jan 8, 2025 · 3 comments
Open

@select and friends do not support all Base.Callables #132

haberdashPI opened this issue Jan 8, 2025 · 3 comments

Comments

@haberdashPI
Copy link

For example:

julia> using DataFrames, TidierData, UUIDs

julia> df = DataFrame(x = [uuid4() for _ in 1:5])

julia> df = @mutate(df, y = string(x))
5×2 DataFrame
 Row │ x                                     y
     │ UUID                                  String
─────┼─────────────────────────────────────────────────────────────────────────
   13cf06f2e-f427-435b-b7c8-61ead2cad822  3cf06f2e-f427-435b-b7c8-61ead2ca
   290283752-e9cc-48e6-bcb5-887d17f3971d  90283752-e9cc-48e6-bcb5-887d17f3
   38af8d0bf-8612-46b0-aec4-2a0304c91461  8af8d0bf-8612-46b0-aec4-2a0304c9
   48c229d55-0e1f-4e44-a2ee-53c8fbb84757  8c229d55-0e1f-4e44-a2ee-53c8fbb8
   5 │ bca74943-a2ad-499b-a09d-784a617d5744  bca74943-a2ad-499b-a09d-784a617d

julia> df = @mutate(df, z = UUID(y))
ERROR: UndefVarError: `UUID` not defined in `TidierData`
Suggestion: check for spelling errors or missing imports.
Hint: a global variable of this name also exists in Base.
Stacktrace:
  [1] (::var"#18#20")(y::Vector{String})
    @ Main ~/.julia/packages/TidierData/byaNj/src/parsing.jl:162
  [2] _transformation_helper(df::DataFrame, col_idx::Int64, ::Base.RefValue{Any})
    @ DataFrames ~/.julia/packages/DataFrames/kcA9R/src/abstractdataframe/selection.jl:562
  [3] select_transform!(::Base.RefValue{Any}, df::DataFrame, newdf::DataFrame, transformed_cols::Set{Symbol}, copycols::Bool, allow_resizing_newdf::Base.RefValue{Bool}, column_to_copy::BitVector)
    @ DataFrames ~/.julia/packages/DataFrames/kcA9R/src/abstractdataframe/selection.jl:805
  [4] _manipulate(df::DataFrame, normalized_cs::Vector{Any}, copycols::Bool, keeprows::Bool)
    @ DataFrames ~/.julia/packages/DataFrames/kcA9R/src/abstractdataframe/selection.jl:1783
  [5] manipulate(::DataFrame, ::Any, ::Vararg{Any}; copycols::Bool, keeprows::Bool, renamecols::Bool)
    @ DataFrames ~/.julia/packages/DataFrames/kcA9R/src/abstractdataframe/selection.jl:1703
  [6] select(::DataFrame, ::Any, ::Vararg{Any}; copycols::Bool, renamecols::Bool, threads::Bool)
    @ DataFrames ~/.julia/packages/DataFrames/kcA9R/src/abstractdataframe/selection.jl:1303
  [7] select
    @ ~/.julia/packages/DataFrames/kcA9R/src/abstractdataframe/selection.jl:1303 [inlined]
  [8] transform(df::DataFrame, args::Any)
    @ DataFrames ~/.julia/packages/DataFrames/kcA9R/src/abstractdataframe/selection.jl:1383
  [9] top-level scope
    @ ~/.julia/packages/TidierData/byaNj/src/TidierData.jl:293
 [10] top-level scope
    @ none:1

julia> uuid(x) = UUID(x)
uuid (generic function with 1 method)

julia> df = @mutate(df, z = uuid(y))
5×3 DataFrame
 Row │ x                                     y                                  z
     │ UUID                                  String                             UUID
─────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────
   13cf06f2e-f427-435b-b7c8-61ead2cad822  3cf06f2e-f427-435b-b7c8-61ead2ca  3cf06f2e-f427-435b-b7c8-61ead2cad822
   290283752-e9cc-48e6-bcb5-887d17f3971d  90283752-e9cc-48e6-bcb5-887d17f3  90283752-e9cc-48e6-bcb5-887d17f3971d
   38af8d0bf-8612-46b0-aec4-2a0304c91461  8af8d0bf-8612-46b0-aec4-2a0304c9  8af8d0bf-8612-46b0-aec4-2a0304c91461
   48c229d55-0e1f-4e44-a2ee-53c8fbb84757  8c229d55-0e1f-4e44-a2ee-53c8fbb8  8c229d55-0e1f-4e44-a2ee-53c8fbb84757
   5 │ bca74943-a2ad-499b-a09d-784a617d5744  bca74943-a2ad-499b-a09d-784a617d  bca74943-a2ad-499b-a09d-784a617d5744
@haberdashPI haberdashPI changed the title @select and friends do not support all Base.Callables @select and friends do not support all Base.Callables Jan 8, 2025
@kdpsingh
Copy link
Member

kdpsingh commented Jan 8, 2025

Thanks - will look to see what is going on here.

@kdpsingh
Copy link
Member

kdpsingh commented Jan 8, 2025

I tracked it down to this line in the parse_escape_function():

elseif fn isa Symbol && hasproperty(Base, fn) && typeof(getproperty(Base, fn)) <: Type
        return x

Because UUID is a DataType, typeof(getproperty(Base, :UUID)) <: Type returns true.

I think I remember why I had put this in place - let me explore if this is easily modifiable without affecting another edge case.

@haberdashPI
Copy link
Author

Not having all the context I don't know what the right call is here, but I do think it would be ideal if all Base.Callable objects could be handled (which Type is one of). Baring that it would be nice if escaping would work (e.g. !!(UUID)(string)) at the moment that also throws an error (don't remember what offhand).

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