Skip to content

Commit 41edab5

Browse files
authored
Merge pull request #233 from MilesCranmer/allow-empty-units
Allow empty string units (==1)
2 parents 7197c47 + 3e1ad01 commit 41edab5

3 files changed

Lines changed: 3 additions & 1 deletion

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SymbolicRegression"
22
uuid = "8254be44-1295-4e6a-a16d-46603ac705cb"
33
authors = ["MilesCranmer <miles.cranmer@gmail.com>"]
4-
version = "0.21.1"
4+
version = "0.21.2"
55

66
[deps]
77
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"

src/Dataset.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ function get_units(_, _, ::Nothing, ::Function)
224224
return nothing
225225
end
226226
function get_units(::Type{T}, ::Type{D}, x::AbstractString, f::Function) where {T,D}
227+
isempty(x) && return one(Quantity{T,D})
227228
return convert(Quantity{T,D}, f(x))
228229
end
229230
function get_units(::Type{T}, ::Type{D}, x::Quantity, ::Function) where {T,D}

test/test_units.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ options = Options(;
4444
Quantity(1.5, SymbolicDimensions),
4545
Quantity(1.0, SymbolicDimensions),
4646
]
47+
@test get_units(Float64, SD, [""], sym_uparse) == [Quantity(1.0, SymbolicDimensions)]
4748
# Bad unit types:
4849
@test_throws ErrorException get_units(Float64, D, (; X=[1, 2]), uparse)
4950

0 commit comments

Comments
 (0)