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

Lazy-loading DataFrames.jl reduces the package loading time #154

Merged
merged 3 commits into from
Aug 17, 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
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
IndirectArrays = "9b13fd28-a010-5f03-acff-a1bbcff69959"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
TikzPictures = "37f6aa50-8035-52d0-81c2-5a1d08754b2d"

[compat]
Contour = "0.5"
ColorBrewer = "0.4"
Colors = "0.12"
ColorSchemes = "3.9"
Colors = "0.12"
Contour = "0.5"
DataFrames = "0.21"
Discretizers = "3.2"
ImageMagick = "0.7.3, 1"
Expand Down
15 changes: 6 additions & 9 deletions src/PGFPlots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ export pushPGFPlots, popPGFPlots
import Colors: RGB
import Contour: contours, levels

using Requires
using Discretizers
using DataFrames
using Printf

# load dynamic dependencies
function __init__()
@require DataFrames="a93c6f00-e57d-5684-b7b6-d8193f3e46c0" include("dataframes.jl")
end

mutable struct ErrorBars
data::AbstractMatrix{Real}
style
Expand Down Expand Up @@ -42,14 +47,6 @@ end
include("colormaps.jl")
include("plots.jl")

Plots.Linear(df::DataFrame; x::Symbol=:x, y::Symbol=:y, kwargs...) = Plots.Linear(df[!,x], df[!,y]; kwargs...)
Plots.Linear3(df::DataFrame; x::Symbol=:x, y::Symbol=:y, z::Symbol=:z, kwargs...) = Plots.Linear3(df[!,x], df[!,y], df[!,z]; kwargs...)
Plots.Histogram(df::DataFrame; x::Symbol=:x, kwargs...) = Plots.Histogram(df[!,x]; kwargs...)
Plots.Scatter(df::DataFrame; x::Symbol=:x, y::Symbol=:y, kwargs...) = Plots.Scatter(df[!,x], df[!,y]; kwargs...)
Plots.Quiver(df::DataFrame; x::Symbol=:x, y::Symbol=:y, u::Symbol=:u, v::Symbol=:v, kwargs...) = Plots.Quiver(convert(Vector, df[!,x]), convert(Vector, df[!,y]), convert(Vector, df[!,u]), convert(Vector, df[!,v]); kwargs...)
Plots.Histogram2(df::DataFrame; x::Symbol=:x, y::Symbol=:y, kwargs...) = Plots.Histogram2(convert(Vector, df[!,x]), convert(Vector, df[!,y]); kwargs...)
Plots.Histogram2(df::DataFrame, edges_x::AbstractVector{C}, edges_y::AbstractVector{C}; x::Symbol=:x, y::Symbol=:y, kwargs...) where {C<:Real} = Plots.Histogram2(convert(Vector, df[!,x]), convert(Vector, df[!,y]), edges_x, edges_y; kwargs...)

import TikzPictures: TikzPicture, PDF, TEX, TIKZ, SVG, save, LaTeXString, @L_str, @L_mstr

_pgfplotsoptions = Any[""]
Expand Down
22 changes: 22 additions & 0 deletions src/dataframes.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using DataFrames

Plots.Linear(df::DataFrame; x::Symbol=:x, y::Symbol=:y, kwargs...) =
Plots.Linear(df[!,x], df[!,y]; kwargs...)

Plots.Linear3(df::DataFrame; x::Symbol=:x, y::Symbol=:y, z::Symbol=:z, kwargs...) =
Plots.Linear3(df[!,x], df[!,y], df[!,z]; kwargs...)

Plots.Histogram(df::DataFrame; x::Symbol=:x, kwargs...) =
Plots.Histogram(df[!,x]; kwargs...)

Plots.Scatter(df::DataFrame; x::Symbol=:x, y::Symbol=:y, kwargs...) =
Plots.Scatter(df[!,x], df[!,y]; kwargs...)

Plots.Quiver(df::DataFrame; x::Symbol=:x, y::Symbol=:y, u::Symbol=:u, v::Symbol=:v, kwargs...) =
Plots.Quiver(convert(Vector, df[!,x]), convert(Vector, df[!,y]), convert(Vector, df[!,u]), convert(Vector, df[!,v]); kwargs...)

Plots.Histogram2(df::DataFrame; x::Symbol=:x, y::Symbol=:y, kwargs...) =
Plots.Histogram2(convert(Vector, df[!,x]), convert(Vector, df[!,y]); kwargs...)

Plots.Histogram2(df::DataFrame, edges_x::AbstractVector{C}, edges_y::AbstractVector{C}; x::Symbol=:x, y::Symbol=:y, kwargs...) where {C<:Real} =
Plots.Histogram2(convert(Vector, df[!,x]), convert(Vector, df[!,y]), edges_x, edges_y; kwargs...)