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

Bump compat for CategoricalArrays to 0.8 #1447

Merged
merged 2 commits into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Each release typically has a number of minor bug fixes beyond what is listed her

# Version 1.x

* Add support for CategoricalArrays v0.8 & and DataFrames v0.21 (#1447)
* Add `Guide.manual_discrete_key`, updates `Guide.manual_color_key` (#1441)
* Increase support for syntax `color=[colorant"color"]` (#1438)
* Enable `color` aesthetic for `Stat.qq` (#1434)
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[compat]
Cairo = "0.7, 0.8, 1.0"
CategoricalArrays = "0.5, 0.6, 0.7"
CategoricalArrays = "0.8"
Colors = "0.9, 0.10, 0.11, 0.12"
Compose = "0.7, 0.8"
Contour = "0.5"
CoupledFields = "0.1, 0.2"
DataFrames = "0.15, 0.16, 0.17, 0.18, 0.19, 0.20"
DataFrames = "0.21"
DataStructures = "0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17"
Distributions = "0.16, 0.17, 0.18, 0.19, 0.20, 0.21, 0.22, 0.23"
DocStringExtensions = "0.7, 0.8"
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ RDatasets = "ce6b1742-4840-55fa-b093-852dadbb1d8b"
Showoff = "992d4aef-0814-514b-bc4d-f2e9a6c4116f"

[compat]
CSV = "0.4, 0.5"
CSV = "0.6"
Documenter = "~0.22"
15 changes: 8 additions & 7 deletions docs/src/gallery/geometries.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ hstack(p1, p2, p3)
using Gadfly, RDatasets, DataFrames
set_default_plot_size(21cm, 8cm)

D = by(dataset("datasets","HairEyeColor"), [:Eye,:Sex], Frequency=:Freq=>sum)
hecolor = dataset("datasets","HairEyeColor")
D = combine(groupby(hecolor, [:Eye,:Sex]), :Freq=>sum=>:Frequency)
p1 = plot(D, color=:Eye, y=:Frequency, x=:Sex, Geom.bar(position=:dodge))

palette = ["brown","blue","tan","green"] # Is there a hazel color?
Expand Down Expand Up @@ -235,19 +236,19 @@ set_default_plot_size(21cm, 8cm)
salaries = dataset("car","Salaries")
salaries.Salary /= 1000.0
salaries.Discipline = ["Discipline $(x)" for x in salaries.Discipline]
df = by(salaries, [:Rank,:Discipline], :Salary=>mean, :Salary=>std)
df.ymin, df.ymax = df.Salary_mean.-df.Salary_std, df.Salary_mean.+df.Salary_std
df.label = string.(round.(Int, df.Salary_mean))
fn1(x, u=mean(x), s=std(x)) = (Salary=u, ymin=u-s, ymax=u+s,
label="$(round.(Int,u))")
df = combine(:Salary=>fn1, groupby(salaries, [:Rank, :Discipline]))

p1 = plot(df, x=:Discipline, y=:Salary_mean, color=:Rank,
p1 = plot(df, x=:Discipline, y=:Salary, color=:Rank,
Scale.x_discrete(levels=["Discipline A", "Discipline B"]),
ymin=:ymin, ymax=:ymax, Geom.errorbar, Stat.dodge,
Geom.bar(position=:dodge),
Scale.color_discrete(levels=["Prof", "AssocProf", "AsstProf"]),
Guide.colorkey(title="", pos=[0.76w, -0.38h]),
Theme(bar_spacing=0mm, stroke_color=c->"black")
)
p2 = plot(df, y=:Discipline, x=:Salary_mean, color=:Rank,
p2 = plot(df, y=:Discipline, x=:Salary, color=:Rank,
Coord.cartesian(yflip=true), Scale.y_discrete,
xmin=:ymin, xmax=:ymax, Geom.errorbar, Stat.dodge(axis=:y),
Geom.bar(position=:dodge, orientation=:horizontal),
Expand Down Expand Up @@ -630,6 +631,6 @@ hstack(p1,p2)
using Gadfly, RDatasets
set_default_plot_size(14cm, 8cm)
Dsing = dataset("lattice","singer")
Dsing.Voice = [x[1:5] for x in Dsing.VoicePart]
Dsing.Voice = [x[1:5] for x in Array(Dsing.VoicePart)]
plot(Dsing, x=:VoicePart, y=:Height, color=:Voice, Geom.violin)
```
15 changes: 7 additions & 8 deletions docs/src/gallery/guides.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ p1 = plot(layer(points, x=:index, y=:val, color=[colorant"green"]),
Guide.manual_color_key("Legend", ["Points", "Line"], ["green", "deepskyblue"],
shape=[Shape.circle, Shape.hline]))

D = dataset("COUNT", "titanicgrp")
D = join(D, by(D, :Class, :Cases=>sum), on=:Class)
D.prcnt = 100*D.Survive./D.Cases_sum
D = groupby(dataset("COUNT", "titanicgrp"), :Class)
fn1(s,c) = 100*s./sum(c)
D = combine(D, :Age, :Sex, [:Survive, :Cases]=>fn1=>:prcnt)
p2 = plot(stack(D, [:Age, :Sex]), xgroup=:Class,
Geom.subplot_grid(layer(x=:variable, y=:prcnt, color=:value, Geom.bar)),
Scale.x_discrete, Guide.ylabel("Survival (%)"),
Scale.x_discrete, Guide.ylabel("Survival (% Class)"),
Guide.manual_color_key("Age", ["children","adults"], 1:2),
Guide.manual_color_key("Sex", ["female","male"], 3:4),
Theme(bar_spacing=1mm, key_position=:none,
Expand Down Expand Up @@ -84,10 +84,9 @@ plot(Dsleep, x=:BodyWt, y=:BrainWt, Geom.point, color=:Vore, shape=:SleepTime,
using Compose, Gadfly, RDatasets
set_default_plot_size(14cm, 8cm)

Titanic = dataset("datasets", "Titanic")
Class = by(Titanic, :Class, :Freq=>sum)
Titanic = join(Titanic[Titanic.Survived.=="Yes",:], Class, on=:Class)
Titanic.prcnt = 100*Titanic.Freq./Titanic.Freq_sum
D = groupby(dataset("datasets", "Titanic"), :Class)
Titanic = combine(D, :, :Freq=>(c->100*c./sum(c))=>:prcnt)
filter!(:Survived=>x->x=="Yes", Titanic)
sizemap = n->range(3pt, 8pt, length=n)

plot(Titanic, Scale.x_log10, Scale.y_log10,
Expand Down
16 changes: 8 additions & 8 deletions docs/src/gallery/scales.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ plot(x=rand(12), y=rand(12), color=repeat(["a","b","c"], outer=[4]),
```@example
using Gadfly, RDatasets, DataFrames
set_default_plot_size(14cm, 8cm)
D = by(dataset("datasets","HairEyeColor"), [:Eye,:Sex], Frequency=:Freq=>sum)
hecolor = dataset("datasets","HairEyeColor")
D = combine(groupby(hecolor, [:Eye,:Sex]), :Freq=>sum=>:Frequency)
palette = ["brown","blue","tan","green"] # Is there a hazel color?
pa = plot(D, x=:Sex, y=:Frequency, color=:Eye, Geom.bar(position=:stack),
Scale.color_discrete_manual(palette...))
Expand Down Expand Up @@ -169,9 +170,9 @@ using Gadfly, RDatasets, Statistics
set_default_plot_size(14cm, 8cm)

tips = dataset("reshape2", "tips")
tipsm = by(tips, [:Day, :Sex], :TotalBill=>mean, :Tip=>mean)
tipsm = combine(groupby(tips, [:Day, :Sex]), [:TotalBill, :Tip].=>mean)

plot(tipsm, Geom.point,
plot(tipsm, Geom.point,
x=:TotalBill_mean, y=:Tip_mean, color=:Sex, shape=:Day,
layer(x=:TotalBill_mean, y=:Tip_mean, group=:Day, Geom.line,
style(default_color=colorant"gray")),
Expand Down Expand Up @@ -210,10 +211,9 @@ plot(aq, x=:Day, y=:Ozone, color=:Month, size=:Wind,
using Compose, Gadfly, RDatasets
set_default_plot_size(14cm, 8cm)

Titanic = dataset("datasets", "Titanic")
Class = by(Titanic, :Class, :Freq=>sum)
Titanic = join(Titanic[Titanic.Survived.=="Yes",:], Class, on=:Class)
Titanic.prcnt = 100*Titanic.Freq./Titanic.Freq_sum
D = groupby(dataset("datasets", "Titanic"), :Class)
Titanic = combine(D, :, :Freq=>(c->100*c./sum(c))=>:prcnt)
filter!(:Survived=>x->x=="Yes", Titanic)
sizemap = n->range(4pt, 12pt, length=n)

plot(Titanic, Scale.x_log10, Scale.y_log10,
Expand Down Expand Up @@ -255,7 +255,7 @@ Random.seed!(1234)
p1 = plot(x=rand(1:3, 20), y=rand(20), Scale.x_discrete)
# To perserve the order of the columns in the plot when plotting a DataFrame
df = DataFrame(v1 = randn(10), v2 = randn(10), v3 = randn(10))
p2 = plot(df, x=Col.index, y=Col.value, Scale.x_discrete(levels=names(df)))
p2 = plot(df, x=Col.index, y=Col.value, Scale.x_discrete(levels=propertynames(df)))
hstack(p1,p2)
```

Expand Down
5 changes: 2 additions & 3 deletions docs/src/gallery/statistics.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ set_default_plot_size(21cm, 8cm)
salaries = dataset("car","Salaries")
salaries.Salary /= 1000.0
salaries.Discipline = ["Discipline $(x)" for x in salaries.Discipline]
df = by(salaries, [:Rank,:Discipline], :Salary=>mean, :Salary=>std)
df.ymin, df.ymax = df.Salary_mean.-df.Salary_std, df.Salary_mean.+df.Salary_std
df = combine(groupby(salaries, [:Rank, :Discipline]), :Salary.=>mean)
df.label = string.(round.(Int, df.Salary_mean))

p1 = plot(df, x=:Discipline, y=:Salary_mean, color=:Rank,
Expand Down Expand Up @@ -87,7 +86,7 @@ plot(y=[sigmoid, x->sigmoid(x+2)], xmin=[-10], xmax=[10],
using Distributions, Gadfly, RDatasets
set_default_plot_size(21cm, 8cm)
iris, geyser = dataset.("datasets", ["iris", "faithful"])
df = by(iris, :Species, d=:SepalLength=>x->fit(Normal, x))
df = combine(groupby(iris, :Species), :SepalLength=>(x->fit(Normal, x))=>:d)
ds2 = fit.([Normal, Uniform], [geyser.Eruptions])

yeqx(x=4:6) = layer(x=x, Geom.abline(color="gray80"))
Expand Down
4 changes: 2 additions & 2 deletions src/dataframes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function meltdata(U::AbstractDataFrame, colgroups::Vector{Col.GroupedColumn})
um, un = size(U)

# Figure out the size of the new melted matrix
allcolumns = Set{Symbol}(names(U))
allcolumns = Set{Symbol}(propertynames(U))

vm = um
colidxs = [colgroup.columns===nothing ? collect(allcolumns) : colgroup.columns for colgroup in colgroups]
Expand All @@ -18,7 +18,7 @@ function meltdata(U::AbstractDataFrame, colgroups::Vector{Col.GroupedColumn})
vnames = Symbol[]
colmap = Dict{Any, Int}()

eltypd = Dict(k=>v for (k,v) in zip(names(U), eltype.(eachcol(U))))
eltypd = Dict{Symbol, DataType}(k=>v for (k,v) in zip(propertynames(U), eltype.(eachcol(U))))
# allocate vectors for grouped columns
for (j, (colgroup, colidx)) in enumerate(zip(colgroups, colidxs))
eltyp = promote_type(getindex.([eltypd], colidx)...)
Expand Down
2 changes: 1 addition & 1 deletion src/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ discretize_make_ia(values::CategoricalArray) =
discretize_make_ia(values, intersect(push!(levels(values), missing), unique(values)))
discretize_make_ia(values::CategoricalArray, ::Nothing) = discretize_make_ia(values)
function discretize_make_ia(values::CategoricalArray{T}, levels::Vector) where {T}
mapping = something.(indexin(CategoricalArrays.index(values.pool), levels), 0)
mapping = something.(indexin(CategoricalArrays.levels(values.pool), levels), 0)
pushfirst!(mapping, something(findfirst(ismissing, levels), 0))
index = [mapping[x+1] for x in values.refs]
any(iszero, index) && throw(ArgumentError("values not in levels encountered"))
Expand Down
16 changes: 8 additions & 8 deletions test/testscripts/issue975.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using DataFrames, Gadfly, Dates

set_default_plot_size(6inch, 3inch)
set_default_plot_size(7inch, 3inch)

# Geom.smooth already has tests for these types:
# Floats: smooth_lm.jl
Expand All @@ -15,16 +15,16 @@ n = length(t)
D = DataFrame(t1=t1, t2=t2,
cycle = 5*sin.(t*2π/365.25)+randn(n),
trend = 0.1*[1.0:n;].+2*randn(n))
Dl = stack(D, setdiff(names(D), [:t1,:t2]))
Dl = stack(D, Not([:t1, :t2]))

plot(D,
x=:t1, y=:trend, Geom.point,
Geom.smooth(method=:lm),
p1 = plot(D, x=:t1, y=:trend,
Geom.smooth(method=:lm), Geom.point,
Theme(point_size=1.8pt, key_position=:none)
)

plot(Dl,
x=:t2, y=:value, color=:variable, Geom.point,
Geom.smooth(smoothing=0.05),
p2 = plot(Dl,
x=:t2, y=:value, color=:variable,
Geom.smooth(smoothing=0.05), Geom.point,
Theme(point_size=1.8pt, key_position=:none)
)
hstack(p1, p2)
2 changes: 1 addition & 1 deletion test/testscripts/stat_dodge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set_default_plot_size(21cm, 8cm)
salaries = dataset("car","Salaries")
salaries.Salary /= 1000.0
salaries.Discipline = ["Discipline $(x)" for x in salaries.Discipline]
df = by(salaries, [:Rank,:Discipline], :Salary=>mean, :Salary=>std)
df = combine(groupby(salaries, [:Rank,:Discipline]), :Salary=>mean, :Salary=>std)
df.ymin, df.ymax = df.Salary_mean.-df.Salary_std, df.Salary_mean.+df.Salary_std
df.label = string.(round.(Int, df.Salary_mean))

Expand Down
2 changes: 1 addition & 1 deletion test/testscripts/wide_form.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ set_default_plot_size(6inch, 4inch)

births = dataset("HistData", "Arbuthnot")

plot(births, x=Col.value(:Year), y=Col.value(:Males, :Females),
plot(births, x=:Year, y=Col.value(:Males, :Females),
color=Col.index(:Males, :Females), Geom.line)