Skip to content

Commit a6f6f03

Browse files
authored
fix unitful bug (#384)
* fix unitful bug * update CI
1 parent d6a3eff commit a6f6f03

File tree

6 files changed

+42
-18
lines changed

6 files changed

+42
-18
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ jobs:
1818
fail-fast: false
1919
matrix:
2020
version:
21-
- '1.6' # latest LTS
21+
- '1.10' # latest LTS
2222
- '1'
23-
- '~1.11.0-0' # upcoming julia version, next `rc`
2423
experimental:
2524
- false
2625
os: [ubuntu-latest]

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ Requires = "1"
4040
SparseArrays = "1"
4141
StaticArrays = "1"
4242
StatsBase = "0.33, 0.34"
43+
Term = "2"
4344
Unitful = "1"
44-
julia = "1.6"
45+
julia = "1.10"
4546

4647
[extensions]
4748
FreeTypeExt = ["FileIO", "FreeType"]

ext/UnitfulExt.jl

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,28 @@ unitless(x::Quantity) = ustrip(x) # NOTE: keep in sync with src/common.jl
2424
# lineplot
2525
function UnicodePlots.lineplot(
2626
x::AbstractVector{<:RealOrRealQuantity},
27-
y::AbstractVector{<:Quantity};
27+
y::AbstractVector{<:RealOrRealQuantity};
2828
unicode_exponent::Bool = KEYWORDS.unicode_exponent,
29+
canvas::Type = KEYWORDS.canvas,
2930
xlabel = KEYWORDS.xlabel,
3031
ylabel = KEYWORDS.ylabel,
3132
kw...,
3233
)
34+
pkw, okw = UnicodePlots.split_plot_kw(kw)
3335
x, ux = number_unit(x, unicode_exponent)
3436
y, uy = number_unit(y, unicode_exponent)
35-
UnicodePlots.lineplot(
36-
unitless.(x),
37-
unitless.(y);
37+
x_, y_ = unitless.(x), unitless.(y)
38+
plot = Plot(
39+
x_,
40+
y_,
41+
nothing,
42+
canvas;
3843
xlabel = unit_label(xlabel, ux),
3944
ylabel = unit_label(ylabel, uy),
4045
unicode_exponent,
41-
kw...,
46+
pkw...,
4247
)
48+
UnicodePlots.lineplot!(plot, x_, y_; okw...)
4349
end
4450

4551
UnicodePlots.lineplot!(
@@ -53,22 +59,28 @@ UnicodePlots.lineplot!(
5359
# scatterplot
5460
function UnicodePlots.scatterplot(
5561
x::AbstractVector{<:RealOrRealQuantity},
56-
y::AbstractVector{<:Quantity};
62+
y::AbstractVector{<:RealOrRealQuantity};
5763
unicode_exponent::Bool = KEYWORDS.unicode_exponent,
64+
canvas::Type = KEYWORDS.canvas,
5865
xlabel = KEYWORDS.xlabel,
5966
ylabel = KEYWORDS.ylabel,
6067
kw...,
6168
)
69+
pkw, okw = UnicodePlots.split_plot_kw(kw)
6270
x, ux = number_unit(x, unicode_exponent)
6371
y, uy = number_unit(y, unicode_exponent)
64-
UnicodePlots.scatterplot(
65-
unitless.(x),
66-
unitless.(y);
72+
x_, y_ = unitless.(x), unitless.(y)
73+
plot = Plot(
74+
x_,
75+
y_,
76+
nothing,
77+
canvas;
6778
xlabel = unit_label(xlabel, ux),
6879
ylabel = unit_label(ylabel, uy),
6980
unicode_exponent,
70-
kw...,
81+
pkw...,
7182
)
83+
UnicodePlots.scatterplot!(plot, x_, y_; okw...)
7284
end
7385

7486
UnicodePlots.scatterplot!(

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ withenv("FORCE_COLOR" => "X") do # JuliaPlots/UnicodePlots.jl/issues/134
132132
@timeit_include "tst_quality.jl"
133133
end
134134

135-
# ~ 90s & 8.26GiB on 1.9
135+
# ~ 94s & 9.88GiB on 1.11
136136
print_timer(TO; compact = true, sortby = :firstexec)
137137

138138
println("\n== end: testing with $(UnicodePlots.colormode())bit colormode ==")

test/tst_io.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ sombrero(x, y) = 30sinc(√(x^2 + y^2) / π)
6868
if measure
6969
GC.enable(false)
7070
stats = @timed string(p; color = true) # repeated !
71-
@test stats.bytes / 1e3 < 500 # ~ 356kB on 1.10
72-
@test stats.time * 1e3 < 0.8 # ~ 0.3ms on 1.10
71+
@test stats.bytes / 1e3 < 500 # ~ 292kB on 1.11
72+
@test stats.time * 1e3 < 0.8 # ~ 0.3ms on 1.11
7373
GC.enable(true)
7474
end
7575
end
@@ -80,8 +80,8 @@ sombrero(x, y) = 30sinc(√(x^2 + y^2) / π)
8080
if measure
8181
GC.enable(false)
8282
stats = @timed string(p; color = true) # repeated !
83-
@test stats.bytes / 1e3 < 160 # ~ 152kB on 1.10
84-
@test stats.time * 1e3 < 0.5 # ~ 0.26ms on 1.10
83+
@test stats.bytes / 1e3 < 160 # ~ 123kB on 1.11
84+
@test stats.time * 1e3 < 0.5 # ~ 0.2ms on 1.11
8585
GC.enable(true)
8686
end
8787
end

test/tst_issues.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,16 @@
9595
p = scatterplot(x, y; ylim)
9696
show(devnull, p)
9797
end
98+
99+
@testset "Unitful dispatch (#383)" begin
100+
p = lineplot(rand(1), rand(1) * u"m")
101+
show(devnull, p)
102+
p = lineplot(rand(1) * u"m", rand(1))
103+
show(devnull, p)
104+
105+
p = scatterplot(rand(1), rand(1) * u"m")
106+
show(devnull, p)
107+
p = scatterplot(rand(1) * u"m", rand(1))
108+
show(devnull, p)
109+
end
98110
end

0 commit comments

Comments
 (0)