Skip to content

Commit

Permalink
Use Symbolics instead of Unitful.uparse to avoid eval during precom…
Browse files Browse the repository at this point in the history
…pilation
  • Loading branch information
tomyun committed Apr 17, 2024
1 parent dada08b commit 2e10b45
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
SymPy = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6"
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53"
TypedTables = "9d95f2ec-7b3d-5a63-8d20-e2491e220bb9"
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
Expand Down
6 changes: 5 additions & 1 deletion src/unit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ for f in (:unitfy, :deunitfy)
end

import Dates
import Symbolics
unitfy(df::AbstractDataFrame; kw...) = begin
#HACK: default constructor for common types to avoid scope binding issue
D = merge(Dict(
Expand All @@ -82,7 +83,10 @@ unitfy(df::AbstractDataFrame; kw...) = begin
#TODO: remove fallback eval in favor of explict constructor mapping
haskey(D, e) ? D[e] : Main.eval(e)
else
Unitful.uparse(s)
#HACK: use Symbolics to avoid eval during precompilation
#Unitful.uparse(s)
# https://github.com/PainterQubits/Unitful.jl/issues/649
Symbolics.parse_expr_to_symbolic(Meta.parse(s), Unitful)
end
end
u(m) = missing
Expand Down

0 comments on commit 2e10b45

Please sign in to comment.