Skip to content

Commit

Permalink
CLN: clean up @require files to not call using on loaded req'd mod
Browse files Browse the repository at this point in the history
  • Loading branch information
sglyon committed Sep 19, 2018
1 parent 477f861 commit 194db18
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 29 deletions.
35 changes: 13 additions & 22 deletions src/dataframes_api.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import .DataFrames.AbstractDataFrame
using .DataFrames

# utilities

_has_group(df::AbstractDataFrame, group::Any) = false
_has_group(df::AbstractDataFrame, group::Symbol) = haskey(df, group)
function _has_group(df::AbstractDataFrame, group::Vector{Symbol})
_has_group(df::DataFrames.AbstractDataFrame, group::Any) = false
_has_group(df::DataFrames.AbstractDataFrame, group::Symbol) = haskey(df, group)
function _has_group(df::DataFrames.AbstractDataFrame, group::Vector{Symbol})
all(x -> haskey(df, x), group)
end

_group_name(df::AbstractDataFrame, group::Symbol) = df[1, group]
function _group_name(df::AbstractDataFrame, groups::Vector{Symbol})
_group_name(df::DataFrames.AbstractDataFrame, group::Symbol) = df[1, group]
function _group_name(df::DataFrames.AbstractDataFrame, groups::Vector{Symbol})
string("(", join([df[1, g] for g in groups], ", "), ")")
end

Expand Down Expand Up @@ -38,10 +35,10 @@ useful when using the `group` keyword arugment, as the function will be applied
to each SubDataFrame. In the example above, the name attribute would set a
different mean for each group.
"""
function GenericTrace(df::AbstractDataFrame; group=nothing, kind="scatter", kwargs...)
function GenericTrace(df::DataFrames.AbstractDataFrame; group=nothing, kind="scatter", kwargs...)
d = Dict{Symbol,Any}(kwargs)
if _has_group(df, group)
_traces = by(df, group) do dfg
_traces = DataFrames.by(df, group) do dfg
GenericTrace(dfg; kind=kind, name=_group_name(dfg, group), kwargs...)
end
return GenericTrace[t for t in _traces[:x1]]
Expand All @@ -65,7 +62,7 @@ $(SIGNATURES)
Pass the provided values of `x` and `y` as keyword arguments for constructing
the trace from `df`. See other method for more information
"""
function GenericTrace(df::AbstractDataFrame, x::Symbol, y::Symbol; kwargs...)
function GenericTrace(df::DataFrames.AbstractDataFrame, x::Symbol, y::Symbol; kwargs...)
GenericTrace(df; x=x, y=y, kwargs...)
end

Expand All @@ -74,7 +71,7 @@ $(SIGNATURES)
Pass the provided value `y` as keyword argument for constructing the trace from
`df`. See other method for more information
"""
function GenericTrace(df::AbstractDataFrame, y::Symbol; kwargs...)
function GenericTrace(df::DataFrames.AbstractDataFrame, y::Symbol; kwargs...)
GenericTrace(df; y=y, kwargs...)
end

Expand All @@ -89,7 +86,7 @@ then call `by(df, group)` and construct one trace per SubDataFrame, passing
all other keyword arguments. This means all keyword arguments are passed
applied to all traces
"""
function Plot(df::AbstractDataFrame, l::Layout=Layout();
function Plot(df::DataFrames.AbstractDataFrame, l::Layout=Layout();
style::Style=CURRENT_STYLE[], kwargs...)
Plot(GenericTrace(df; kwargs...), l, style=style)
end
Expand All @@ -99,7 +96,7 @@ $(SIGNATURES)
Construct a plot from `df`, passing the provided values of x and y as keyword
arguments. See docstring for other method for more information.
"""
function Plot(d::AbstractDataFrame, x::Symbol, y::Symbol, l::Layout=Layout();
function Plot(d::DataFrames.AbstractDataFrame, x::Symbol, y::Symbol, l::Layout=Layout();
style::Style=CURRENT_STYLE[], kwargs...)
Plot(d, l; x=x, y=y, style=style, kwargs...)
end
Expand All @@ -109,19 +106,13 @@ $(SIGNATURES)
Construct a plot from `df`, passing the provided value y as a keyword argument.
See docstring for other method for more information.
"""
function Plot(d::AbstractDataFrame, y::Symbol, l::Layout=Layout();
function Plot(d::DataFrames.AbstractDataFrame, y::Symbol, l::Layout=Layout();
style::Style=CURRENT_STYLE[], kwargs...)
Plot(d, l; y=y, style=style, kwargs...)
end


for t in _TRACE_TYPES
str_t = string(t)
@eval $t(df::AbstractDataFrame; kwargs...) = GenericTrace(df; kind=$(str_t), kwargs...)
end


@require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin
import .Revise: track
track(PlotlyBase, @__FILE__)
@eval $t(df::DataFrames.AbstractDataFrame; kwargs...) = GenericTrace(df; kind=$(str_t), kwargs...)
end
8 changes: 1 addition & 7 deletions src/distributions.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
using Distributions

@require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin
Revise.track(PlotlyBase, @__FILE__)
end

_strip_module(s) = split(s, '.', limit=2)[end]
_strip_type_param(s) = replace(s, r"{.+?}" => "")
_clean_name(d::Distribution) = _strip_module(_strip_type_param(repr(d)))
_clean_name(d::Distributions.Distribution) = _strip_module(_strip_type_param(repr(d)))

function scatter(d::Distributions.ContinuousUnivariateDistribution)
ls(a, b, c) = range(a, stop=b, length=c)
Expand Down

0 comments on commit 194db18

Please sign in to comment.